SRGSSR / pillarbox-apple

A next-generation reactive media playback ecosystem for Apple platforms.
https://testflight.apple.com/join/TS6ngLqf
MIT License
45 stars 6 forks source link

Update Nimble for async / await test support #122

Closed defagos closed 1 year ago

defagos commented 1 year ago

As a developer I need an easy way to test async / await code as well.

Acceptance criteria

Tasks

defagos commented 1 year ago

An example in which the content is played:

@MainActor
func testMethod2() async {
    let item = PlayerItem(url: URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8")!)
    let player = Player(item: item)
    player.play()
    try? await Task.sleep(for: .seconds(5))
}

and an example in which content playback never starts:

@MainActor
func testMethod1() async {
    let item = PlayerItem(url: URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8")!)
    let player = Player(item: item)
    player.play()
    expect(player.playbackState).toEventually(equal(.paused))
}

Difference is the use of toEventually which does not behave properly in async test methods apparently.

defagos commented 1 year ago

There is already an issue raised.

defagos commented 1 year ago

Nimble 11.1.0 is available.

defagos commented 1 year ago

On tvOS executing testMoveFromInvalidIndex leads to the following Nimble warning logged to the console:

[Nimble Warning]: If you're getting stuck on a debugger breakpoint for a fatal error while using throwAssertion(), please disable 'Debug Executable' in your scheme. Go to 'Edit Scheme > Test > Info' and uncheck 'Debug Executable'. If you've already done that, suppress this warning by setting `NimbleEnvironment.activeInstance.suppressTVOSAssertionWarning = true`. This is required because the standard methods of catching assertions (mach APIs) are unavailable for tvOS. Instead, the same mechanism the debugger uses is the fallback method for tvOS.

Disabling Debug Executable is not so practical for everyday use. But maybe there is a better approach.

Note that running tests with make test-tvos works fine so this is really a development QoL issue. Maybe using test plans could help but I am not sure they are intended to customize test behavior per platform.

defagos commented 1 year ago

I doubt we can disable Nimble warning since the value we set is saved in thread local storage, but we cannot do it on background threads we don't spawn ourselves and which Nimble will check this setting on.