From 9126604d2290db635c970c3047608d0617369dde Mon Sep 17 00:00:00 2001 From: ZejiaJiang <96095733+ZejiaJiang@users.noreply.github.com> Date: Sun, 30 Jan 2022 16:53:54 +0800 Subject: [PATCH] fix flaky test caused by timing issue (#26795) --- .../messaging/eventhubs/EventProcessorClientTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorClientTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorClientTest.java index cd30bfcd8c948..9fcd0bd4ec66f 100644 --- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorClientTest.java +++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorClientTest.java @@ -286,6 +286,7 @@ public void testProcessSpansWithoutDiagnosticId() throws Exception { when(eventData3.getSequenceNumber()).thenReturn(3L); when(eventData3.getOffset()).thenReturn(150L); when(eventData3.getEnqueuedTime()).thenReturn(Instant.ofEpochSecond(1560639208)); + final int numberOfEvents = 3; Map properties = new HashMap<>(); @@ -305,7 +306,7 @@ public void testProcessSpansWithoutDiagnosticId() throws Exception { final SampleCheckpointStore checkpointStore = new SampleCheckpointStore(); - CountDownLatch countDownLatch = new CountDownLatch(3); + CountDownLatch countDownLatch = new CountDownLatch(numberOfEvents); TestPartitionProcessor testPartitionProcessor = new TestPartitionProcessor(); testPartitionProcessor.countDownLatch = countDownLatch; //Act @@ -319,9 +320,10 @@ public void testProcessSpansWithoutDiagnosticId() throws Exception { assertTrue(success); - //Assert - verify(tracer1, times(3)).start(eq("EventHubs.process"), any(), eq(ProcessKind.PROCESS)); - verify(tracer1, times(3)).end(eq("success"), isNull(), any()); + // This is one less because the processEvent is called before the end span call, so it is possible for + // to reach this line without calling it the 5th time yet. (Timing issue.) + verify(tracer1, times(numberOfEvents)).start(eq("EventHubs.process"), any(), eq(ProcessKind.PROCESS)); + verify(tracer1, atLeast(numberOfEvents - 1)).end(eq("success"), isNull(), any()); } /**