Skip to content

Commit

Permalink
Improve test flakyness
Browse files Browse the repository at this point in the history
  • Loading branch information
waliid committed Dec 9, 2024
1 parent 701997c commit 0d1c493
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions Tests/PlayerTests/Playlist/CurrentItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ final class CurrentItemTests: TestCase {
let item2 = PlayerItem.simple(url: Stream.unavailable.url)
let item3 = PlayerItem.simple(url: Stream.shortOnDemand.url)
let player = Player(items: [item1, item2, item3])
expectEqualPublished(
let publisher = player.changePublisher(at: \.currentItem).removeDuplicates()
expectAtLeastEqualPublished(
values: [item1, item2],
from: player.changePublisher(at: \.currentItem).removeDuplicates(),
during: .seconds(2)
from: publisher
) {
player.play()
}

expectNothingPublishedNext(from: publisher, during: .seconds(1))
}

func testCurrentItemWithLastFailedItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ final class ProgressTrackerProgressTests: TestCase {
let progressTracker = ProgressTracker(interval: CMTime(value: 1, timescale: 4))
let item = PlayerItem.simple(url: Stream.shortOnDemand.url)
let player = Player(item: item)
expectPublished(
let publisher = progressTracker.changePublisher(at: \.progress)
.removeDuplicates()
expectAtLeastPublished(
values: [0, 0.25, 0.5, 0.75, 1, 0],
from: progressTracker.changePublisher(at: \.progress)
.removeDuplicates(),
to: beClose(within: 0.1),
during: .seconds(2)
from: publisher,
to: beClose(within: 0.1)
) {
progressTracker.player = player
player.play()
}

expectNothingPublishedNext(from: publisher, during: .seconds(1))
}

func testPausedDvrStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ final class PlayerItemTrackerMetricPublisherTests: TestCase {

func testPlaylist() {
let player = Player(items: [.simple(url: Stream.shortOnDemand.url), .simple(url: Stream.mediumOnDemand.url)])
expectSimilarPublished(
let publisher = player.metricEventsPublisher
expectAtLeastSimilarPublished(
values: [
[],
[.anyMetadata],
[.anyMetadata, .anyAsset],
[.anyMetadata, .anyAsset]
],
from: player.metricEventsPublisher,
during: .seconds(2)
from: publisher
) {
player.play()
}

expectNothingPublishedNext(from: publisher, during: .seconds(1))
}
}

0 comments on commit 0d1c493

Please sign in to comment.