Skip to content

Commit

Permalink
chore(tests): Fix tests (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz authored Apr 11, 2024
1 parent a574f94 commit 4543c58
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 224 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-tests-ios:
unit-tests:
runs-on: blaze/macos-14
strategy:
matrix:
# also run for macos
destination: ["platform=iOS Simulator,name=iPhone 15 Pro"]
target: [macos, iOS]
include:
- target: iOS
destination: '-destination "platform=iOS Simulator,name=iPhone 15 Pro"'
- target: macos
destination: '-destination "platform=macOS,name=Any Mac"'
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Run Tests
run: |-
xcodebuild test -scheme SwiftAudioEx -destination "${destination}" -enableCodeCoverage YES
env:
destination: ${{ matrix.destination }}
unit-tests-macos:
runs-on: blaze/macos-14
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Run Tests
run: |-
swift test
run: xcodebuild test -scheme SwiftAudioEx ${{ matrix.destination }} -enableCodeCoverage YES
- name: Upload coverage to Codecov
if: matrix.target == 'macos'
uses: codecov/[email protected]
2 changes: 1 addition & 1 deletion Sources/SwiftAudioEx/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class AudioPlayer: AVPlayerWrapperDelegate {

try action()

if playWhenReady == true {
if playWhenReady == true, playbackError == nil {
self.playWhenReady = true
}
}
Expand Down
24 changes: 12 additions & 12 deletions Tests/SwiftAudioExTests/AVPlayerWrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: false)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperStateWhenPlayingSourceShouldBePlaying() {
Expand All @@ -52,7 +52,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: true)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperStateWhenPausingSourceShouldBePaused() {
Expand All @@ -68,7 +68,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: true)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperStateWhenTogglingFromPlayShouldBePaused() {
Expand All @@ -84,7 +84,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: true)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperStateWhenStoppingShouldBeStopped() {
Expand All @@ -100,7 +100,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: true)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperStateLoadingWithInitialTimeShouldBePlaying() {
Expand All @@ -114,7 +114,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: LongSource.url, playWhenReady: true, initialTime: 4.0)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

// MARK: - Duration tests
Expand All @@ -131,7 +131,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: false)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

// MARK: - Current time tests
Expand All @@ -152,7 +152,7 @@ class AVPlayerWrapperTests: XCTestCase {
expectation.fulfill()
}
wrapper.load(from: Source.url, playWhenReady: false)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperSeekingShouldSeekWhileNotYetLoaded() {
Expand All @@ -163,7 +163,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
wrapper.load(from: Source.url, playWhenReady: false)
wrapper.seek(to: seekTime)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperSeekByShouldSeek() {
Expand All @@ -176,7 +176,7 @@ class AVPlayerWrapperTests: XCTestCase {
expectation.fulfill()
}
wrapper.load(from: Source.url, playWhenReady: false)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperLoadingSourceWithInitialTimeShouldSeek() {
Expand All @@ -185,7 +185,7 @@ class AVPlayerWrapperTests: XCTestCase {
expectation.fulfill()
}
wrapper.load(from: LongSource.url, playWhenReady: false, initialTime: 4.0)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

// MARK: - Rate tests
Expand All @@ -202,7 +202,7 @@ class AVPlayerWrapperTests: XCTestCase {
}
}
wrapper.load(from: Source.url, playWhenReady: true)
wait(for: [expectation], timeout: 20.0)
wait(for: [expectation], timeout: defaultTimeout)
}

func testAVPlayerWrapperTimeObserverWhenUpdatedShouldUpdateTheObserversPeriodicObserverTimeInterval() {
Expand Down
8 changes: 4 additions & 4 deletions Tests/SwiftAudioExTests/AudioPlayerEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AudioPlayerEventTests: XCTestCase {
func testEventAddListener() {
let listener = EventListener()
event.addListener(listener, listener.handleEvent)
waitTrue(self.event.invokers.count > 0, timeout: 5)
waitTrue(self.event.invokers.count > 0, timeout: defaultTimeout)
}

func testEventRemoveListener() {
Expand All @@ -32,7 +32,7 @@ class AudioPlayerEventTests: XCTestCase {
listener = nil
event.emit(data: ())

waitEqual(self.event.invokers.count, 0, timeout: 5)
waitEqual(self.event.invokers.count, 0, timeout: defaultTimeout)
}

func testEventAddMultipleListeners() {
Expand All @@ -44,7 +44,7 @@ class AudioPlayerEventTests: XCTestCase {
return listener
}

waitEqual(self.event.invokers.count, listeners.count, timeout: 5)
waitEqual(self.event.invokers.count, listeners.count, timeout: defaultTimeout)
}

func testEventRemoveOneListener() {
Expand All @@ -59,6 +59,6 @@ class AudioPlayerEventTests: XCTestCase {
let listenerToRemove = listeners[listeners.count / 2]
event.removeListener(listenerToRemove)

waitEqual(self.event.invokers.count, listeners.count - 1, timeout: 5)
waitEqual(self.event.invokers.count, listeners.count - 1, timeout: defaultTimeout)
}
}
Loading

0 comments on commit 4543c58

Please sign in to comment.