Skip to content

Commit f9fbe8e

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 54d1630 commit f9fbe8e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/realtime/liveobjects.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8815,10 +8815,24 @@ 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+
8829+
// yield to the event loop so publishAndApply reaches the sync wait.
8830+
// (we use the same mechanism as the 'publishAndApply rejects when channel
8831+
// state changes during sync wait' test, which validates this yield is
8832+
// sufficient — if publishAndApply had not yet entered the sync-wait, the
8833+
// channel state change would not cause it to reject.)
8834+
await new Promise((resolve) => setTimeout(resolve, 0));
8835+
88228836
// complete the sync sequence
88238837
await objectsHelper.processObjectStateMessageOnChannel({
88248838
channel,

0 commit comments

Comments
 (0)