Skip to content

Commit c50fefb

Browse files
committed
Improving long waits for cert test
1 parent 045a72a commit c50fefb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/python_testing/TC_CGEN_2_2.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def steps_TC_CGEN_2_2(self) -> list[TestStep]:
291291
TestStep(33, 'TH1 waits for PIXIT.CGEN.FailsafeExpiryLengthSeconds.'),
292292
TestStep(34, 'TH1 reads the TrustedRootCertificates attribute from the Node Operational Credentials cluster.'),
293293
# TestStep(35, '''TH2 sends ArmFailSafe command to the DUT with ExpiryLengthSeconds field set to PIXIT.CGEN.FailsafeExpiryLengthSeconds
294-
# and the Breadcrumb value as 1.'''),
294+
# and the Breadcrumb value as 1.'''),
295295
TestStep(36, 'TH1 sends ArmFailSafe command to the DUT with ExpiryLengthSeconds field set to 0.'),
296296
TestStep(37, 'TH1 sends ArmFailSafe command to the DUT with ExpiryLengthSeconds field set to maxFailsafe.'),
297297
TestStep(38, 'TH1 saves the current wall time clock in seconds as Tstart,'),
@@ -382,9 +382,14 @@ async def test_TC_CGEN_2_2(self):
382382

383383
# Get the start time to measure the elapsed time
384384
start_time = time.time()
385+
target_time = start_time + (maxFailsafe + .5)
385386

386387
# Wait for the full duration of the maxFailsafe time with an additional 0.5-second buffer
387-
await asyncio.sleep(maxFailsafe + 0.5)
388+
while time.time() < target_time:
389+
try:
390+
await asyncio.sleep(0.1)
391+
except asyncio.CancelledError:
392+
continue
388393

389394
# Calculate and log the elapsed time since the start of the wait
390395
elapsed_time = time.time() - start_time
@@ -686,10 +691,9 @@ async def test_TC_CGEN_2_2(self):
686691
# Wait the half of the maximum failsafe time using a while loop
687692
while time.time() < target_time:
688693
try:
689-
await asyncio.sleep(0.1) # Esperar un tiempo pequeño en cada iteración
694+
await asyncio.sleep(0.1)
690695
except asyncio.CancelledError:
691-
# Si se lanza el TimeoutError, simplemente lo ignoramos
692-
continue # Ignoramos el error y seguimos esperando hasta que se cumpla el tiempo objetivo
696+
continue
693697

694698
elapsed_time = time.time() - start_time
695699
logger.info(f'Step #33: {run_type} - Elapsed time: {elapsed_time} seconds after waiting for half of the maxFailsafe.')
@@ -720,12 +724,10 @@ async def test_TC_CGEN_2_2(self):
720724
target_time = start_time + maxFailsafe + 1
721725
while time.time() < target_time:
722726
try:
723-
await asyncio.sleep(0.1) # Esperar un tiempo pequeño en cada iteración
727+
await asyncio.sleep(0.1)
724728
except asyncio.CancelledError:
725-
# Si se lanza el TimeoutError, simplemente lo ignoramos
726-
continue # Ignoramos el error y seguimos esperando hasta que se cumpla el tiempo objetivo
729+
continue
727730

728-
# await asyncio.sleep(maxFailsafe + 1)
729731
elapsed_time = time.time() - start_time
730732
logger.info(f'Step #33: {run_type} - Failsafe timer (max_fail_safe) expired after {elapsed_time} seconds.')
731733

@@ -747,10 +749,8 @@ async def test_TC_CGEN_2_2(self):
747749
# self.step(35)
748750
# cmd = Clusters.GeneralCommissioning.Commands.ArmFailSafe(expiryLengthSeconds=maxFailsafe, breadcrumb=1)
749751
# resp = await self.send_single_cmd(
750-
# dev_ctrl=self.default_controller,
751-
# node_id=self.dut_node_id,
752-
# # dev_ctrl=TH2,
753-
# # node_id=newNodeId+1,
752+
# dev_ctrl=TH2,
753+
# node_id=newNodeId+1,
754754
# cmd=cmd)
755755
# # Verify that the DUT responds with ArmFailSafeResponse with ErrorCode as 'BusyWithOtherAdmin'(4)
756756
# logger.info(f'Step #35 - TH2 ArmFailSafeResponse with ErrorCode as BusyWithOtherAdmin ({resp.errorCode})')
@@ -826,7 +826,7 @@ async def test_TC_CGEN_2_2(self):
826826
target_time = start_time + (maxFailsafe / 2)
827827
# Make TH1 wait until the current time is greater than or equal to the target time
828828
while time.time() < target_time:
829-
time.sleep(0.1) # Wait for 100ms to avoid excessive CPU usage
829+
await asyncio.sleep(0.1)
830830

831831
# Check if the elapsed time since start_time has reached or exceeded half of the maxFailsafe time (maxFailsafe / 2).
832832
# If the current time surpasses the start time by at least half of the maxFailsafe time, the TH1 process is allowed to proceed.
@@ -879,7 +879,7 @@ async def test_TC_CGEN_2_2(self):
879879

880880
# Make TH1 wait until the current time is greater than or equal to the target time
881881
while time.time() < target_time:
882-
time.sleep(0.1) # Wait for 100ms to avoid excessive CPU usage
882+
await asyncio.sleep(0.1)
883883

884884
# Checks if the elapsed time from start_time has met or exceeded maxFailsafe
885885
# If the current time has passed the start time by at least maxFailsafe, the TH1 process can proceed

0 commit comments

Comments
 (0)