forked from wandb/wandb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(launch): Improve run stopping robustness for launch runs (wandb…
- Loading branch information
1 parent
e583691
commit 50d613f
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
tests/pytest_tests/system_tests/test_launch/test_job_status_tracker.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,44 @@ | ||
import base64 | ||
from unittest import mock | ||
from unittest.mock import MagicMock | ||
|
||
import wandb | ||
from wandb.sdk.launch.agent.job_status_tracker import JobAndRunStatusTracker | ||
|
||
|
||
def test_check_stop_run_not_exist(wandb_init): | ||
job_tracker = JobAndRunStatusTracker( | ||
"run_queue_item_id", "test-queue", MagicMock(), MagicMock() | ||
) | ||
run = wandb_init(id="testrun") | ||
api = wandb.InternalApi() | ||
mock_launch_project = MagicMock() | ||
mock_launch_project.target_entity = run._entity | ||
mock_launch_project.target_project = run._project | ||
mock_launch_project.run_id = run._run_id + "a" | ||
job_tracker.update_run_info(mock_launch_project) | ||
|
||
res = job_tracker.check_wandb_run_stopped(api) | ||
assert not res | ||
run.finish() | ||
|
||
|
||
def test_check_stop_run_exist_stopped(user, wandb_init): | ||
mock.patch("wandb.sdk.wandb_run.thread.interrupt_main", lambda x: None) | ||
job_tracker = JobAndRunStatusTracker( | ||
"run_queue_item_id", "test-queue", MagicMock(), MagicMock() | ||
) | ||
run = wandb_init(id="testrun", entity=user) | ||
print(run._entity) | ||
api = wandb.InternalApi() | ||
encoded_run_id = base64.standard_b64encode( | ||
f"Run:v1:testrun:{run._project}:{run._entity}".encode() | ||
).decode("utf-8") | ||
mock_launch_project = MagicMock() | ||
mock_launch_project.target_entity = run._entity | ||
mock_launch_project.target_project = run._project | ||
mock_launch_project.run_id = run._run_id | ||
job_tracker.update_run_info(mock_launch_project) | ||
assert api.stop_run(encoded_run_id) | ||
assert job_tracker.check_wandb_run_stopped(api) | ||
run.finish() |
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