-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration test for multi-activity agreement #350
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1150758
Add integration tests for multi-activity agreement
azawlocki bb5a457
Add --config-override option for pytest tests
azawlocki 2c11749
Specify yagna release tag `0.6.` for use in `goth` tests
azawlocki 69c629d
Increase task timeout in `blender.py`
azawlocki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ ya-market = "0.1.0" | |
[tool.poe.tasks] | ||
test = "pytest --cov=yapapi --ignore tests/goth" | ||
goth-assets = "python -m goth create-assets tests/goth/assets" | ||
goth-tests = "pytest -svx tests/goth" | ||
goth-tests = "pytest -svx tests/goth --config-override docker-compose.build-environment.release-tag=0.6." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this parameter used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used to enforce using |
||
typecheck = "mypy ." | ||
codestyle = "black --check --diff ." | ||
_liccheck_export = "poetry export -E cli -f requirements.txt -o .requirements.txt" | ||
|
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
"""A requestor script for testing if multiple workers are run for an agreement.""" | ||
import asyncio | ||
from datetime import timedelta | ||
import logging | ||
|
||
from yapapi import Executor, Task | ||
from yapapi.log import enable_default_logger, log_event_repr # noqa | ||
from yapapi.package import vm | ||
|
||
|
||
async def main(): | ||
|
||
vm_package = await vm.repo( | ||
image_hash="9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae", | ||
min_mem_gib=0.5, | ||
min_storage_gib=2.0, | ||
) | ||
|
||
async def worker(work_ctx, tasks): | ||
"""Compute just one task and exit.""" | ||
async for task in tasks: | ||
work_ctx.run("/bin/sleep", "1") | ||
yield work_ctx.commit() | ||
task.accept_result() | ||
return | ||
|
||
async with Executor( | ||
budget=10.0, | ||
package=vm_package, | ||
max_workers=1, | ||
subnet_tag="goth", | ||
timeout=timedelta(minutes=6), | ||
event_consumer=log_event_repr, | ||
) as executor: | ||
|
||
tasks = [Task(data=n) for n in range(3)] | ||
async for task in executor.submit(worker, tasks): | ||
print(f"Task computed: {task}") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
enable_default_logger() | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
logging.getLogger("yapapi.events").addHandler(console_handler) | ||
|
||
asyncio.run(main()) |
86 changes: 86 additions & 0 deletions
86
tests/goth/test_multiactivity_agreement/test_multiactivity_agreement.py
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,86 @@ | ||
"""A goth test scenario for multi-activity agreements.""" | ||
from functools import partial | ||
import logging | ||
import os | ||
from pathlib import Path | ||
import re | ||
|
||
import pytest | ||
|
||
import goth.configuration | ||
from goth.runner import Runner | ||
from goth.runner.probe import RequestorProbe | ||
from goth.runner.log import configure_logging | ||
|
||
|
||
logger = logging.getLogger("goth.test.multiactivity_agreement") | ||
|
||
|
||
async def assert_agreement_created(events): | ||
"""Assert that `AgreementCreated` event occurs.""" | ||
|
||
async for line in events: | ||
m = re.match(r"AgreementCreated\(agr_id='([^']+)'", line) | ||
if m: | ||
return m.group(1) | ||
raise AssertionError("Expected AgreementCreated event") | ||
|
||
|
||
async def assert_multiple_workers_run(agr_id, events): | ||
"""Assert that more than one worker is run with given `agr_id`. | ||
|
||
Fails if a worker failure is detected or if a worker has run for another agreement. | ||
""" | ||
workers_finished = 0 | ||
|
||
async for line in events: | ||
m = re.match(r"WorkerFinished\(agr_id='([^']+)'", line) | ||
if m: | ||
worker_agr_id = m.group(1) | ||
assert worker_agr_id == agr_id, "Worker run for another agreement" | ||
assert line.endswith(" exc_info=None)"), "Worker finished with error" | ||
workers_finished += 1 | ||
elif re.match("ComputationFinished", line): | ||
break | ||
|
||
assert workers_finished > 1, ( | ||
f"Only {workers_finished} worker(s) run for agreement {agr_id}, " "expected more than one" | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_multiactivity_agreement(project_dir: Path, log_dir: Path, config_overrides) -> None: | ||
|
||
configure_logging(log_dir) | ||
|
||
# Override the default test configuration to create only one provider node | ||
nodes = [ | ||
{"name": "requestor", "type": "Requestor"}, | ||
{"name": "provider-1", "type": "VM-Wasm-Provider", "use-proxy": True}, | ||
] | ||
config_overrides.append(("nodes", nodes)) | ||
goth_config = goth.configuration.load_yaml( | ||
project_dir / "tests" / "goth" / "assets" / "goth-config.yml", | ||
config_overrides, | ||
) | ||
|
||
runner = Runner(base_log_dir=log_dir, compose_config=goth_config.compose_config) | ||
|
||
async with runner(goth_config.containers): | ||
|
||
requestor = runner.get_probes(probe_type=RequestorProbe)[0] | ||
|
||
async with requestor.run_command_on_host( | ||
str(Path(__file__).parent / "requestor.py"), env=os.environ | ||
) as (_cmd_task, cmd_monitor): | ||
|
||
# Wait for agreement | ||
assertion = cmd_monitor.add_assertion(assert_agreement_created) | ||
agr_id = await assertion.wait_for_result(timeout=30) | ||
|
||
# Wait for multiple workers run for the agreement | ||
assertion = cmd_monitor.add_assertion( | ||
partial(assert_multiple_workers_run, agr_id), | ||
name=f"assert_multiple_workers_run({agr_id})", | ||
) | ||
await assertion.wait_for_result(timeout=60) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requestor will have to wait 10 minutes if any provider is broken (there are currently providers that are signing agreements and then doing nothing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. But the problem with the timeout being too low is recurring and sometimes affects all providers (for example it happened after
0.6.3
yagna
release, when many providers needed to refresh their VM images and were unable to do so for a long time since the activities were interrupted by ourblender.py
requestor due to 2 minute timeouts).