Skip to content

Commit a6eae7e

Browse files
committed
Update to new config problems
1 parent 438062c commit a6eae7e

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

tests/benchmark/conftest.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import pytest
77

8-
from dispatcher.brokers.pg_notify import get_connection
9-
from dispatcher.main import DispatcherMain
8+
from dispatcher.brokers.pg_notify import create_connection
9+
from dispatcher.config import DispatcherSettings
10+
from dispatcher.factories import from_settings
1011

1112

1213
class PoolServer:
@@ -17,6 +18,9 @@ class PoolServer:
1718
which will run (and stop) the relevant dispatcher code in a background process.
1819
"""
1920

21+
def __init__(self, config):
22+
self.config = config
23+
2024
def run_benchmark_test(self, queue_in, queue_out, times):
2125
print(f'submitting message to pool server {times}')
2226
queue_in.put(str(times))
@@ -27,8 +31,10 @@ def run_benchmark_test(self, queue_in, queue_out, times):
2731
raise Exception('Test subprocess runner exception, look back in logs')
2832

2933
@classmethod
30-
async def run_pool(cls, queue_in, queue_out, workers, function='lambda: __import__("time").sleep(0.01)'):
31-
dispatcher = DispatcherMain({"producers": {"brokers": {}}, "pool": {"max_workers": workers}})
34+
async def run_pool(cls, config, queue_in, queue_out, workers, function='lambda: __import__("time").sleep(0.01)'):
35+
this_config = config.copy()
36+
this_config['service']['pool_kwargs']['max_workers'] = workers
37+
dispatcher = from_settings(DispatcherSettings(this_config))
3238
pool = dispatcher.pool
3339
await pool.start_working(dispatcher)
3440
queue_out.put('ready')
@@ -58,10 +64,10 @@ async def run_pool(cls, queue_in, queue_out, workers, function='lambda: __import
5864
print('exited forever loop of pool server')
5965

6066
@classmethod
61-
def run_pool_loop(cls, queue_in, queue_out, workers, **kwargs):
67+
def run_pool_loop(cls, config, queue_in, queue_out, workers, **kwargs):
6268
loop = asyncio.get_event_loop()
6369
try:
64-
loop.run_until_complete(cls.run_pool(queue_in, queue_out, workers, **kwargs))
70+
loop.run_until_complete(cls.run_pool(config, queue_in, queue_out, workers, **kwargs))
6571
except Exception:
6672
import traceback
6773

@@ -79,7 +85,7 @@ def run_pool_loop(cls, queue_in, queue_out, workers, **kwargs):
7985
def start_server(self, workers, **kwargs):
8086
self.queue_in = multiprocessing.Queue()
8187
self.queue_out = multiprocessing.Queue()
82-
process = multiprocessing.Process(target=self.run_pool_loop, args=(self.queue_in, self.queue_out, workers), kwargs=kwargs)
88+
process = multiprocessing.Process(target=self.run_pool_loop, args=(self.config, self.queue_in, self.queue_out, workers), kwargs=kwargs)
8389
process.start()
8490
return process
8591

@@ -118,7 +124,7 @@ def run_benchmark_test(self, queue_in, queue_out, times):
118124
queue_in.put('wake')
119125
print('sending pg_notify messages')
120126
function = 'lambda: __import__("time").sleep(0.01)'
121-
conn = get_connection({"conninfo": CONNECTION_STRING})
127+
conn = create_connection(**{"conninfo": CONNECTION_STRING})
122128
with conn.cursor() as cur:
123129
for i in range(times):
124130
cur.execute(f"SELECT pg_notify('test_channel', '{function}');")
@@ -127,10 +133,10 @@ def run_benchmark_test(self, queue_in, queue_out, times):
127133
print(f'finished running round with {times} messages, got: {message_in}')
128134

129135
@classmethod
130-
async def run_pool(cls, queue_in, queue_out, workers):
131-
dispatcher = DispatcherMain(
132-
{"producers": {"brokers": {"pg_notify": {"conninfo": CONNECTION_STRING}, "channels": CHANNELS}}, "pool": {"max_workers": workers}}
133-
)
136+
async def run_pool(cls, config, queue_in, queue_out, workers):
137+
this_config = config.copy()
138+
this_config['service']['pool_kwargs']['max_workers'] = workers
139+
dispatcher = from_settings(DispatcherSettings(this_config))
134140
await dispatcher.start_working()
135141
# Make sure the dispatcher is listening before starting the tests which will submit messages
136142
for producer in dispatcher.producers:
@@ -157,12 +163,12 @@ async def run_pool(cls, queue_in, queue_out, workers):
157163

158164

159165
@pytest.fixture
160-
def with_pool_server():
161-
server_thing = PoolServer()
166+
def with_pool_server(test_settings):
167+
server_thing = PoolServer(test_settings.serialize())
162168
return server_thing.with_server
163169

164170

165171
@pytest.fixture
166-
def with_full_server():
167-
server_thing = FullServer()
172+
def with_full_server(test_settings):
173+
server_thing = FullServer(test_settings.serialize())
168174
return server_thing.with_server

tests/benchmark/test_control.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import pytest
44

5-
from dispatcher.control import Control
6-
from dispatcher.brokers.pg_notify import get_connection
5+
from dispatcher.brokers.pg_notify import create_connection
6+
from dispatcher.factories import get_control_from_settings
77

88

99
@pytest.mark.benchmark(group="control")
10-
def test_alive_benchmark(benchmark, with_full_server, conn_config):
11-
control = Control('test_channel', config=conn_config)
10+
def test_alive_benchmark(benchmark, with_full_server, test_settings):
11+
control = get_control_from_settings(settings=test_settings)
1212

1313
def alive_check():
1414
r = control.control_with_reply('alive')
@@ -20,11 +20,11 @@ def alive_check():
2020

2121
@pytest.mark.benchmark(group="control")
2222
@pytest.mark.parametrize('messages', [0, 3, 4, 5, 10, 100])
23-
def test_alive_benchmark_while_busy(benchmark, with_full_server, conn_config, messages):
24-
control = Control('test_channel', config=conn_config)
23+
def test_alive_benchmark_while_busy(benchmark, with_full_server, test_settings, messages):
24+
control = get_control_from_settings(settings=test_settings)
2525

2626
def alive_check():
27-
submit_conn = get_connection(conn_config)
27+
submit_conn = create_connection(**test_settings.brokers['pg_notify']['config'])
2828
function = 'lambda: __import__("time").sleep(0.01)'
2929
with submit_conn.cursor() as cur:
3030
for i in range(messages):

0 commit comments

Comments
 (0)