docs
This commit is contained in:
@@ -36,6 +36,8 @@ RENDER(Request& context)
|
||||
const socketDetail = document.getElementById('socket-detail');
|
||||
let sawHello = false;
|
||||
let sawBroadcast = false;
|
||||
let sawState = false;
|
||||
let stateAck = null;
|
||||
|
||||
function mark(el, detailEl, ok, text) {
|
||||
el.textContent = ok ? 'PASS' : 'FAIL';
|
||||
@@ -67,10 +69,19 @@ RENDER(Request& context)
|
||||
if (payload.type === 'hello-ack') {
|
||||
sawHello = true;
|
||||
mark(helloStatus, helloDetail, true, JSON.stringify(payload, null, 2));
|
||||
ws.send(JSON.stringify({ type: 'set-state', nonce }));
|
||||
ws.send(JSON.stringify({ type: 'read-state', nonce }));
|
||||
ws.send(JSON.stringify({ type: 'broadcast', nonce }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.type === 'state-ack') {
|
||||
sawState = true;
|
||||
stateAck = payload;
|
||||
mark(socketStatus, socketDetail, true, `state count=${payload.state_count}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.type === 'broadcast-ack') {
|
||||
sawBroadcast = true;
|
||||
mark(broadcastStatus, broadcastDetail, true, JSON.stringify(payload, null, 2));
|
||||
@@ -87,12 +98,17 @@ RENDER(Request& context)
|
||||
ws.addEventListener('close', () => {
|
||||
if (!sawHello) mark(helloStatus, helloDetail, false, 'socket closed before hello acknowledgment');
|
||||
if (!sawBroadcast) mark(broadcastStatus, broadcastDetail, false, 'socket closed before broadcast acknowledgment');
|
||||
if (!sawHello || !sawBroadcast) mark(socketStatus, socketDetail, false, 'socket closed before suite completed');
|
||||
if (!sawState) {
|
||||
mark(socketStatus, socketDetail, false, 'socket closed before state round trip');
|
||||
} else {
|
||||
mark(socketStatus, socketDetail, true, `state count=${stateAck && stateAck.state_count}`);
|
||||
}
|
||||
});
|
||||
|
||||
window.setTimeout(() => {
|
||||
if (!sawHello) mark(helloStatus, helloDetail, false, 'timeout waiting for hello acknowledgment');
|
||||
if (!sawBroadcast) mark(broadcastStatus, broadcastDetail, false, 'timeout waiting for broadcast acknowledgment');
|
||||
if (!sawState) mark(socketStatus, socketDetail, false, 'timeout waiting for state-ack');
|
||||
}, 5000);
|
||||
</script><?
|
||||
site_tests_page_end();
|
||||
@@ -122,5 +138,19 @@ WS(Request& context)
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == "set-state")
|
||||
{
|
||||
context.connection["state_count"].set((f64)((u64)context.connection["state_count"].to_u64() + 1));
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == "read-state")
|
||||
{
|
||||
DValue event = websocket_suite_event(context, "state-ack", nonce);
|
||||
event["state_count"] = (f64)context.connection["state_count"].to_u64();
|
||||
ws_send_to(ws_connection_id(), json_encode(event));
|
||||
return;
|
||||
}
|
||||
|
||||
ws_send_to(ws_connection_id(), json_encode(websocket_suite_event(context, "unknown", nonce)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user