Skip to content

Commit 2aa49a2

Browse files
committed
test fixes
1 parent df94a17 commit 2aa49a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+95
-95
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515
- name: Install dependencies
1616
run: |
1717
sudo apt-get update

itest/lib/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import random
44
from .testbase import TestBase
55
from .task import Task
6-
from .cleanup import cleanup
6+
from .cleanup import cleanup as clean
77
from .cleanup import killall
88
from .node import Node
99
from .vars import THINGSDB_BIN
@@ -56,7 +56,7 @@ async def _run_test(test):
5656
""")
5757

5858
try:
59-
await test.run()
59+
await test.async_run()
6060
except Exception as e:
6161
task.stop(success=False)
6262
if not THINGSDB_KEEP_ON_ERROR:
@@ -72,7 +72,7 @@ async def _run_test(test):
7272

7373
def run_test(test: TestBase):
7474
loop = asyncio.get_event_loop()
75-
cleanup()
75+
clean()
7676
loop.run_until_complete(_run_test(test))
7777

7878

itest/lib/node.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import sys
21
import os
32
import asyncio
43
import subprocess
54
import platform
65
import configparser
76
import psutil
87
import logging
9-
import io
108
import re
119
import threading
1210
from .vars import THINGSDB_BIN
@@ -165,11 +163,21 @@ def write_config(self):
165163
config = configparser.RawConfigParser()
166164
config.add_section('thingsdb')
167165

168-
config.set('thingsdb', 'listen_client_port', self.listen_client_port)
169-
config.set('thingsdb', 'listen_node_port', self.listen_node_port)
170-
config.set('thingsdb', 'http_api_port', self.http_api_port)
171-
config.set('thingsdb', 'http_status_port', self.http_status_port)
172-
config.set('thingsdb', 'ws_port', self.ws_port)
166+
config.set('thingsdb',
167+
'listen_client_port',
168+
str(self.listen_client_port))
169+
config.set('thingsdb',
170+
'listen_node_port',
171+
str(self.listen_node_port))
172+
config.set('thingsdb',
173+
'http_api_port',
174+
str(self.http_api_port))
175+
config.set('thingsdb',
176+
'http_status_port',
177+
str(self.http_status_port))
178+
config.set('thingsdb',
179+
'ws_port',
180+
str(self.ws_port))
173181

174182
config.set('thingsdb', 'bind_client_addr', self.bind_client_addr)
175183
config.set('thingsdb', 'bind_node_addr', self.bind_node_addr)
@@ -270,13 +278,14 @@ def is_active(self):
270278
return False if self.proc is None else psutil.pid_exists(self.proc.pid)
271279

272280
def kill(self):
273-
command = f'kill -9 {self.proc.pid}'
274-
logging.info(f'execute: `{command}``')
275-
os.system(command)
281+
if self.proc:
282+
command = f'kill -9 {self.proc.pid}'
283+
logging.info(f'execute: `{command}``')
284+
os.system(command)
276285
self.proc = None
277286

278287
async def stop(self):
279-
if self.is_active():
288+
if self.is_active() and self.proc:
280289
os.system('kill {}'.format(self.proc.pid))
281290
await asyncio.sleep(0.2)
282291

@@ -291,7 +300,7 @@ async def stop(self):
291300
return True
292301

293302
async def shutdown(self, timeout=20):
294-
if self.is_active():
303+
if self.is_active() and self.proc:
295304
os.system('kill {}'.format(self.proc.pid))
296305

297306
while timeout:
@@ -304,6 +313,6 @@ async def shutdown(self, timeout=20):
304313
assert (self.proc.returncode == 0)
305314

306315
def soft_kill(self):
307-
if self.is_active():
316+
if self.is_active() and self.proc:
308317
os.system('kill {}'.format(self.proc.pid))
309318
self.proc = None

itest/lib/target.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

itest/lib/testbase.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
import asyncio
33
from thingsdb.exceptions import NodeError
44
from .client import get_client
5+
from .node import Node
56

67

78
class TestBase(unittest.TestCase):
89

910
title = 'no test title'
11+
node0: Node
12+
node1: Node
13+
node2: Node
14+
node3: Node
15+
node4: Node
1016

11-
async def run(self):
12-
raise NotImplementedError('run must be implemented')
17+
async def async_run(self):
18+
raise NotImplementedError('async_run must be implemented')
1319

1420
async def wait_nodes_ready(self, client=None, success_count=10):
1521
if client is None:
@@ -77,7 +83,7 @@ async def assertNoChange(self, client, query):
7783

7884
async def run_tests(self, *args, **kwargs):
7985
for attr, f in self.__class__.__dict__.items():
80-
if attr.startswith('test_') and callable(f):
86+
if attr.startswith('test_') and asyncio.iscoroutinefunction(f):
8187
client = await get_client(self.node0)
8288
await client.query(r"""//ti
8389
del_collection('stuff');

itest/test_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TestAdvanced(TestBase):
1919
title = 'Test advanced, single node'
2020

2121
@default_test_setup(num_nodes=1, seed=1, threshold_full_storage=10)
22-
async def run(self):
22+
async def async_run(self):
2323

2424
self.node0.version()
2525

itest/test_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestArguments(TestBase):
1212
title = 'Test arguments'
1313

1414
@default_test_setup(num_nodes=1, seed=1)
15-
async def run(self):
15+
async def async_run(self):
1616

1717
await self.node0.init_and_run()
1818

itest/test_backup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestBackup(TestBase):
1818
num_nodes=2, seed=1,
1919
threshold_full_storage=100,
2020
gcloud_key_file='/tmp/_test_ti.json')
21-
async def run(self):
21+
async def async_run(self):
2222

2323
await self.node0.init_and_run()
2424

itest/test_changes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ class TestChanges(TestBase):
1111
title = 'Test with multiple changes at the same time'
1212

1313
@default_test_setup(num_nodes=4, seed=1, threshold_full_storage=1000000)
14-
async def run(self):
14+
async def async_run(self):
1515
x = 50
1616
mq = '.x += .x % {}; .arr.push(.x);'
1717

1818
await self.node0.init_and_run()
1919

2020
client0 = await get_client(self.node0)
2121
client0.set_default_scope('//stuff')
22-
client0.id = 2
22+
setattr(client0, 'id', 2)
2323

2424
await client0.query('.x = 10; .arr = [];')
2525

2626
await self.node1.join_until_ready(client0)
2727

2828
client1 = await get_client(self.node1)
2929
client1.set_default_scope('//stuff')
30-
client1.id = 5
30+
setattr(client1, 'id', 5)
3131

3232
for _ in range(x):
3333
await self.mquery(mq, client0, client1)
@@ -48,7 +48,7 @@ async def run(self):
4848

4949
client2 = await get_client(self.node2)
5050
client2.set_default_scope('//stuff')
51-
client2.id = 9
51+
setattr(client2, 'id', 9)
5252

5353
# Added sleep() to test if this prevents a timeout-error which
5454
# may sometimes happen on the `mquery` below
@@ -95,7 +95,7 @@ async def run(self):
9595

9696
client3 = await get_client(self.node3)
9797
client3.set_default_scope('//stuff')
98-
client3.id = 11
98+
setattr(client3, 'id', 11)
9999

100100
await asyncio.sleep(0.5)
101101
check_arr = await client0.query('.arr;')

itest/test_collection_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TestCollectionFunctions(TestBase):
2525
title = 'Test collection scope functions'
2626

2727
@default_test_setup(num_nodes=2, seed=1, threshold_full_storage=50000)
28-
async def run(self):
28+
async def async_run(self):
2929

3030
await self.node0.init_and_run()
3131

0 commit comments

Comments
 (0)