-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #495 from golemfactory/az/fix-assertion-reporting
Ensure assertion success/failure is reported in EventMonitor
- Loading branch information
Showing
5 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ exclude= '/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|_build| | |
|
||
[tool.poetry] | ||
name = "goth" | ||
version = "0.2.3" | ||
version = "0.2.4" | ||
description = "Golem Test Harness - integration testing framework" | ||
authors = ["Golem Factory <[email protected]>"] | ||
license = "GPL-3.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Unit tests related to the use of assertion monitors in Runner.""" | ||
|
||
import asyncio | ||
from pathlib import Path | ||
import tempfile | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from goth.assertions.monitor import EventMonitor | ||
from goth.runner import Runner, TemporalAssertionError | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_check_assertions(caplog): | ||
"""Test the `Runner.check_assertion_errors()` method.""" | ||
|
||
runner = Runner( | ||
base_log_dir=Path(tempfile.mkdtemp()), | ||
compose_config=Mock(), | ||
) | ||
|
||
async def assertion(events): | ||
async for _ in events: | ||
break | ||
async for _ in events: | ||
raise AssertionError("Just failing") | ||
|
||
idle_monitor = EventMonitor() | ||
idle_monitor.start() | ||
busy_monitor = EventMonitor() | ||
busy_monitor.add_assertion(assertion) | ||
busy_monitor.start() | ||
|
||
await asyncio.sleep(0.1) | ||
runner.check_assertion_errors(idle_monitor, busy_monitor) | ||
|
||
await busy_monitor.add_event(1) | ||
await asyncio.sleep(0.1) | ||
runner.check_assertion_errors(idle_monitor, busy_monitor) | ||
|
||
await busy_monitor.add_event(2) | ||
await asyncio.sleep(0.1) | ||
# Assertion failure should be logged at this point | ||
assert any(record.levelname == "ERROR" for record in caplog.records) | ||
# And `check_assertion_errors()` should raise an exception | ||
with pytest.raises(TemporalAssertionError): | ||
runner.check_assertion_errors(idle_monitor, busy_monitor) | ||
|
||
await busy_monitor.stop() | ||
await idle_monitor.stop() | ||
with pytest.raises(TemporalAssertionError): | ||
runner.check_assertion_errors(idle_monitor, busy_monitor) |