+34
-10
@@ -14,6 +14,30 @@ import { createPlayer, namePlayer, sleep } from './lib.mjs'
|
||||
|
||||
const ID_RE = /^[A-Za-z0-9_-]{12}$/
|
||||
|
||||
// A synchronising round-trip before an absence assertion (the leak driver's quiet-group rule): an
|
||||
// ack'd GM action guarantees the server finished the earlier mutation under its lock, then the
|
||||
// quiet window observes that no socket is still delivering frames. A fixed sleep would make
|
||||
// "nothing arrived" a race; this makes it an observation.
|
||||
const QUIET_MS = 60
|
||||
async function quiet(clients, quietMs = QUIET_MS) {
|
||||
const deadline = Date.now() + 5000
|
||||
let last = -1
|
||||
let since = Date.now()
|
||||
for (;;) {
|
||||
const n = clients.reduce((a, c) => a + c.ws.messages.length, 0)
|
||||
if (n !== last) { last = n; since = Date.now() }
|
||||
if (Date.now() - since >= quietMs) return
|
||||
if (Date.now() > deadline) throw new Error('server never went quiet')
|
||||
await sleep(10)
|
||||
}
|
||||
}
|
||||
async function settle(gm, clients) {
|
||||
// The caller has already awaited the ack of the action under test, so the server has run the
|
||||
// mutation (and is writing the derived frames right after the ack, under the same lock). Observe
|
||||
// quiescence on every socket before asserting absence, exactly like the leak driver's group end.
|
||||
await quiet([gm, ...clients])
|
||||
}
|
||||
|
||||
async function gmConnect(origin, gmKey) {
|
||||
const conn = await openAs(origin, gmKey)
|
||||
await conn.ws.waitText('hello')
|
||||
@@ -84,7 +108,7 @@ test('marker emission: only a marked window, exact anchor and count, no wall fie
|
||||
// A solid wall with the switch on stores the switch and sends nothing (5.8 gate).
|
||||
let from = player.conn.ws.messages.length
|
||||
await addWall(gm, { a: [100, 700], b: [400, 700], player_marker: true })
|
||||
await sleep(120)
|
||||
await settle(gm, [player.conn])
|
||||
assert.equal(markersAfter(player.conn.ws, from).length, 0,
|
||||
'a solid wall with player_marker:true emits no marker')
|
||||
|
||||
@@ -92,7 +116,7 @@ test('marker emission: only a marked window, exact anchor and count, no wall fie
|
||||
from = player.conn.ws.messages.length
|
||||
await addWall(gm, { blocks_sight: false, blocks_movement: true, door: true,
|
||||
player_marker: false, a: [500, 500], b: [500, 700] })
|
||||
await sleep(120)
|
||||
await settle(gm, [player.conn])
|
||||
assert.equal(markersAfter(player.conn.ws, from).length, 0,
|
||||
'a window with its marker off emits nothing')
|
||||
|
||||
@@ -129,7 +153,7 @@ test('marker lifetime and resync: survives walk-away and doors, full after explo
|
||||
let from = alice.conn.ws.messages.length
|
||||
assert.equal((await gm.ws.request({ t: 'token.move', id: aliceToken,
|
||||
pos: [2000, 2000] })).ok, true)
|
||||
await sleep(120)
|
||||
await settle(gm, [alice.conn])
|
||||
assert.equal(markersAfter(alice.conn.ws, from).length, 0,
|
||||
'walking away never retracts or re-sends a marker')
|
||||
|
||||
@@ -138,7 +162,7 @@ test('marker lifetime and resync: survives walk-away and doors, full after explo
|
||||
from = alice.conn.ws.messages.length
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: window.id,
|
||||
open })).ok, true)
|
||||
await sleep(80)
|
||||
await settle(gm, [alice.conn])
|
||||
assert.equal(markersAfter(alice.conn.ws, from).length, 0,
|
||||
`door.set open:${open} leaves the marker alone`)
|
||||
}
|
||||
@@ -173,7 +197,7 @@ test('marker lifetime and resync: survives walk-away and doors, full after explo
|
||||
player_marker: false })).ok, true)
|
||||
const carol = await namedPlayer(gm, s.origin, 'Marker Carol')
|
||||
await addSightToken(gm, carol, [300, 300])
|
||||
await sleep(150)
|
||||
await settle(gm, [carol.conn])
|
||||
const carolMarkers = markerFrames(carol.conn.ws).flatMap(m => m.set)
|
||||
assert.equal(carolMarkers.length, 0, 'a window with the switch off is an invisible barrier')
|
||||
|
||||
@@ -238,17 +262,17 @@ test('retraction: every cause sends del only, a re-earned marker gets a fresh id
|
||||
const away = async () => {
|
||||
assert.equal((await gm.ws.request({ t: 'token.move', id: tokenId,
|
||||
pos: [2000, 2000] })).ok, true)
|
||||
await sleep(100)
|
||||
await quiet([gm, alice.conn])
|
||||
}
|
||||
const back = async () => {
|
||||
assert.equal((await gm.ws.request({ t: 'token.move', id: tokenId,
|
||||
pos: [300, 300] })).ok, true)
|
||||
await sleep(100)
|
||||
await quiet([gm, alice.conn])
|
||||
}
|
||||
const retract = async action => {
|
||||
const from = alice.conn.ws.messages.length
|
||||
assert.equal((await action()).ok, true)
|
||||
await sleep(100)
|
||||
await settle(gm, [alice.conn])
|
||||
return framesAfter(alice.conn.ws, from)
|
||||
}
|
||||
const reEarn = async what => {
|
||||
@@ -370,12 +394,12 @@ test('marker retraction is durable: delete and cascade survive a restart (#60)',
|
||||
let from = alice.conn.ws.messages.length
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id: off.id,
|
||||
player_marker: false })).ok, true)
|
||||
await sleep(100)
|
||||
await settle(gm, [alice.conn])
|
||||
assert.deepEqual(markersAfter(alice.conn.ws, from)[0].del, [offId])
|
||||
from = alice.conn.ws.messages.length
|
||||
assert.equal((await gm.ws.request({ t: 'wall.remove', scene: gm.scene,
|
||||
id: gone.id })).ok, true)
|
||||
await sleep(100)
|
||||
await settle(gm, [alice.conn])
|
||||
assert.deepEqual(markersAfter(alice.conn.ws, from)[0].del, [goneId])
|
||||
gm.ws.close(); alice.conn.ws.close()
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user