Skip to content

Commit a904b04

Browse files
Fix 'operation buffered during sync' test to actually test buffering
The test introduced in 6b1c2de was not actually exercising the buffered-during-sync code path. It called counter.increment(5) and immediately completed the sync, but the ACK consistently arrived after sync completion, so the operation was applied directly rather than being buffered. The test passed even with the buffering implementation disabled. Fix by using an ACK interceptor to deterministically control when the ACK is delivered: intercept it, release it, then yield to the event loop so publishAndApply enters the sync-wait before we complete the sync. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4e2ddb0 commit a904b04

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/realtime/liveobjects.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8815,10 +8815,25 @@ define(['ably', 'shared_helper', 'chai', 'liveobjects', 'liveobjects_helper'], f
88158815
// inject an ATTACHED with HAS_OBJECTS to trigger SYNCING state
88168816
await injectAttachedMessage(helper, channel, 1 << 7); // HAS_OBJECTS flag is bit 7
88178817

8818+
// set up ACK interceptor so we can control when the ACK is delivered
8819+
const interceptor = createAckInterceptor(helper, client);
8820+
88188821
// perform an increment while in SYNCING state
8819-
// the ACK will be buffered until sync completes
88208822
const incrementPromise = counter.increment(5);
88218823

8824+
// wait for the ACK to be intercepted, then release it.
8825+
// this lets publishAndApply proceed past publish into the sync-wait.
8826+
await interceptor.waitForAck();
8827+
interceptor.releaseAll();
8828+
interceptor.restore();
8829+
8830+
// yield to the event loop so publishAndApply reaches the sync wait.
8831+
// (we use the same mechanism as the 'publishAndApply rejects when channel
8832+
// state changes during sync wait' test, which validates this yield is
8833+
// sufficient — if publishAndApply had not yet entered the sync-wait, the
8834+
// channel state change would not cause it to reject.)
8835+
await new Promise((resolve) => setTimeout(resolve, 0));
8836+
88228837
// complete the sync sequence
88238838
await objectsHelper.processObjectStateMessageOnChannel({
88248839
channel,

0 commit comments

Comments
 (0)