From 59b530be8283553a1bf8b454450d53a964ec83c4 Mon Sep 17 00:00:00 2001 From: "Budnick, Leon" Date: Fri, 15 Nov 2024 10:41:00 +0100 Subject: [PATCH] run v2 in ci instead of v1 --- .github/workflows/pat_integration.yml | 4 +- .../ReferenceTestV2/reference_consumer_v2.py | 2 +- .../ReferenceTestV2/reference_provider_v2.py | 7 ++- examples/ReferenceTestV2/run.py | 47 +++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 examples/ReferenceTestV2/run.py diff --git a/.github/workflows/pat_integration.yml b/.github/workflows/pat_integration.yml index cc002993..e827e0ff 100644 --- a/.github/workflows/pat_integration.yml +++ b/.github/workflows/pat_integration.yml @@ -28,10 +28,10 @@ jobs: - name: Run tests with tls enabled if: ${{ matrix.tls_enable }} - run: python -m examples.ReferenceTest.run --tls + run: python -m examples.ReferenceTestV2.run --tls timeout-minutes: 2 - name: Run tests with tls disabled if: ${{ !matrix.tls_enable }} - run: python -m examples.ReferenceTest.run + run: python -m examples.ReferenceTestV2.run timeout-minutes: 2 diff --git a/examples/ReferenceTestV2/reference_consumer_v2.py b/examples/ReferenceTestV2/reference_consumer_v2.py index fb679d3d..9b73042f 100644 --- a/examples/ReferenceTestV2/reference_consumer_v2.py +++ b/examples/ReferenceTestV2/reference_consumer_v2.py @@ -304,7 +304,7 @@ def run_ref_test(results_collector: ResultsCollector) -> ResultsCollector: # no results_collector.log_result(max(durations) <= 15, step, info) # noqa: PLR2004 step = "2b.2" info = "the Reference Provider grants subscriptions of at most 15 seconds (renew)" - subscription = next(client.subscription_mgr.subscriptions.values()) + subscription = list(client.subscription_mgr.subscriptions.values())[0] # noqa: RUF015 granted = subscription.renew(30000) print(f"renew granted = {granted}") results_collector.log_result(max(durations) <= 15, step, info) # noqa: PLR2004 diff --git a/examples/ReferenceTestV2/reference_provider_v2.py b/examples/ReferenceTestV2/reference_provider_v2.py index 81ff9d19..6631a4c0 100644 --- a/examples/ReferenceTestV2/reference_provider_v2.py +++ b/examples/ReferenceTestV2/reference_provider_v2.py @@ -180,8 +180,8 @@ def provide_realtime_data(sdc_provider: SdcProvider): waveform_provider.register_waveform_generator(waveform.Handle, wf_generator) -if __name__ == "__main__": - with pathlib.Path(__file__).parent.joinpath("logging_default.json") as f: +def run_provider(): + with pathlib.Path(__file__).parent.joinpath("logging_default.json").open() as f: logging_setup = json.load(f) logging.config.dictConfig(logging_setup) xtra_log_config = os.getenv("ref_xtra_log_cnf") # noqa:SIM112 @@ -471,3 +471,6 @@ def provide_realtime_data(sdc_provider: SdcProvider): sleep(5) except KeyboardInterrupt: print("Exiting...") + +if __name__ == "__main__": + run_provider() diff --git a/examples/ReferenceTestV2/run.py b/examples/ReferenceTestV2/run.py new file mode 100644 index 00000000..78d3b08e --- /dev/null +++ b/examples/ReferenceTestV2/run.py @@ -0,0 +1,47 @@ +"""Script that executes the plug-a-thon tests.""" + +import os +import pathlib +import platform +import sys +import threading +import uuid + +from sdc11073 import network + +from examples.ReferenceTestV2 import reference_provider_v2, reference_consumer_v2 + + +def setup(tls: bool): + os.environ['ref_search_epr'] = str(uuid.uuid4()) + if platform.system() == 'Darwin': + os.environ['ref_ip'] = next(str(adapter.ip) for adapter in network.get_adapters() if not adapter.is_loopback) + else: + os.environ['ref_ip'] = next(str(adapter.ip) for adapter in network.get_adapters() if adapter.is_loopback) + if tls: + certs_path = pathlib.Path(__file__).parent.parent.joinpath('certs') + assert certs_path.exists() + os.environ['ref_ca'] = str(certs_path) + os.environ['ref_ssl_passwd'] = 'dummypass' + + +def run() -> reference_consumer_v2.ResultsCollector: + threading.Thread(target=reference_provider_v2.run_provider, daemon=True).start() + return reference_consumer_v2.run_ref_test(reference_consumer_v2.ResultsCollector()) + + +def main(tls: bool): + setup(tls) + return run() + + +if __name__ == '__main__': + import argparse + + parser = argparse.ArgumentParser(description='run plug-a-thon tests') + parser.add_argument('--tls', action='store_true', help='Indicates whether tls encryption should be enabled.') + + args = parser.parse_args() + run_results = main(tls=args.tls) + run_results.print_summary() + sys.exit(bool(results.failed_count))