diff --git a/Tests/AnalyticsTests/ComScore/ComScorePageViewTests.swift b/Tests/AnalyticsTests/ComScore/ComScorePageViewTests.swift index 4e8e80daf..098a03ff9 100644 --- a/Tests/AnalyticsTests/ComScore/ComScorePageViewTests.swift +++ b/Tests/AnalyticsTests/ComScore/ComScorePageViewTests.swift @@ -123,14 +123,14 @@ final class ComScorePageViewTests: ComScoreTestCase { func testAutomaticTrackingWithoutProtocolImplementation() { let viewController = UIViewController() - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { viewController.simulateViewAppearance() } } func testManualTrackingWithoutProtocolImplementation() { let viewController = UIViewController() - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { viewController.trackPageView() } } @@ -179,7 +179,7 @@ final class ComScorePageViewTests: ComScoreTestCase { let viewController2 = AutomaticMockViewController(title: "title2") let tabBarController = UITabBarController() tabBarController.viewControllers = [viewController1, viewController2] - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { viewController2.simulateViewAppearance() } } @@ -209,14 +209,14 @@ final class ComScorePageViewTests: ComScoreTestCase { UINavigationController(rootViewController: viewController1), UINavigationController(rootViewController: viewController2) ] - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { viewController2.simulateViewAppearance() } } func testManualTracking() { let viewController = ManualMockViewController() - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { viewController.simulateViewAppearance() } expectAtLeastHits( diff --git a/Tests/AnalyticsTests/ComScore/ComScoreTrackerMetadataTests.swift b/Tests/AnalyticsTests/ComScore/ComScoreTrackerMetadataTests.swift index 92e43ce9d..7ce8ab347 100644 --- a/Tests/AnalyticsTests/ComScore/ComScoreTrackerMetadataTests.swift +++ b/Tests/AnalyticsTests/ComScore/ComScoreTrackerMetadataTests.swift @@ -40,7 +40,7 @@ final class ComScoreTrackerMetadataTests: ComScoreTestCase { ] )) - expectNoHits(during: .seconds(3)) { + expectNoHits(during: .milliseconds(500)) { player.play() } } @@ -53,7 +53,7 @@ final class ComScoreTrackerMetadataTests: ComScoreTestCase { ] )) - expectNoHits(during: .seconds(3)) { + expectNoHits(during: .milliseconds(500)) { player.play() } } diff --git a/Tests/AnalyticsTests/ComScore/ComScoreTrackerRateTests.swift b/Tests/AnalyticsTests/ComScore/ComScoreTrackerRateTests.swift index fb88e1bef..475f4469b 100644 --- a/Tests/AnalyticsTests/ComScore/ComScoreTrackerRateTests.swift +++ b/Tests/AnalyticsTests/ComScore/ComScoreTrackerRateTests.swift @@ -58,7 +58,7 @@ final class ComScoreTrackerRateTests: ComScoreTestCase { player.play() expect(player.playbackState).toEventually(equal(.playing)) - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.setDesiredPlaybackSpeed(1) } } diff --git a/Tests/AnalyticsTests/ComScore/ComScoreTrackerSeekTests.swift b/Tests/AnalyticsTests/ComScore/ComScoreTrackerSeekTests.swift index e7e3d9631..4f6fca4ab 100644 --- a/Tests/AnalyticsTests/ComScore/ComScoreTrackerSeekTests.swift +++ b/Tests/AnalyticsTests/ComScore/ComScoreTrackerSeekTests.swift @@ -45,7 +45,7 @@ final class ComScoreTrackerSeekTests: ComScoreTestCase { expect(player.playbackState).toEventually(equal(.paused)) - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.seek(at(.init(value: 7, timescale: 1))) } diff --git a/Tests/AnalyticsTests/ComScore/ComScoreTrackerTests.swift b/Tests/AnalyticsTests/ComScore/ComScoreTrackerTests.swift index a90827608..4e48660a2 100644 --- a/Tests/AnalyticsTests/ComScore/ComScoreTrackerTests.swift +++ b/Tests/AnalyticsTests/ComScore/ComScoreTrackerTests.swift @@ -61,7 +61,7 @@ final class ComScoreTrackerTests: ComScoreTestCase { ComScoreTracker.adapter { _ in .test } ] )) - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.pause() } } @@ -132,7 +132,7 @@ final class ComScoreTrackerTests: ComScoreTestCase { ComScoreTracker.adapter { _ in .test } ] )) - expectNoHits(during: .seconds(3)) { + expectNoHits(during: .milliseconds(500)) { player.play() } } @@ -163,7 +163,7 @@ final class ComScoreTrackerTests: ComScoreTestCase { player.isTrackingEnabled = false - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.play() } diff --git a/Tests/AnalyticsTests/CommandersAct/CommandersActHeartbeatTests.swift b/Tests/AnalyticsTests/CommandersAct/CommandersActHeartbeatTests.swift index 497cc2f85..991e49d2a 100644 --- a/Tests/AnalyticsTests/CommandersAct/CommandersActHeartbeatTests.swift +++ b/Tests/AnalyticsTests/CommandersAct/CommandersActHeartbeatTests.swift @@ -34,7 +34,7 @@ final class CommandersActHeartbeatTests: CommandersActTestCase { func testNoHeartbeatInitially() { _ = Self.player(from: .onDemand, into: &cancellables) - expectNoHits(during: .milliseconds(300)) + expectNoHits(during: .milliseconds(500)) } func testOnDemandHeartbeatAfterPlay() { @@ -63,7 +63,7 @@ final class CommandersActHeartbeatTests: CommandersActTestCase { expectAtLeastHits(pos()) { player.play() } - expectNoHits(during: .milliseconds(300)) { + expectNoHits(during: .milliseconds(500)) { player.pause() } } diff --git a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerDvrPropertiesTests.swift b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerDvrPropertiesTests.swift index 529456ec0..18e5b3723 100644 --- a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerDvrPropertiesTests.swift +++ b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerDvrPropertiesTests.swift @@ -94,16 +94,12 @@ final class CommandersActTrackerDvrPropertiesTests: CommandersActTestCase { CommandersActTracker.adapter { _ in .test } ] )) - - player?.play() - expect(player?.playbackState).toEventually(equal(.playing)) - - player?.pause() - wait(for: .seconds(2)) - + expectAtLeastHits(play()) { + player?.play() + } expectAtLeastHits( stop { labels in - expect(labels.media_position).to(equal(0)) + expect(labels.media_position).notTo(beNil()) } ) { player = nil @@ -119,7 +115,7 @@ final class CommandersActTrackerDvrPropertiesTests: CommandersActTestCase { )) expect(player?.playbackState).toEventually(equal(.paused)) - expectNoHits(during: .seconds(5)) { + expectNoHits(during: .milliseconds(500)) { player = nil } } diff --git a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerSeekTests.swift b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerSeekTests.swift index 599d8aa63..9830545ff 100644 --- a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerSeekTests.swift +++ b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerSeekTests.swift @@ -44,7 +44,7 @@ final class CommandersActTrackerSeekTests: CommandersActTestCase { expect(player.playbackState).toEventually(equal(.paused)) - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.seek(at(.init(value: 7, timescale: 1))) } diff --git a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerTests.swift b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerTests.swift index b5e47067f..b883c9566 100644 --- a/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerTests.swift +++ b/Tests/AnalyticsTests/CommandersAct/CommandersActTrackerTests.swift @@ -34,7 +34,7 @@ final class CommandersActTrackerTests: CommandersActTestCase { CommandersActTracker.adapter { _ in [:] } ] )) - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.pause() } } @@ -129,7 +129,7 @@ final class CommandersActTrackerTests: CommandersActTestCase { player?.play() } - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player = nil } } @@ -141,7 +141,7 @@ final class CommandersActTrackerTests: CommandersActTestCase { CommandersActTracker.adapter { _ in [:] } ] )) - expectNoHits(during: .seconds(3)) { + expectNoHits(during: .milliseconds(500)) { player.play() } } @@ -172,7 +172,7 @@ final class CommandersActTrackerTests: CommandersActTestCase { player.isTrackingEnabled = false - expectNoHits(during: .seconds(2)) { + expectNoHits(during: .milliseconds(500)) { player.play() } diff --git a/Tests/CoreTests/DispatchPublisherTests.swift b/Tests/CoreTests/DispatchPublisherTests.swift index 0cfd45a69..f5a61afa8 100644 --- a/Tests/CoreTests/DispatchPublisherTests.swift +++ b/Tests/CoreTests/DispatchPublisherTests.swift @@ -81,13 +81,13 @@ final class DispatchPublisherTests: XCTestCase { let delayedPublisher = [1, 2, 3].publisher .delayIfNeeded(for: 0.1, scheduler: DispatchQueue.main) let subject = CurrentValueSubject(0) - expectEqualPublished(values: [0, 1, 2, 3], from: Publishers.Merge(delayedPublisher, subject), during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [0, 1, 2, 3], from: Publishers.Merge(delayedPublisher, subject)) } func testDelayIfNeededOutputOrderingWithZeroDelay() { let delayedPublisher = [1, 2, 3].publisher .delayIfNeeded(for: 0, scheduler: DispatchQueue.main) let subject = CurrentValueSubject(0) - expectEqualPublished(values: [1, 2, 3, 0], from: Publishers.Merge(delayedPublisher, subject), during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [1, 2, 3, 0], from: Publishers.Merge(delayedPublisher, subject)) } } diff --git a/Tests/CoreTests/MeasurePublisherTests.swift b/Tests/CoreTests/MeasurePublisherTests.swift index 505ff21ff..d47b317b3 100644 --- a/Tests/CoreTests/MeasurePublisherTests.swift +++ b/Tests/CoreTests/MeasurePublisherTests.swift @@ -16,7 +16,7 @@ final class MeasurePublisherTests: XCTestCase { .delay(for: .milliseconds(500), scheduler: DispatchQueue.main) .measureDateInterval() .map(\.duration) - expectPublished(values: [0.5], from: publisher, to: beClose(within: 0.1), during: .seconds(1)) + expectAtLeastPublished(values: [0.5], from: publisher, to: beClose(within: 0.1)) } func testWithMultipleEvents() { @@ -24,7 +24,7 @@ final class MeasurePublisherTests: XCTestCase { .delay(for: .milliseconds(500), scheduler: DispatchQueue.main) .measureDateInterval() .map(\.duration) - expectPublished(values: [0.5, 0], from: publisher, to: beClose(within: 0.1), during: .seconds(1)) + expectAtLeastPublished(values: [0.5, 0], from: publisher, to: beClose(within: 0.1)) } func testWithoutEvents() { diff --git a/Tests/CoreTests/ReplaySubjectTests.swift b/Tests/CoreTests/ReplaySubjectTests.swift index 6395e55c7..72882fb4b 100644 --- a/Tests/CoreTests/ReplaySubjectTests.swift +++ b/Tests/CoreTests/ReplaySubjectTests.swift @@ -33,13 +33,13 @@ final class ReplaySubjectTests: XCTestCase { subject.send(1) subject.send(2) subject.send(3) - expectEqualPublished(values: [2, 3], from: subject, during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [2, 3], from: subject) } func testNewValuesWithBufferOfZero() { let subject = ReplaySubject(bufferSize: 0) subject.send(1) - expectEqualPublished(values: [2, 3], from: subject, during: .milliseconds(100)) { + expectAtLeastEqualPublished(values: [2, 3], from: subject) { subject.send(2) subject.send(3) } @@ -50,7 +50,7 @@ final class ReplaySubjectTests: XCTestCase { subject.send(1) subject.send(2) subject.send(3) - expectEqualPublished(values: [2, 3, 4, 5], from: subject, during: .milliseconds(100)) { + expectAtLeastEqualPublished(values: [2, 3, 4, 5], from: subject) { subject.send(4) subject.send(5) } @@ -61,8 +61,8 @@ final class ReplaySubjectTests: XCTestCase { subject.send(1) subject.send(2) subject.send(3) - expectEqualPublished(values: [2, 3], from: subject, during: .milliseconds(100)) - expectEqualPublished(values: [2, 3], from: subject, during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [2, 3], from: subject) + expectAtLeastEqualPublished(values: [2, 3], from: subject) } func testSubscriptionRelease() { @@ -79,10 +79,10 @@ final class ReplaySubjectTests: XCTestCase { subject.send(1) subject.send(2) subject.send(3) - expectEqualPublished(values: [2, 3, 4], from: subject, during: .milliseconds(100)) { + expectAtLeastEqualPublished(values: [2, 3, 4], from: subject) { subject.send(4) } - expectEqualPublished(values: [3, 4], from: subject, during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [3, 4], from: subject) } func testCompletion() { @@ -98,7 +98,7 @@ final class ReplaySubjectTests: XCTestCase { subject.send(1) subject.send(completion: .finished) subject.send(2) - expectEqualPublished(values: [1], from: subject, during: .milliseconds(100)) + expectAtLeastEqualPublished(values: [1], from: subject) } func testCompletionWithMultipleSubscribers() { diff --git a/Tests/CoreTests/SlicePublisherTests.swift b/Tests/CoreTests/SlicePublisherTests.swift index b7a66fc03..e27c26078 100644 --- a/Tests/CoreTests/SlicePublisherTests.swift +++ b/Tests/CoreTests/SlicePublisherTests.swift @@ -22,6 +22,6 @@ final class SlicePublisherTests: XCTestCase { Person(firstName: "Jane", lastName: "Smith"), Person(firstName: "John", lastName: "Bridges") ].publisher.slice(at: \.firstName) - expectEqualPublished(values: ["Jane", "John"], from: publisher, during: .milliseconds(100)) + expectAtLeastEqualPublished(values: ["Jane", "John"], from: publisher) } } diff --git a/Tests/CoreTests/TriggerTests.swift b/Tests/CoreTests/TriggerTests.swift index 493f225d6..a6cc33fd0 100644 --- a/Tests/CoreTests/TriggerTests.swift +++ b/Tests/CoreTests/TriggerTests.swift @@ -40,7 +40,7 @@ final class TriggerTests: XCTestCase { func testHashableActivationIndex() { let trigger = Trigger() - expectEqualPublished(values: ["out"], from: trigger.signal(activatedBy: "index").map { _ in "out" }, during: .seconds(1)) { + expectAtLeastEqualPublished(values: ["out"], from: trigger.signal(activatedBy: "index").map { _ in "out" }) { trigger.activate(for: "index") } } diff --git a/Tests/CoreTests/WaitPublisherTests.swift b/Tests/CoreTests/WaitPublisherTests.swift index d5fe9b8b1..73370d322 100644 --- a/Tests/CoreTests/WaitPublisherTests.swift +++ b/Tests/CoreTests/WaitPublisherTests.swift @@ -18,7 +18,7 @@ final class WaitPublisherTests: XCTestCase { .wait(untilOutputFrom: signal) expectNothingPublished(from: publisher, during: .milliseconds(100)) - expectEqualPublished(values: ["Received"], from: publisher, during: .milliseconds(100)) { + expectAtLeastEqualPublished(values: ["Received"], from: publisher) { signal.send(()) } } diff --git a/Tests/PlayerTests/Asset/ResourceItemTests.swift b/Tests/PlayerTests/Asset/ResourceItemTests.swift index 78521d4c7..a9db388b1 100644 --- a/Tests/PlayerTests/Asset/ResourceItemTests.swift +++ b/Tests/PlayerTests/Asset/ResourceItemTests.swift @@ -32,10 +32,9 @@ final class ResourceItemTests: TestCase { func testFailingPlayerItem() { let item = Resource.failing(error: StructError()).playerItem(configuration: .default, limits: .none) _ = AVPlayer(playerItem: item) - expectEqualPublished( + expectAtLeastEqualPublished( values: [.unknown], - from: item.statusPublisher(), - during: .seconds(1) + from: item.statusPublisher() ) } } diff --git a/Tests/PlayerTests/Player/ErrorTests.swift b/Tests/PlayerTests/Player/ErrorTests.swift index f42096e92..fe92d602c 100644 --- a/Tests/PlayerTests/Player/ErrorTests.swift +++ b/Tests/PlayerTests/Player/ErrorTests.swift @@ -34,10 +34,9 @@ final class ErrorTests: TestCase { func testInvalidStream() { let player = Player(item: .simple(url: Stream.unavailable.url)) - expectEqualPublishedNext( + expectAtLeastEqualPublishedNext( values: [.init(rawValue: NSURLErrorFileDoesNotExist)], - from: Self.errorCodePublisher(for: player), - during: .seconds(1) + from: Self.errorCodePublisher(for: player) ) } diff --git a/Tests/PlayerTests/Player/PlaybackTests.swift b/Tests/PlayerTests/Player/PlaybackTests.swift index e1f46b289..17fac49f0 100644 --- a/Tests/PlayerTests/Player/PlaybackTests.swift +++ b/Tests/PlayerTests/Player/PlaybackTests.swift @@ -39,10 +39,9 @@ final class PlaybackTests: XCTestCase { func testUnknown() { let item = PlayerItem.simple(url: Stream.unavailable.url) let player = Player(item: item) - expectEqualPublished( + expectAtLeastEqualPublished( values: [.idle], - from: playbackStatePublisher(for: player), - during: .seconds(1) + from: playbackStatePublisher(for: player) ) } } diff --git a/Tests/PlayerTests/Player/PlayerTests.swift b/Tests/PlayerTests/Player/PlayerTests.swift index dd51a251b..8c9c411bd 100644 --- a/Tests/PlayerTests/Player/PlayerTests.swift +++ b/Tests/PlayerTests/Player/PlayerTests.swift @@ -45,10 +45,9 @@ final class PlayerTests: TestCase { func testRetrieveCurrentValueOnSubscription() { let player = Player(item: .simple(url: Stream.onDemand.url)) expect(player.properties.isBuffering).toEventually(beFalse()) - expectEqualPublished( + expectAtLeastEqualPublished( values: [false], - from: player.propertiesPublisher.slice(at: \.isBuffering), - during: .seconds(1) + from: player.propertiesPublisher.slice(at: \.isBuffering) ) } diff --git a/Tests/PlayerTests/PlayerItem/PlayerItemAssetPublisherTests.swift b/Tests/PlayerTests/PlayerItem/PlayerItemAssetPublisherTests.swift index f56e3c92e..679bab652 100644 --- a/Tests/PlayerTests/PlayerItem/PlayerItemAssetPublisherTests.swift +++ b/Tests/PlayerTests/PlayerItem/PlayerItemAssetPublisherTests.swift @@ -12,19 +12,17 @@ import PillarboxStreams final class PlayerItemAssetPublisherTests: TestCase { func testNoLoad() { let item = PlayerItem.simple(url: Stream.onDemand.url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.loading], - from: item.$content.map(\.resource), - during: .milliseconds(500) + from: item.$content.map(\.resource) ) } func testLoad() { let item = PlayerItem.simple(url: Stream.onDemand.url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.loading, .simple(url: Stream.onDemand.url)], - from: item.$content.map(\.resource), - during: .milliseconds(500) + from: item.$content.map(\.resource) ) { PlayerItem.load(for: item.id) } @@ -32,18 +30,16 @@ final class PlayerItemAssetPublisherTests: TestCase { func testReload() { let item = PlayerItem.simple(url: Stream.onDemand.url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.loading, .simple(url: Stream.onDemand.url)], - from: item.$content.map(\.resource), - during: .milliseconds(500) + from: item.$content.map(\.resource) ) { PlayerItem.load(for: item.id) } - expectSimilarPublishedNext( + expectAtLeastSimilarPublished( values: [.simple(url: Stream.onDemand.url)], - from: item.$content.map(\.resource), - during: .milliseconds(500) + from: item.$content.map(\.resource) ) { PlayerItem.reload(for: item.id) } diff --git a/Tests/PlayerTests/Playlist/CurrentItemTests.swift b/Tests/PlayerTests/Playlist/CurrentItemTests.swift index 72079426a..0d1614742 100644 --- a/Tests/PlayerTests/Playlist/CurrentItemTests.swift +++ b/Tests/PlayerTests/Playlist/CurrentItemTests.swift @@ -28,10 +28,9 @@ final class CurrentItemTests: TestCase { let item1 = PlayerItem.simple(url: Stream.unavailable.url) let item2 = PlayerItem.simple(url: Stream.shortOnDemand.url) let player = Player(items: [item1, item2]) - expectEqualPublished( + expectAtLeastEqualPublished( values: [item1], - from: player.changePublisher(at: \.currentItem).removeDuplicates(), - during: .milliseconds(500) + from: player.changePublisher(at: \.currentItem).removeDuplicates() ) { player.play() } @@ -42,10 +41,9 @@ 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( + expectAtLeastEqualPublished( values: [item1, item2], - from: player.changePublisher(at: \.currentItem).removeDuplicates(), - during: .seconds(2) + from: player.changePublisher(at: \.currentItem).removeDuplicates() ) { player.play() } @@ -87,10 +85,9 @@ final class CurrentItemTests: TestCase { func testCurrentItemWithFailedItem() { let item = PlayerItem.simple(url: Stream.unavailable.url) let player = Player(item: item) - expectEqualPublished( + expectAtLeastEqualPublished( values: [item], - from: player.changePublisher(at: \.currentItem).removeDuplicates(), - during: .milliseconds(500) + from: player.changePublisher(at: \.currentItem).removeDuplicates() ) } @@ -126,10 +123,9 @@ final class CurrentItemTests: TestCase { let item1 = PlayerItem.simple(url: Stream.onDemand.url) let item2 = PlayerItem.simple(url: Stream.shortOnDemand.url) let player = Player(items: [item1, item2]) - expectEqualPublished( + expectAtLeastEqualPublished( values: [item1, item2], - from: player.changePublisher(at: \.currentItem).removeDuplicates(), - during: .milliseconds(500) + from: player.changePublisher(at: \.currentItem).removeDuplicates() ) { player.currentItem = item2 } diff --git a/Tests/PlayerTests/ProgressTracker/ProgressTrackerProgressTests.swift b/Tests/PlayerTests/ProgressTracker/ProgressTrackerProgressTests.swift index 559fb6f65..929406db7 100644 --- a/Tests/PlayerTests/ProgressTracker/ProgressTrackerProgressTests.swift +++ b/Tests/PlayerTests/ProgressTracker/ProgressTrackerProgressTests.swift @@ -50,12 +50,11 @@ 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( + 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) + to: beClose(within: 0.1) ) { progressTracker.player = player player.play() diff --git a/Tests/PlayerTests/ProgressTracker/ProgressTrackerTimeTests.swift b/Tests/PlayerTests/ProgressTracker/ProgressTrackerTimeTests.swift index 0752bafed..d7fb7960a 100644 --- a/Tests/PlayerTests/ProgressTracker/ProgressTrackerTimeTests.swift +++ b/Tests/PlayerTests/ProgressTracker/ProgressTrackerTimeTests.swift @@ -50,7 +50,7 @@ final class ProgressTrackerTimeTests: TestCase { let progressTracker = ProgressTracker(interval: CMTime(value: 1, timescale: 4)) let item = PlayerItem.simple(url: Stream.shortOnDemand.url) let player = Player(item: item) - expectPublished( + expectAtLeastPublished( values: [ .invalid, .zero, @@ -62,8 +62,7 @@ final class ProgressTrackerTimeTests: TestCase { ], from: progressTracker.changePublisher(at: \.time) .removeDuplicates(), - to: beClose(within: 0.1), - during: .seconds(2) + to: beClose(within: 0.1) ) { progressTracker.player = player player.play() diff --git a/Tests/PlayerTests/Publishers/MetadataPublisherTests.swift b/Tests/PlayerTests/Publishers/MetadataPublisherTests.swift index ceee52046..60259c86b 100644 --- a/Tests/PlayerTests/Publishers/MetadataPublisherTests.swift +++ b/Tests/PlayerTests/Publishers/MetadataPublisherTests.swift @@ -17,19 +17,17 @@ final class MetadataPublisherTests: TestCase { func testEmpty() { let player = Player() - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(100) + from: Self.titlePublisherTest(for: player) ) } func testImmediatelyAvailableWithoutMetadata() { let player = Player(item: .simple(url: Stream.onDemand.url)) - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(100) + from: Self.titlePublisherTest(for: player) ) } @@ -37,10 +35,9 @@ final class MetadataPublisherTests: TestCase { let player = Player( item: .mock(url: Stream.onDemand.url, loadedAfter: 0.1, withMetadata: AssetMetadataMock(title: "title")) ) - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil, "title"], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(200) + from: Self.titlePublisherTest(for: player) ) } @@ -50,19 +47,17 @@ final class MetadataPublisherTests: TestCase { loadedAfter: 0, withMetadata: AssetMetadataMock(title: "title") )) - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil, "title"], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(200) + from: Self.titlePublisherTest(for: player) ) } func testUpdate() { let player = Player(item: .mock(url: Stream.onDemand.url, withMetadataUpdateAfter: 0.1)) - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil, "title0", "title1"], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(500) + from: Self.titlePublisherTest(for: player) ) } @@ -72,10 +67,9 @@ final class MetadataPublisherTests: TestCase { values: [nil, "Title 1"], from: Self.titlePublisherTest(for: player) ) - expectEqualPublishedNext( + expectAtLeastEqualPublishedNext( values: [nil, "Title 2"], - from: Self.titlePublisherTest(for: player), - during: .milliseconds(500) + from: Self.titlePublisherTest(for: player) ) { player.items = [.webServiceMock(media: .media2)] } @@ -83,10 +77,9 @@ final class MetadataPublisherTests: TestCase { func testEntirePlayback() { let player = Player(item: .mock(url: Stream.shortOnDemand.url, loadedAfter: 0, withMetadata: AssetMetadataMock(title: "title"))) - expectEqualPublished( + expectAtLeastEqualPublished( values: [nil, "title", nil], - from: Self.titlePublisherTest(for: player), - during: .seconds(2) + from: Self.titlePublisherTest(for: player) ) { player.play() } diff --git a/Tests/PlayerTests/Publishers/NowPlayingInfoPublisherTests.swift b/Tests/PlayerTests/Publishers/NowPlayingInfoPublisherTests.swift index 0b179ae59..488674579 100644 --- a/Tests/PlayerTests/Publishers/NowPlayingInfoPublisherTests.swift +++ b/Tests/PlayerTests/Publishers/NowPlayingInfoPublisherTests.swift @@ -20,10 +20,9 @@ final class NowPlayingInfoPublisherTests: TestCase { func testInactive() { let player = Player(item: .mock(url: Stream.onDemand.url, loadedAfter: 0, withMetadata: AssetMetadataMock(title: "title"))) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [[:]], - from: Self.nowPlayingInfoPublisher(for: player), - during: .milliseconds(100) + from: Self.nowPlayingInfoPublisher(for: player) ) } @@ -36,10 +35,9 @@ final class NowPlayingInfoPublisherTests: TestCase { player.isActive = true } - expectSimilarPublishedNext( + expectAtLeastSimilarPublishedNext( values: [[:]], - from: Self.nowPlayingInfoPublisher(for: player), - during: .milliseconds(100) + from: Self.nowPlayingInfoPublisher(for: player) ) { player.isActive = false } diff --git a/Tests/PlayerTests/Publishers/PeriodicMetricsPublisherTests.swift b/Tests/PlayerTests/Publishers/PeriodicMetricsPublisherTests.swift index 9fe33272d..452971361 100644 --- a/Tests/PlayerTests/Publishers/PeriodicMetricsPublisherTests.swift +++ b/Tests/PlayerTests/Publishers/PeriodicMetricsPublisherTests.swift @@ -13,10 +13,9 @@ import PillarboxStreams final class PeriodicMetricsPublisherTests: TestCase { func testEmpty() { let player = Player() - expectEqualPublished( + expectAtLeastEqualPublished( values: [0], - from: player.periodicMetricsPublisher(forInterval: .init(value: 1, timescale: 4)).map(\.count), - during: .seconds(1) + from: player.periodicMetricsPublisher(forInterval: .init(value: 1, timescale: 4)).map(\.count) ) } @@ -44,7 +43,7 @@ final class PeriodicMetricsPublisherTests: TestCase { func testNoMetricsForLiveMp3() { let player = Player(item: .simple(url: Stream.liveMp3.url)) let publisher = player.periodicMetricsPublisher(forInterval: .init(value: 1, timescale: 4)).map(\.count) - expectEqualPublished(values: [0], from: publisher, during: .milliseconds(500)) { + expectAtLeastEqualPublished(values: [0], from: publisher) { player.play() } } @@ -63,10 +62,9 @@ final class PeriodicMetricsPublisherTests: TestCase { func testFailure() { let item = PlayerItem.failing(loadedAfter: 0.1) let player = Player(item: item) - expectEqualPublished( + expectAtLeastEqualPublished( values: [0], - from: player.periodicMetricsPublisher(forInterval: .init(value: 1, timescale: 4)).map(\.count), - during: .seconds(1) + from: player.periodicMetricsPublisher(forInterval: .init(value: 1, timescale: 4)).map(\.count) ) } } diff --git a/Tests/PlayerTests/Publishers/PlayerPublisherTests.swift b/Tests/PlayerTests/Publishers/PlayerPublisherTests.swift index 814e75c36..8252d3cfd 100644 --- a/Tests/PlayerTests/Publishers/PlayerPublisherTests.swift +++ b/Tests/PlayerTests/Publishers/PlayerPublisherTests.swift @@ -45,19 +45,17 @@ final class PlayerPublisherTests: TestCase { func testBufferingEmpty() { let player = Player() - expectEqualPublished( + expectAtLeastEqualPublished( values: [false], - from: Self.bufferingPublisher(for: player), - during: .milliseconds(500) + from: Self.bufferingPublisher(for: player) ) } func testBuffering() { let player = Player(item: .simple(url: Stream.onDemand.url)) - expectEqualPublished( + expectAtLeastEqualPublished( values: [true, false], - from: Self.bufferingPublisher(for: player), - during: .seconds(1) + from: Self.bufferingPublisher(for: player) ) } diff --git a/Tests/PlayerTests/Tools/PlayerItemTrackerMock.swift b/Tests/PlayerTests/Tools/PlayerItemTrackerMock.swift index ea5461ac2..93ca3e45d 100644 --- a/Tests/PlayerTests/Tools/PlayerItemTrackerMock.swift +++ b/Tests/PlayerTests/Tools/PlayerItemTrackerMock.swift @@ -46,6 +46,7 @@ final class PlayerItemTrackerMock: PlayerItemTracker { func updateProperties(to properties: PlayerProperties) {} func updateMetricEvents(to events: [MetricEvent]) { + guard !events.isEmpty else { return } configuration.statePublisher.send(.metricEvents) } diff --git a/Tests/PlayerTests/Tracking/PlayerItemTrackerLifeCycleTests.swift b/Tests/PlayerTests/Tracking/PlayerItemTrackerLifeCycleTests.swift index 1a3939b0f..2c9b92e9b 100644 --- a/Tests/PlayerTests/Tracking/PlayerItemTrackerLifeCycleTests.swift +++ b/Tests/PlayerTests/Tracking/PlayerItemTrackerLifeCycleTests.swift @@ -23,7 +23,7 @@ final class PlayerItemTrackerLifeCycleTests: TestCase { func testItemPlayback() { let player = Player() let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher, during: .seconds(2)) { + expectAtLeastEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher) { player.append(.simple( url: Stream.onDemand.url, trackerAdapters: [PlayerItemTrackerMock.adapter(statePublisher: publisher)] @@ -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)] diff --git a/Tests/PlayerTests/Tracking/PlayerItemTrackerMetricPublisherTests.swift b/Tests/PlayerTests/Tracking/PlayerItemTrackerMetricPublisherTests.swift index 6d9895faa..f2c120296 100644 --- a/Tests/PlayerTests/Tracking/PlayerItemTrackerMetricPublisherTests.swift +++ b/Tests/PlayerTests/Tracking/PlayerItemTrackerMetricPublisherTests.swift @@ -12,7 +12,7 @@ import PillarboxStreams final class PlayerItemTrackerMetricPublisherTests: TestCase { func testEmptyPlayer() { let player = Player() - expectSimilarPublished(values: [[]], from: player.metricEventsPublisher, during: .milliseconds(500)) + expectAtLeastSimilarPublished(values: [[]], from: player.metricEventsPublisher) } func testItemPlayback() { @@ -38,15 +38,14 @@ final class PlayerItemTrackerMetricPublisherTests: TestCase { func testPlaylist() { let player = Player(items: [.simple(url: Stream.shortOnDemand.url), .simple(url: Stream.mediumOnDemand.url)]) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [ [], [.anyMetadata], [.anyMetadata, .anyAsset], [.anyMetadata, .anyAsset] ], - from: player.metricEventsPublisher, - during: .seconds(2) + from: player.metricEventsPublisher ) { player.play() } diff --git a/Tests/PlayerTests/Tracking/PlayerTrackingTests.swift b/Tests/PlayerTests/Tracking/PlayerTrackingTests.swift index cb0367113..f53fe2f1d 100644 --- a/Tests/PlayerTests/Tracking/PlayerTrackingTests.swift +++ b/Tests/PlayerTests/Tracking/PlayerTrackingTests.swift @@ -15,7 +15,7 @@ final class PlayerTrackingTests: TestCase { player.isTrackingEnabled = false let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized], from: publisher, during: .milliseconds(500)) { + expectAtLeastEqualPublished(values: [.initialized], from: publisher) { player.append( .simple( url: Stream.shortOnDemand.url, @@ -34,7 +34,7 @@ final class PlayerTrackingTests: TestCase { let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized], from: publisher, during: .seconds(1)) { + expectAtLeastEqualPublished(values: [.initialized], from: publisher) { player.append( .simple( url: Stream.shortOnDemand.url, @@ -46,7 +46,7 @@ final class PlayerTrackingTests: TestCase { } expectAtLeastEqualPublished( - values: [.enabled, .metricEvents, .disabled], + values: [.enabled, .metricEvents, .metricEvents, .disabled], from: publisher ) { player.isTrackingEnabled = true @@ -60,7 +60,7 @@ final class PlayerTrackingTests: TestCase { let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher, during: .seconds(1)) { + expectAtLeastEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher) { player.append( .simple( url: Stream.shortOnDemand.url, @@ -86,7 +86,7 @@ final class PlayerTrackingTests: TestCase { let player = Player(item: .simple(url: Stream.shortOnDemand.url, trackerAdapters: [PlayerItemTrackerMock.adapter(statePublisher: publisher)])) player.isTrackingEnabled = true - expectEqualPublished(values: [.metricEvents, .metricEvents], from: publisher, during: .seconds(1)) { + expectAtLeastEqualPublished(values: [.metricEvents, .metricEvents], from: publisher) { player.isTrackingEnabled = true } } @@ -97,7 +97,7 @@ final class PlayerTrackingTests: TestCase { let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher, during: .seconds(1)) { + expectAtLeastEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher) { player.append( .simple( url: Stream.shortOnDemand.url, @@ -115,7 +115,7 @@ final class PlayerTrackingTests: TestCase { let publisher = PlayerItemTrackerMock.StatePublisher() - expectEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher, during: .seconds(1)) { + expectAtLeastEqualPublished(values: [.initialized, .enabled, .metricEvents, .metricEvents], from: publisher) { player.append( .simple( url: Stream.onDemand.url, diff --git a/Tests/PlayerTests/Types/ImageSourceTests.swift b/Tests/PlayerTests/Types/ImageSourceTests.swift index df8b4c396..772408428 100644 --- a/Tests/PlayerTests/Types/ImageSourceTests.swift +++ b/Tests/PlayerTests/Types/ImageSourceTests.swift @@ -11,29 +11,26 @@ import UIKit final class ImageSourceTests: TestCase { func testNone() { - expectEqualPublished( + expectAtLeastEqualPublished( values: [.none], - from: ImageSource.none.imageSourcePublisher(), - during: .milliseconds(100) + from: ImageSource.none.imageSourcePublisher() ) } func testImage() { let image = UIImage(systemName: "circle")! - expectEqualPublished( + expectAtLeastEqualPublished( values: [.image(image)], - from: ImageSource.image(image).imageSourcePublisher(), - during: .milliseconds(100) + from: ImageSource.image(image).imageSourcePublisher() ) } func testNonLoadedImageForValidUrl() { let url = Bundle.module.url(forResource: "pixel", withExtension: "jpg")! let source = ImageSource.url(standardResolution: url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.url(standardResolution: url)], - from: source.imageSourcePublisher(), - during: .milliseconds(100) + from: source.imageSourcePublisher() ) } @@ -41,10 +38,9 @@ final class ImageSourceTests: TestCase { let url = Bundle.module.url(forResource: "pixel", withExtension: "jpg")! let image = UIImage(contentsOfFile: url.path())! let source = ImageSource.url(standardResolution: url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.url(standardResolution: url), .image(image)], - from: source.imageSourcePublisher(), - during: .milliseconds(100) + from: source.imageSourcePublisher() ) { _ = source.image } @@ -53,10 +49,9 @@ final class ImageSourceTests: TestCase { func testInvalidImageFormat() { let url = Bundle.module.url(forResource: "invalid", withExtension: "jpg")! let source = ImageSource.url(standardResolution: url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.url(standardResolution: url), .none], - from: source.imageSourcePublisher(), - during: .milliseconds(100) + from: source.imageSourcePublisher() ) { _ = source.image } @@ -65,10 +60,9 @@ final class ImageSourceTests: TestCase { func testFailingUrl() { let url = URL(string: "https://localhost:8123/missing.jpg")! let source = ImageSource.url(standardResolution: url) - expectSimilarPublished( + expectAtLeastSimilarPublished( values: [.url(standardResolution: url), .none], - from: source.imageSourcePublisher(), - during: .seconds(1) + from: source.imageSourcePublisher() ) { _ = source.image }