Skip to content

Commit f6b6290

Browse files
Copilotajinkyasraj
andcommitted
test: improve race condition test assertions and comments
Co-authored-by: ajinkyasraj <145996984+ajinkyasraj@users.noreply.github.com>
1 parent 47091e6 commit f6b6290

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/octez.connect-transport-matrix/__tests__/communication-client/P2PCommunicationClient.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ describe('P2PCommunicationClient', () => {
287287
}
288288

289289
// Both concurrent callers will fail their getBeaconInfo calls
290-
// The fix ensures the second caller doesn't orphan the first caller's new promise
290+
// The fix ensures callers don't reset this.relayServer if another caller
291+
// has already created a new promise instance for retry, preventing orphaned promises
291292
let firstCallReachedCatch = false
292293
let secondCallReachedCatch = false
293294

@@ -317,11 +318,14 @@ describe('P2PCommunicationClient', () => {
317318
data: { region: 'us', known_servers: ['b'], timestamp: 3000 }
318319
})
319320

320-
// The third call should succeed and not hang
321+
// The third call should succeed without hanging (proving no orphaned promises)
321322
const thirdResult = await freshClient.getRelayServer()
322323

324+
expect(thirdResult.server).toBeDefined()
323325
expect(thirdResult.timestamp).toBe(3000)
324326
expect(firstCallReachedCatch || secondCallReachedCatch).toBe(true)
327+
// Both failed calls should have attempted cleanup
328+
expect(mockStorage.delete).toHaveBeenCalledWith(StorageKey.MATRIX_SELECTED_NODE)
325329
})
326330
})
327331

0 commit comments

Comments
 (0)