Skip to content

Commit d2908c4

Browse files
authored
Merge pull request #132 from GabrielSalla/improve-test-time
Improve test time
2 parents fa104c4 + 15bcc61 commit d2908c4

File tree

7 files changed

+27
-71
lines changed

7 files changed

+27
-71
lines changed

poetry.lock

Lines changed: 2 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ pyyaml = "^6.0.2"
2525
sqlalchemy = "^2.0.36"
2626

2727
[tool.poetry.group.dev.dependencies]
28-
isort = "*"
2928
mypy = "*"
3029
pytest = "*"
3130
pytest-asyncio = "*"
3231
pytest-cov = "*"
3332
pytest-mock = "*"
3433
pytest-rerunfailures = "*"
3534
ruff = "*"
36-
types-setuptools = "*"
3735
types-requests = "*"
3836
types-pyyaml = "*"
3937
types-pytz = "*"
40-
types-pymysql = "*"
4138
types-croniter = "*"
4239

4340
[tool.poetry.group.plugin-aws.dependencies]

tests/components/executor/test_event_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ async def long_sleep() -> None:
263263
async def test_run_timeout(caplog, monkeypatch, sample_monitor: Monitor):
264264
"""'run' should execute all the reactions and the timeout should be independent for each
265265
function"""
266-
monkeypatch.setattr(configs, "executor_reaction_timeout", 0.2)
266+
monkeypatch.setattr(configs, "executor_reaction_timeout", 0.1)
267267

268268
async def long_sleep(message_payload):
269-
await asyncio.sleep(1)
269+
await asyncio.sleep(0.5)
270270

271271
long_sleep_mock = AsyncMock(side_effect=long_sleep)
272272

273273
async def short_sleep(message_payload):
274-
await asyncio.sleep(0.1)
274+
await asyncio.sleep(0.01)
275275

276276
short_sleep_mock = AsyncMock(side_effect=short_sleep)
277277

@@ -295,8 +295,8 @@ async def short_sleep(message_payload):
295295
end_time = time.perf_counter()
296296

297297
total_time = end_time - start_time
298-
assert total_time > 1 - 0.001
299-
assert total_time < 1 + 0.03
298+
assert total_time > 0.4 - 0.001
299+
assert total_time < 0.4 + 0.03
300300

301301
assert long_sleep_mock.call_count == 4
302302
assert_message_in_log(caplog, "Timed out executing reaction", count=4)

tests/components/executor/test_monitor_handler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,18 +1114,18 @@ async def do_nothing(monitor): ...
11141114

11151115
async def test_heartbeat_routine(monkeypatch, sample_monitor: Monitor):
11161116
"""'_heartbeat_routine' should handle execution timeouts while running the monitor routines"""
1117-
monkeypatch.setattr(monitor_handler.configs, "executor_monitor_heartbeat_time", 0.5)
1117+
monkeypatch.setattr(monitor_handler.configs, "executor_monitor_heartbeat_time", 0.1)
11181118

11191119
await sample_monitor.refresh()
11201120
assert sample_monitor.last_heartbeat is None
11211121

11221122
heartbeat_task = asyncio.create_task(monitor_handler._heartbeat_routine(sample_monitor))
11231123

11241124
await asyncio.sleep(0)
1125-
for _ in range(4):
1125+
for _ in range(2):
11261126
await sample_monitor.refresh()
11271127
assert sample_monitor.last_heartbeat > now() - timedelta(seconds=0.1)
1128-
await asyncio.sleep(0.5)
1128+
await asyncio.sleep(0.1)
11291129

11301130
heartbeat_task.cancel()
11311131

@@ -1205,11 +1205,11 @@ async def test_run_monitor_heartbeat(monkeypatch, sample_monitor: Monitor):
12051205
"""'run' should handle execution timeouts while running the monitor routines"""
12061206

12071207
async def sleep(monitor, tasks):
1208-
await asyncio.sleep(2.1)
1208+
await asyncio.sleep(0.5)
12091209

12101210
monkeypatch.setattr(monitor_handler, "_run_routines", sleep)
12111211

1212-
monkeypatch.setattr(monitor_handler.configs, "executor_monitor_heartbeat_time", 0.5)
1212+
monkeypatch.setattr(monitor_handler.configs, "executor_monitor_heartbeat_time", 0.1)
12131213

12141214
await sample_monitor.refresh()
12151215
assert sample_monitor.last_heartbeat is None
@@ -1222,7 +1222,7 @@ async def sleep(monitor, tasks):
12221222
for _ in range(4):
12231223
await sample_monitor.refresh()
12241224
assert sample_monitor.last_heartbeat > now() - timedelta(seconds=0.1)
1225-
await asyncio.sleep(0.5)
1225+
await asyncio.sleep(0.1)
12261226

12271227
await run_task
12281228

tests/components/executor/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ async def test_change_visibility_loop(mocker, monkeypatch, clear_queue):
2323
monkeypatch.setattr(
2424
message_queue.queue._config, # type: ignore[attr-defined]
2525
"queue_wait_message_time",
26-
0.2,
26+
0.1,
2727
)
2828
change_visibility_spy: MagicMock = mocker.spy(message_queue, "change_visibility")
2929

3030
message = InternalMessage(json.dumps({"type": "type", "payload": "payload"}))
3131

3232
task = asyncio.create_task(runner._change_visibility_loop(message))
33-
await asyncio.sleep(1.0)
33+
await asyncio.sleep(0.5)
3434
task.cancel()
3535

3636
await asyncio.sleep(0.1)

tests/module_loader/test_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ def test_load_module_from_file_reload_replace_variables():
202202
module.v.append(10)
203203
assert module.v == [10]
204204

205-
# As python checks for the timestamp to change to reload a module, sleep for 1 second
206-
time.sleep(1)
205+
# As python checks for the timestamp to change to reload a module, sleep until the next second
206+
time.sleep(1 - time.time() % 1 + 0.01)
207207

208208
module = loader.load_module_from_file(module_path)
209209

tests/plugins/aws/queues/sqs/test_sqs_queue.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def test_get_message_not_deleted():
266266
"url": "http://motoserver:5000/123456789012/app",
267267
"region": "us-east-1",
268268
"create_queue": True,
269-
"queue_wait_message_time": 2,
269+
"queue_wait_message_time": 0,
270270
"queue_visibility_time": 1,
271271
}
272272
)
@@ -281,7 +281,7 @@ async def test_get_message_not_deleted():
281281
message = await queue.get_message()
282282
assert message is None
283283

284-
await asyncio.sleep(1)
284+
await asyncio.sleep(2)
285285

286286
message = await queue.get_message()
287287
assert message is not None
@@ -298,7 +298,7 @@ async def test_change_visibility():
298298
"url": "http://motoserver:5000/123456789012/app",
299299
"region": "us-east-1",
300300
"create_queue": True,
301-
"queue_wait_message_time": 2,
301+
"queue_wait_message_time": 0,
302302
"queue_visibility_time": 1,
303303
}
304304
)
@@ -310,12 +310,11 @@ async def test_change_visibility():
310310
assert message is not None
311311
assert message.content == {"type": "test", "payload": {"a": 1}}
312312

313-
for _ in range(3):
314-
await queue.change_visibility(message)
315-
new_message = await queue.get_message()
316-
assert new_message is None
313+
await queue.change_visibility(message)
314+
new_message = await queue.get_message()
315+
assert new_message is None
317316

318-
await asyncio.sleep(1)
317+
await asyncio.sleep(2)
319318

320319
message = await queue.get_message()
321320
assert message is not None
@@ -331,8 +330,8 @@ async def test_delete_message():
331330
"url": "http://motoserver:5000/123456789012/app",
332331
"region": "us-east-1",
333332
"create_queue": True,
334-
"queue_wait_message_time": 2,
335-
"queue_visibility_time": 15,
333+
"queue_wait_message_time": 0,
334+
"queue_visibility_time": 0,
336335
}
337336
)
338337
await queue.init()
@@ -345,7 +344,7 @@ async def test_delete_message():
345344

346345
await queue.delete_message(message)
347346

348-
await asyncio.sleep(2)
347+
await asyncio.sleep(0.5)
349348

350349
message = await queue.get_message()
351350
assert message is None

0 commit comments

Comments
 (0)