Model the fake voice recorder on a cancellable recording job - #7466
Open
hayaksi1 wants to merge 2 commits into
Open
Model the fake voice recorder on a cancellable recording job#7466hayaksi1 wants to merge 2 commits into
hayaksi1 wants to merge 2 commits into
Conversation
FakeVoiceRecorder pushed a whole recording synchronously from a single suspending call, which made it both weaker and stricter than DefaultVoiceRecorder. Every level emission carried the same elapsed time and the emissions were coalesced by Molecule, so no intermediate recording state was observable and the level-limit test had to skip half the emissions to compensate. Each level now advances the test time source and suspends for its share of the recording duration, so the states arrive one at a time and that magic number is gone. Call verification moved to the constructor lambdas the rest of the repo uses, in place of hand-rolled counters and assertCalls. The counters discarded the argument, so nothing pinned that cancelling a recording stops it with cancelled = true; that is now asserted. Truth is no longer needed by the fixture module. A second startRecord() no longer raises an error where production only warns and returns, and stopping or deleting terminates an in-flight emission loop the way cancelling the real recording job does, so a stale recording state can no longer arrive after the recording has finished.
Contributor
|
Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:
|
The level loop checked a single isRecording flag, which cannot tell "this recording was cancelled" from "a later recording has started". After a cancel followed by a new start, the first loop resumed, saw the flag set again, and advanced the shared test time source, so the new recording reported the elapsed time of both. Each recording now carries an id and its loop stops as soon as that id is no longer the active one.
hayaksi1
force-pushed
the
fix/4770-fake-voice-recorder
branch
from
August 17, 2026 15:03
d02a9e8 to
e8730f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Content
FakeVoiceRecorderpushed a whole recording synchronously from a single suspending call, which made it both weaker and stricter thanDefaultVoiceRecorder. It now models a cancellable recording job, the way the real recorder does.Every level emission carried the same elapsed time and the emissions were coalesced by Molecule, so no intermediate recording state was observable.
present - recording state - number of levels is limitedhad to compensate withskipItems(numberOfLevels / 2 - 1), a magic number that only worked because of the two-to-one coalescing ratio. Each level now advances the test time source and suspends for its share of the recording duration, so the states arrive one at a time,present - recording stateasserts both of them, and that magic number is gone.Call verification moved to the constructor lambdas used elsewhere in the repo, replacing the hand-rolled
startedCount/stoppedCount/deletedCountandassertCalls. The counters discarded the argument, so nothing pinned that cancelling a recording stops it withcancelled = true;present - abort recordingnow asserts exactly that.givenThrowsSecurityExceptionis replaced by a throwingstartRecordResult, and Truth is no longer a dependency of the fixture module.Finally, a second
startRecord()no longer raiseserror("Previous recording was not cleared"), whereDefaultVoiceRecorderonly warns and returns, and stopping or deleting now terminates an in-flight emission loop the way cancelling the real recording job does — so a staleRecordingstate can no longer arrive afterFinished, which is what made adding a delay to the fake break tests before.No production code changes.
Motivation and context
Part of #4770.
Tests
Test-only change.
DefaultVoiceMessageComposerPresenterTestis 28 tests green with the reworked fake.Behavioural gains, rather than a rename:
present - recording statenow asserts the intermediateRecording(500ms, [0.1f])as well as the final state;present - recording state - number of levels is limitedno longer depends on the coalescing ratio;present - abort recordingassertsstopRecord(cancelled = true), which the old counters could not see.Run with
./gradlew :features:messages:impl:testDebugUnitTest.Checked that the new
lambdaError()defaults do not fire throughFakeDefaultVoiceMessageComposerPresenterFactoryby runningMessagesPresenterTestunchanged, and that:libraries:voicerecorder:testand:features:messages:teststill compile.Tested devices
Checklist