From 3a2a0ca7b4b2339ebf14dcf2d7feb38d736dd106 Mon Sep 17 00:00:00 2001 From: khoaguin Date: Fri, 27 Sep 2024 14:47:10 +0700 Subject: [PATCH] [tests/scenarios] adding a try catch in `admin_sync` --- tests/scenariosv2/l0_test.py | 26 ++++++++++++++++---------- tests/scenariosv2/sim/core.py | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/scenariosv2/l0_test.py b/tests/scenariosv2/l0_test.py index 7aa086b043c..c141fdd1039 100644 --- a/tests/scenariosv2/l0_test.py +++ b/tests/scenariosv2/l0_test.py @@ -300,19 +300,25 @@ async def admin_sync( to_ = to_client.metadata.server_side_type while not ctx.events.is_set(exit_after): - await asyncio.sleep(random.uniform(5, 10)) + try: + await asyncio.sleep(random.uniform(3, 5)) + + ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Checking") + result = sy.sync(from_client, to_client) + if isinstance(result, sy.SyftSuccess): + continue - ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Checking") - result = sy.sync(from_client, to_client) - if isinstance(result, sy.SyftSuccess): - continue + ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Result={result}") + result._share_all() + result._sync_all() - ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Result={result}") - result._share_all() - result._sync_all() + ctx.events.trigger(trigger) + ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Synced") - ctx.events.trigger(trigger) - ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Synced") + except Exception as e: + ctx.logger.error(f"Admin {from_}: Sync {from_}->{to_} - Error: {str(e)}") + ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Waiting a bit..") + await asyncio.sleep(random.uniform(2, 4)) ctx.logger.info(f"Admin {from_}: Sync {from_}->{to_} - Closed") diff --git a/tests/scenariosv2/sim/core.py b/tests/scenariosv2/sim/core.py index b79f4f7b038..341d799d9da 100644 --- a/tests/scenariosv2/sim/core.py +++ b/tests/scenariosv2/sim/core.py @@ -184,6 +184,7 @@ async def wrapper(ctx: SimulatorContext, *args, **kwargs): if _trigger: ctx.events.trigger(_trigger) + ctx.logger.info(f"Triggering event: {_trigger.name}") return result except Exception as e: