Commit c57871bd authored by Cyril Guilloud's avatar Cyril Guilloud
Browse files

Merge branch '2873-test-failure-test_data_policy_event' into 'master'

Resolve "test failure: test_data_policy_event"

Closes #2873

See merge request !3909
parents 3f12c2fb e2819aff
Pipeline #51618 failed with stages
in 105 minutes and 28 seconds
......@@ -1050,51 +1050,51 @@ def test_session_ending(
def test_data_policy_event(session, esrf_data_policy):
e = channels.EventChannel(f"{session.name}:esrf_data_policy")
full_event_list = list()
called_cbk = {"nb": 0}
called = gevent.event.Event()
event_channel = channels.EventChannel(f"{session.name}:esrf_data_policy")
event_queue = gevent.queue.Queue()
def f(events_list):
# global last_event
called_cbk["nb"] += 1
full_event_list.extend(events_list)
called.set()
def event_callback(events):
for event in events:
event_queue.put(event)
e.register_callback(f)
def wait_for_event_callback():
# give the hand to gevent loop and wait callback to be called
with gevent.Timeout(1):
called.wait()
called.clear()
event_channel.register_callback(event_callback)
scan_saving = session.scan_saving
wait_for_event_callback()
assert called_cbk["nb"] == 1
assert full_event_list[-1]["event_type"] == ESRFDataPolicyEvent.Enable
scan_saving.newproposal("hg123")
wait_for_event_callback()
assert called_cbk["nb"] == 2
assert full_event_list[-1]["event_type"] == ESRFDataPolicyEvent.Change
assert full_event_list[-1]["value"]["message"] == "Proposal set to 'hg123'"
scan_saving.newcollection("sample1")
scan_saving.newdataset("42")
create_dataset(scan_saving)
scan_saving.enddataset()
create_dataset(scan_saving)
scan_saving.endproposal()
wait_for_event_callback()
assert len(full_event_list) == 5
wait_for_event_callback()
session.disable_esrf_data_policy()
wait_for_event_callback()
assert full_event_list[-1]["event_type"] == ESRFDataPolicyEvent.Disable
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Enable
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Change
assert event["value"]["message"] == "Proposal set to 'hg123'"
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Change
assert event["value"]["message"] == "Dataset collection set to 'sample1'"
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Change
assert event["value"]["message"] == "Dataset set to '0042'"
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Change
assert event["value"]["message"] == "Dataset set to '0001'"
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Change
assert event["value"]["message"] == f"Proposal set to '{scan_saving.proposal_name}'"
event = event_queue.get(timeout=3)
assert event["event_type"] == ESRFDataPolicyEvent.Disable
def test_date_in_basepath(session, icat_logbook_subscriber, esrf_data_policy):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment