Skip to content

Commit

Permalink
Disable record_interruptions
Browse files Browse the repository at this point in the history
Causes buggy behaviour with resume/pause sequences
  • Loading branch information
Tom-Willemsen committed Aug 28, 2024
1 parent ccc75be commit 7e55f85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 62 deletions.
1 change: 0 additions & 1 deletion src/ibex_bluesky_core/run_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def get_run_engine() -> RunEngine:
during_task=dt,
call_returns_result=True, # Will be default in a future bluesky version.
)
RE.record_interruptions = True

log_callback = DocLoggingCallback()
RE.subscribe(log_callback)
Expand Down
7 changes: 3 additions & 4 deletions tests/callbacks/test_document_logging_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ def basic_plan() -> Generator[Msg, None, None]:
result: RunEngineResult = RE(basic_plan())
filepath = log_location / f"{result.run_start_uids[0]}.log"

for i in range(0, 3):
for i in range(0, 2):
assert m.call_args_list[i].args == (filepath, "a")
# Checks that the file is opened 3 times, for open, descriptor then stop
# Checks that the file is opened 2 times, for open and then stop

handle = m()
document = json.loads(handle.write.mock_calls[-1].args[0])

# In the stop document to be written, check that the run is successful
assert document["document"]["exit_status"] == "success"
# In the stop document to be written, check that the run is successful with no interruptions
assert document["document"]["num_events"]["interruptions"] == 0
59 changes: 2 additions & 57 deletions tests/test_run_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import bluesky.plan_stubs as bps
import pytest
from bluesky.run_engine import RunEngineResult
from bluesky.utils import Msg, RequestAbort, RequestStop, RunEngineInterrupted
from bluesky.utils import Msg, RequestAbort, RunEngineInterrupted

from ibex_bluesky_core.run_engine import _DuringTask, get_run_engine

Expand Down Expand Up @@ -68,62 +68,7 @@ def basic_plan() -> Generator[Msg, None, None]:
RE(basic_plan())

# Expected basic series of document types for a start run/stop run sequence.
assert documents == ["start", "descriptor", "stop"]


def test_run_engine_emits_documents_for_interruptions(RE):
def pausing_plan() -> Generator[Msg, None, None]:
yield from bps.open_run(md={"reason": "run one start"})
yield from bps.pause()
yield from bps.close_run(reason="run one end")
yield from bps.open_run(md={"reason": "run two start"})
yield from bps.pause()
yield from bps.close_run(reason="run two end")

doc_types = []
docs = []

def sub(typ, doc):
doc_types.append(typ)
docs.append({typ: doc})

RE.subscribe(sub)

with pytest.raises(RunEngineInterrupted):
RE(pausing_plan())

with pytest.raises(RunEngineInterrupted):
RE.resume()

result: RunEngineResult = RE.stop()

assert doc_types == [
"start", # Open run 1
"descriptor", # Open run descriptor
"event", # First pause
"event", # Resume
"stop", # Close run 1
"start", # Open run 2
"descriptor", # Open run descriptor
"event", # Second pause
"stop", # Close run 2
]

assert docs[0]["start"]["reason"] == "run one start"
assert docs[2]["event"]["data"] == {"interruption": "pause"}
assert docs[3]["event"]["data"] == {"interruption": "resume"}
assert docs[4]["stop"]["reason"] == "run one end"

assert docs[5]["start"]["reason"] == "run two start"
assert docs[7]["event"]["data"] == {"interruption": "pause"}
assert docs[8]["stop"]["reason"] == "" # Stopped by run engine, *not* our close_run

assert len(result.run_start_uids) == 2 # Both runs started
assert result.plan_result == RE.NO_PLAN_RETURN
assert result.exit_status == "success"
assert result.interrupted
assert result.exception == RequestStop
assert result.reason == ""
assert documents == ["start", "stop"]


def test_during_task_does_wait_with_small_timeout():
Expand Down

0 comments on commit 7e55f85

Please sign in to comment.