-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d908fe5
commit dfb159f
Showing
4 changed files
with
49 additions
and
6 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
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,43 @@ | ||
from concurrent.futures import Future | ||
from threading import Event | ||
|
||
import pytest | ||
|
||
from blueapi.core import BlueskyContext | ||
from blueapi.worker import RunEngineWorker, RunPlan, Worker, WorkerEvent, WorkerState | ||
|
||
|
||
@pytest.fixture | ||
def context() -> BlueskyContext: | ||
ctx = BlueskyContext() | ||
ctx.with_startup_script("blueapi.startup.example") | ||
return ctx | ||
|
||
|
||
@pytest.fixture | ||
def worker(context: BlueskyContext) -> Worker: | ||
worker = RunEngineWorker(context) | ||
yield worker | ||
worker.stop() | ||
|
||
|
||
def test_stop(worker: Worker) -> None: | ||
worker.start() | ||
|
||
|
||
def test_submit(worker: Worker) -> None: | ||
worker.start() | ||
started = Future() | ||
|
||
def process_event(event: WorkerEvent, task_id: str) -> None: | ||
started.set_result(event) | ||
|
||
worker.worker_events.subscribe(process_event) | ||
worker.submit_task( | ||
"test", | ||
RunPlan( | ||
name="sleep", | ||
params={"time": 0.1}, | ||
), | ||
) | ||
assert started.result(timeout=5.0).status.state is WorkerState.RUNNING |