Skip to content

Commit

Permalink
Fix flaky test in WebViewRumEventConsumerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Nov 15, 2023
1 parent 8196669 commit 9cb38b8
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,9 @@ internal class WebViewRumEventConsumerTest {
}

val expectedOffsets = LinkedHashMap<String, Long>()
val expectedOffsetsKeys = fakeViewEvents
.takeLast(WebViewRumEventConsumer.MAX_VIEW_TIME_OFFSETS_RETAIN)
.map { it.view.id }
val expectedOffsetsValues = fakeServerOffsets.takeLast(WebViewRumEventConsumer.MAX_VIEW_TIME_OFFSETS_RETAIN)
val expectedOffsetsKeys = fakeViewEvents.map { it.view.id }
expectedOffsetsKeys.forEachIndexed { index, key ->
expectedOffsets[key] = expectedOffsetsValues[index]
expectedOffsets[key] = fakeServerOffsets[index]
}
whenever(
mockWebViewRumEventMapper.mapEvent(
Expand All @@ -857,8 +854,12 @@ internal class WebViewRumEventConsumerTest {

// Then
val rumEventConsumer = testedConsumer as WebViewRumEventConsumer
// Because the threads are processed in any order,
// we can't guarantee the order of the entries, and can only assert
// the size of the offsets, and the pairs of key values in it
assertThat(rumEventConsumer.offsets.entries)
.containsExactlyElementsOf(expectedOffsets.entries)
.containsAnyElementsOf(expectedOffsets.entries)
.hasSizeLessThanOrEqualTo(WebViewRumEventConsumer.MAX_VIEW_TIME_OFFSETS_RETAIN)
}

// endregion
Expand Down

0 comments on commit 9cb38b8

Please sign in to comment.