Fix flakiness in DefaultPlaybackSessionManagerTest

Two of the sessions are finished at the same time in the test
and the order of the corresponding callbacks depends on the randomly
generated session string and the order these strings are stored in a
HashSet.

Update test to assert both callbacks are called and they contain the
right arguments, but don't assert on the order of these two callbacks.

PiperOrigin-RevId: 424548819
This commit is contained in:
tonihei 2022-01-27 09:43:19 +00:00 committed by Andrew Lewis
parent 2876908729
commit c9e2a9eb30

View File

@ -788,18 +788,16 @@ public final class DefaultPlaybackSessionManagerTest {
inOrder inOrder
.verify(mockListener) .verify(mockListener)
.onSessionCreated(eq(eventTimeFirstTimelineWindowOnly2), thirdId.capture()); .onSessionCreated(eq(eventTimeFirstTimelineWindowOnly2), thirdId.capture());
// The sessions may finish at the same time, so the order of these two callbacks is undefined.
ArgumentCaptor<String> finishedSessions = ArgumentCaptor.forClass(String.class);
inOrder inOrder
.verify(mockListener) .verify(mockListener, times(2))
.onSessionFinished( .onSessionFinished(
eventTimeSecondTimeline, eq(eventTimeSecondTimeline),
firstId.getValue(), finishedSessions.capture(),
/* automaticTransitionToNextPlayback= */ false); /* automaticTransitionToNextPlayback= */ eq(false));
inOrder assertThat(finishedSessions.getAllValues())
.verify(mockListener) .containsExactly(firstId.getValue(), thirdId.getValue());
.onSessionFinished(
eventTimeSecondTimeline,
thirdId.getValue(),
/* automaticTransitionToNextPlayback= */ false);
inOrder.verify(mockListener).onSessionActive(eventTimeSecondTimeline, secondId.getValue()); inOrder.verify(mockListener).onSessionActive(eventTimeSecondTimeline, secondId.getValue());
inOrder.verifyNoMoreInteractions(); inOrder.verifyNoMoreInteractions();
} }