From 5fed3f23a70cea373987c150185a48dd2bf87edd Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 7 Dec 2022 16:00:30 -0500 Subject: [PATCH] Fix calling update_time_stamp from sub workflow --- ipsframework/services.py | 4 ++- tests/hello-world-nested/hello_driver_sub.py | 1 + tests/hello-world-nested/hello_worker_sub.py | 1 + .../test_hello-world-nested.py | 25 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ipsframework/services.py b/ipsframework/services.py index 1f990751..ad1d3015 100644 --- a/ipsframework/services.py +++ b/ipsframework/services.py @@ -1760,7 +1760,9 @@ def update_time_stamp(self, new_time_stamp=-1): Update time stamp on portal. """ event_data = {} - event_data['sim_name'] = self.sim_name + event_data['sim_name'] = self.sim_conf['__PORTAL_SIM_NAME'] + event_data['real_sim_name'] = self.sim_name + portal_data = {} portal_data['phystimestamp'] = new_time_stamp portal_data['eventtype'] = 'PORTALBRIDGE_UPDATE_TIMESTAMP' diff --git a/tests/hello-world-nested/hello_driver_sub.py b/tests/hello-world-nested/hello_driver_sub.py index 70892542..2756ac32 100644 --- a/tests/hello-world-nested/hello_driver_sub.py +++ b/tests/hello-world-nested/hello_driver_sub.py @@ -16,6 +16,7 @@ def step(self, timestamp=0.0, **keywords): except Exception: self.services.exception('Error accessing worker component') raise + self.services.update_time_stamp(1) self.services.call(worker_comp, 'step', 0.0) with open(self.OUTPUT_FILES.split()[0], 'w') as f: f.write("SUB OUTPUT FILE\n") diff --git a/tests/hello-world-nested/hello_worker_sub.py b/tests/hello-world-nested/hello_worker_sub.py index 940fd977..972755a5 100644 --- a/tests/hello-world-nested/hello_worker_sub.py +++ b/tests/hello-world-nested/hello_worker_sub.py @@ -12,3 +12,4 @@ def __init__(self, services, config): def step(self, timestamp=0.0, **keywords): print('Hello from HelloWorker - sub') self.services.info('Hello from HelloWorker - sub') + self.services.send_portal_event(event_comment='Hello from HelloWorker - sub') diff --git a/tests/hello-world-nested/test_hello-world-nested.py b/tests/hello-world-nested/test_hello-world-nested.py index 5032be1d..465509c4 100644 --- a/tests/hello-world-nested/test_hello-world-nested.py +++ b/tests/hello-world-nested/test_hello-world-nested.py @@ -1,5 +1,7 @@ import os import shutil +import json +import glob from ipsframework import Framework @@ -98,3 +100,26 @@ def test_hello_world_nested(tmpdir, capfd): lines = f.readlines() assert lines[0] == "SUB INPUT FILE\n" + + # check the simulation log json + json_files = glob.glob(str(tmpdir.join("hello_example_SUPER").join("simulation_log").join("*.json"))) + assert len(json_files) == 1 + with open(json_files[0], 'r') as json_file: + events = [json.loads(event) for event in json_file.readlines()] + + assert len(events) == 25 + assert events[-1]['eventtype'] == "IPS_END" + + codes = set(event["code"] for event in events) + + # Check that the sub wortflow writes to the same json file + assert len(codes) == 5 + assert "Framework" in codes + assert "DRIVERS_HELLO_HelloDriver" in codes + assert "WORKERS_HELLO_HelloWorker" in codes + assert "DRIVERS_HELLOSUB_HelloDriver" in codes + assert "WORKERSSUB_HELLO_HelloWorker" in codes + + # Check that phystimestamp get updated by the sub workflow + assert events[0]["phystimestamp"] == -1 + assert events[-1]["phystimestamp"] == 1