Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Fix tests #84

Merged
merged 10 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading