fix: player.setname acks before its effects (#33)
The durable write and registry update stay put; the ack is enqueued between the commit and the first effect, then hello, the full resync and roster follow in their existing order. The failure paths are unchanged. Frame-order test pins ack first on the renaming connection.
This commit is contained in:
@@ -618,3 +618,38 @@ async function openAs_(origin, key) {
|
||||
const ws = await openWs(origin, cookie)
|
||||
return { ws, cookie }
|
||||
}
|
||||
|
||||
// #33: the ack is the first frame a client can observe for its `reqId` (DESIGN 6.1 Ack, 4.2).
|
||||
// `player.setname` used to push `hello`, the resync and `roster` before its ack.
|
||||
test('player.setname: the ack precedes hello, the resync and roster', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await createPlayer(gm.ws)
|
||||
const { cookie } = await signIn(s.origin, alice.key)
|
||||
const ws = await openWs(s.origin, cookie)
|
||||
await ws.waitText('hello')
|
||||
const mark = ws.messages.length
|
||||
const ack = await ws.request({ t: 'player.setname', name: 'Alice' })
|
||||
assert.equal(ack.ok, true, JSON.stringify(ack))
|
||||
await ws.waitFor((m, i) => i >= mark && m.t === 'roster')
|
||||
const seq = ws.messages.slice(mark).map(m => m.t)
|
||||
assert.equal(seq[0], 'ack', `the ack must come first for this reqId: ${JSON.stringify(seq)}`)
|
||||
const at = t => seq.indexOf(t)
|
||||
assert.ok(at('ack') < at('hello'), 'ack before the second hello')
|
||||
assert.ok(at('hello') < at('roster'), 'the effects keep their own order: hello, then roster')
|
||||
assert.ok(at('ack') < at('vision'), 'ack before the resync frames')
|
||||
|
||||
// The failure path is unchanged: one error ack, no hello and no resync.
|
||||
const bob = await createPlayer(gm.ws)
|
||||
const { cookie: bobCookie } = await signIn(s.origin, bob.key)
|
||||
const b = await openWs(s.origin, bobCookie)
|
||||
await b.waitText('hello')
|
||||
const mark2 = b.messages.length
|
||||
const taken = await b.request({ t: 'player.setname', name: 'alice' })
|
||||
assert.equal(taken.code, 'name-taken')
|
||||
await sleep(50)
|
||||
const after = b.messages.slice(mark2).map(m => m.t)
|
||||
assert.deepEqual(after, ['ack'], `a refused rename has no effects: ${JSON.stringify(after)}`)
|
||||
ws.close(); b.close(); gm.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user