Repository navigation
Wait for initialisation instead of a fixed sleep in byte-communication tests - #321
Merged
Merged
Conversation
…n tests The simulator connect tests called connect() and then slept a fixed 3-5 s before asserting on the device. isConnected() turns true before the post-connect config read (infomem, calibration) runs, so on a loaded CI runner the read could miss the window and assertions such as getTrialDurationEstimatedInSecs() failed - seen in Shimmer-Advance-API run 37567210311, which passed on rerun. Add ByteCommunicationTestUtils.connectAndWaitUntilInitialised(), which waits until isInitialised() and the CONNECTED state (30 s ceiling, fails with a message on timeout), and use it for all 22 connect waits. The TaskCompletionSources it replaces were never completed, so they were only ever sleeps. Also disconnect the device in @after so earlier tests' IO threads and status timers no longer run on into later tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JongChern
approved these changes
Oct 12, 2026
JongChern
left a comment
Contributor
There was a problem hiding this comment.
Approved. This is test-only and fixes the flaky connect test.
- Test-only. All 15 files are under
ShimmerDriverPC/src/test. There are no driver changes, and the test exclusions inbuild.gradleare unchanged. - It fixes the failure we kept seeing. That assertion is
getTrialDurationEstimatedInSecs() != 1, which comes from the config bytes.initializeShimmer3or3RqueuesreadConfigBytes()beforereadStatusLogAndStream(), and the helper can't return until the status reply has moved the state to CONNECTED. So the config is always parsed by the time the asserts run, however slow the runner. - The removed
TaskCompletionSourcewaits were only fixed sleeps. Nothing ever completed them, so replacing them changes no behaviour. - The
@Afterdisconnect is safe. Each test creates a freshShimmerPCin@Before, so disconnecting afterwards can't affect later tests, and it stops earlier tests' threads polling the simulator. The 30 s limit reports the state when it fails. - Ran locally three times: all 11 active classes ran, 19/19 passed each time, and no case took over 5 s.
Suggestion (non-blocking)
"isInitialised() and CONNECTED" becomes true partway through the connect sequence:
- When the status reply arrives,
ShimmerPC.eventLogAndStreamStatusChangedmoves the state from CONNECTING to CONNECTED, andShimmerDeviceCallbackAdapter.setBluetoothRadioStatesetsisInitialised(true)alongside it. - That happens before the battery, Bluetooth firmware version, calibration dump and inquiry steps.
- The true end of the sequence is
inquiryDone(), which callsisReadyForStreaming()and sendsNOTIFICATION_SHIMMER_FULLY_INITIALIZED.
The config-based asserts are covered either way. A test that checks calibration, such as Shimmer3R test003_ConnectandTestCalibParamRead, could still race the calibration-dump read on a loaded runner. These classes already receive callbacks through BasicProcessWithCallBack, so waiting for that notification would close the gap. As the description notes, the streaming tests' 2 s data waits are also still fixed sleeps.
JongChern
approved these changes
Oct 12, 2026
JongChern
added a commit
that referenced
this pull request
Oct 15, 2026
The instruction list is guarded by two locks, the device's monitor and
the list's own. Every path takes them device first, list second, except
getInstruction() on the IOThread, which held the list's lock and then
called the synchronized getListofInstructions(). initializeShimmer3or3R()
starts the read-status timer with no delay just as the IOThread picks up
the first post-connect instruction, and the timer's
getListofInstructions() takes the two the other way round. When they met,
both blocked for good: the connect never finished, and disconnect()
could not stop the IOThread ("did not terminate within join timeout").
Thread dumps from Linux CI (lns0_16_11_w_sd_bt_streaming) and from a
local Windows run (API_0000X_ByteCommunicationShimmer3) show the same
cycle. #321 did not cause it. It made connects follow one another
without the old fixed sleeps, which made the race land on CI every time.
getInstruction() now reads the list directly under the list's lock only.
API_00029 forces the interleaving: a stand-in timer holds the device while
the IOThread takes an instruction, then asks for the list. It fails on
the old code and passes on the new.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
The byte-communication simulator tests in
ShimmerDriverPCcalledconnect()and then slept a fixed 3–5 s before asserting on the device.isConnected()turns true before the post-connect config read (infomem, calibration) runs, so on a loaded CI runner that read can miss the window.Seen in Shimmer-Advance-API run 37567210311:
API_0000X_ByteCommunicationShimmer3lns0_16_11_w_sd_bt_streaming.test001_testConnectandDisconnectfailed atgetTrialDurationEstimatedInSecs() != 1. The log shows the connect stalling afterConnecting STARTwith no infomem read inside the 5 s. A rerun passed.Change (test code only)
ByteCommunicationTestUtils.connectAndWaitUntilInitialised(): callsconnect(), then waits untilisInitialised()and theCONNECTEDstate. It has a 30 s ceiling and fails with the current state on timeout.TaskCompletionSources they replace were never completed, so they were only ever fixed sleeps.@Afternow disconnects the device, so earlier tests' IO threads and status timers no longer keep running into later tests (visible in the failing log as otherShimmerPCinstances still pollingGET_STATUS).mStreamingTaskwaits in the streaming tests are unchanged. They wait for data packets, which is a separate concern.The
w_sd_only,w_sync_masterandw_sync_slaveclasses were also updated but are still excluded inShimmerDriverPC/build.gradle; that exclusion is unchanged.Testing
ShimmerDriverPC> gradlew :test --rerun: 54/54 pass locally (JDK 11). The previously failing test now completes in ~1 s rather than always sleeping 5 s. It ran once locally, so CI on this PR is the real check under load.🤖 Generated with Claude Code