Skip to content

Commit

Permalink
fix flaky test caused by timing issue (Azure#26795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZejiaJiang authored Jan 30, 2022
1 parent 86f6bcf commit 9126604
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> properties = new HashMap<>();

Expand All @@ -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
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit 9126604

Please sign in to comment.