Skip to content

Commit

Permalink
Improve test flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
waliid committed Dec 9, 2024
1 parent 701997c commit a9de7dc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 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,21 @@ 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 delta: Float = 0.1
let publisher = progressTracker.changePublisher(at: \.progress)
.removeDuplicates { previous, current in
abs(previous - current) < delta
}
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: delta)
) {
progressTracker.player = player
player.play()
}

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

func testPausedDvrStream() {
Expand Down
8 changes: 5 additions & 3 deletions Tests/PlayerTests/Publishers/MetadataPublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ final class MetadataPublisherTests: TestCase {

func testEntirePlayback() {
let player = Player(item: .mock(url: Stream.shortOnDemand.url, loadedAfter: 0, withMetadata: AssetMetadataMock(title: "title")))
expectEqualPublished(
let publisher = Self.titlePublisherTest(for: player)
expectAtLeastEqualPublished(
values: [nil, "title", nil],
from: Self.titlePublisherTest(for: player),
during: .seconds(2)
from: publisher
) {
player.play()
}

expectNothingPublishedNext(from: publisher, during: .seconds(1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class PlayerItemTrackerLifeCycleTests: TestCase {
func testFailedItem() {
let player = Player()
let publisher = PlayerItemTrackerMock.StatePublisher()
expectEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher, during: .milliseconds(500)) {
expectAtLeastEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher) {
player.append(.simple(
url: Stream.unavailable.url,
trackerAdapters: [PlayerItemTrackerMock.adapter(statePublisher: publisher)]
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 a9de7dc

Please sign in to comment.