Skip to content

Commit

Permalink
Fix ComScoreTrackerIntegrationTest flakiness (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Sep 17, 2024
1 parent 25e4a45 commit cb40f5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ComScoreTracker internal constructor(
* @param window
*/
private fun notifyPosition(position: Long, window: Window) {
if (!window.isLive()) {
if (!window.isLive) {
DebugLogger.debug(TAG, "notifyPosition $position")
streamingAnalytics.startFromPosition(position)
} else {
Expand Down Expand Up @@ -186,7 +186,7 @@ class ComScoreTracker internal constructor(
override fun onTimelineChanged(eventTime: AnalyticsListener.EventTime, reason: Int) {
if (reason == Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) {
eventTime.timeline.getWindow(eventTime.windowIndex, window)
if (window.isLive()) {
if (window.isLive) {
notifyLiveInformation(eventTime.eventPlaybackPositionMs, window)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifyEndEvent()
verifyPlayerInformation()
Expand Down Expand Up @@ -175,14 +175,14 @@ class ComScoreTrackerIntegrationTest {
InstrumentationRegistry.getInstrumentation().waitForIdleSync()

// Verify that the proper events are sent
verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifyPauseEvent()
}
Expand Down Expand Up @@ -216,14 +216,14 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
}
confirmVerified(streamingAnalytics)
Expand All @@ -238,6 +238,7 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
Expand All @@ -246,7 +247,6 @@ class ComScoreTrackerIntegrationTest {
verifyBufferStartEvent()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
}
confirmVerified(streamingAnalytics)
Expand All @@ -263,14 +263,14 @@ class ComScoreTrackerIntegrationTest {
clock.advanceTime(5.minutes.inWholeMilliseconds)
player.setPlaybackSpeed(2f)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
}
confirmVerified(streamingAnalytics)
Expand All @@ -289,14 +289,14 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifyPauseEvent()
}
Expand All @@ -321,17 +321,16 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifyPauseEvent()
verifyLiveInformation()
verifyPlayEvent()
}
confirmVerified(streamingAnalytics)
Expand All @@ -350,14 +349,14 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_IDLE)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifyEndEvent()
}
Expand All @@ -376,20 +375,18 @@ class ComScoreTrackerIntegrationTest {

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

verifyLiveInformation()
verifyOrder {
verifyPlayerInformation()
verifyCreatePlaybackSession()
verifyMetadata()
verifyPlaybackRate(playbackRate = 1f)
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
verifySeekStart()
verifyLiveInformation()
verifyBufferStartEvent()
verifyBufferStopEvent()
verifyLiveInformation()
verifyPlayEvent()
}
confirmVerified(streamingAnalytics)
Expand Down Expand Up @@ -722,12 +719,11 @@ class ComScoreTrackerIntegrationTest {
streamingAnalytics.notifySeekStart()
}

private fun MockKVerificationScope.verifyLiveInformation(
dvrWindowLength: Long = any(),
dvrWindowOffset: Long = any(),
) {
streamingAnalytics.setDvrWindowLength(dvrWindowLength)
streamingAnalytics.startFromDvrWindowOffset(dvrWindowOffset)
private fun verifyLiveInformation() {
verify {
streamingAnalytics.setDvrWindowLength(any())
streamingAnalytics.startFromDvrWindowOffset(any())
}
}
// endregion

Expand Down

0 comments on commit cb40f5d

Please sign in to comment.