Skip to content

Update the observerFail audio test for the engine observer rollback contract - #1240

Draft
hiroshihorie wants to merge 2 commits into
mainfrom
hiroshi/clt-3680-observerfail-teardown-contract
Draft

hiroshihorie wants to merge 2 commits into
mainfrom
hiroshi/clt-3680-observerfail-teardown-contract

Conversation

@hiroshihorie

Copy link
Copy Markdown
Member

Why

LiveKitWebRTC 150.7871.08 (livekit/libwebrtc#312) changed what happens when an AudioEngineObserver hook returns an error:

  • Setup hooks (will-enable, will-start) still fail the operation. The audio device module rolls it back and the SDK throws. If will-enable succeeded and a later step fails, the observer gets a did-disable with the state from before the operation. A will-release follows for an engine the operation created.
  • Teardown hooks (did-stop, did-disable, will-release) run after the engine has already stopped. A failure there is only logged and the operation completes.

observerFail still expected stopLocalRecording() to throw when did-stop failed. That is no longer the contract, so the test was out of date. It does not run in CI, so nothing caught it.

What the test asserts now

TestEngineObserver records every call (hook and reported state) and can be told which hooks fail. In device rendering mode:

  • With did-stop, did-disable and will-release failing, stopLocalRecording() does not throw, the engine is stopped and not recording, and the hooks ran as did-stop, did-disable, will-release, with did-disable reporting playout and recording off.
  • Stopping again calls no hook.
  • With will-enable failing, the start throws and is rolled back. The observer sees will-enable, then will-release, and no did-disable.
  • With will-start failing, the start throws and is rolled back. The observer sees will-enable, will-start, then a did-disable with the state from before the start (playout and recording off), then will-release.
  • A clean start and stop then succeed.

In manual rendering mode:

  • With will-enable failing, the start throws, nothing is recording and no did-disable follows.
  • A clean start succeeds. With did-stop and did-disable failing, the stop does not throw and recording stops.

The test first requires a clean engine (not running, not in manual or always-prepared mode, nothing initialized), because the expected hook states depend on it. A defer restores the observers, rendering mode, voice processing policy and (on iOS) the session category, even if an expectation fails partway through.

How it was tested

  • macOS (Xcode 27.2), against LiveKitWebRTC 150.7871.08: LiveKitAudioTests/AudioEngineObserverTests with microphone access. 1 test in 1 suite, passed. It was run with xcrun xctest on the built test bundle, launched from Terminal. Under xcodebuild test-without-building the test process did not get microphone access and stopped at the first startLocalRecording() with "Microphone permission is not granted", before any contract assertion.
  • As a check that the assertions can fail, one expected hook sequence was changed on purpose. The run then failed on that line. The change was reverted.
  • iOS Simulator (iPhone 18 Pro): build-for-testing only, it compiles. Not run.
  • SwiftFormat 0.64.7 --lint . and SwiftLint 0.65.1 lint --strict: clean.

Not run: no physical iOS device, no simulator run, no other LiveKitAudioTests suites. CI does not run LiveKitAudioTests today (the LiveKitCI scheme covers the Core, Nanopb and ObjC test targets), so CI only checks that this compiles.

Test only, so no .changes entry.

LiveKitWebRTC 150.7871.08 made teardown hooks log-only. A failing
did-stop, did-disable or will-release no longer fails the operation,
so observerFail could no longer expect stopLocalRecording() to throw.

The test now records every observer call and checks both sides of the
contract in device and manual rendering modes. A failing teardown hook
lets the stop succeed after every hook ran. A failing will-enable or
will-start fails the start, rolls it back, and compensates the observer
with did-disable and will-release as documented. The test also restores
the shared AudioManager state it changes.
@github-actions

Copy link
Copy Markdown

⚠️ This PR does not contain any files in the .changes directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant