-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server_sync.js
More file actions
56 lines (48 loc) · 1.72 KB
/
Copy pathtest_server_sync.js
File metadata and controls
56 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Multi-Client Real-Time SSE Sync Verification Test Suite
*/
import http from 'http';
console.log('=== Running Alegio.js Real-Time SSE Multi-Client Sync Test ===\n');
// 1. Establish SSE Client B listener
const reqB = http.request('http://localhost:8085/api/stream', (res) => {
console.log('✅ PASS: Client B connected to SSE Stream (HTTP 200)');
res.on('data', (chunk) => {
const raw = chunk.toString();
const lines = raw.split('\n');
lines.forEach(line => {
if (line.startsWith('data: ')) {
const payload = JSON.parse(line.replace('data: ', ''));
if (payload.type === 'STATE_UPDATE') {
console.log(`✅ PASS: Client B received real-time broadcast from ${payload.sender}:`);
console.log(` Updated '${payload.key}' data count = ${payload.data.length} items`);
console.log('\n🎉 Multi-Client Real-Time SSE Sync Verification Successful!');
process.exit(0);
}
}
});
});
});
reqB.end();
// 2. Client A posts a state mutation to /api/state after 500ms
setTimeout(() => {
console.log('📡 Client A sending state mutation to /api/state...');
const postData = JSON.stringify({
key: 'todos_state',
clientId: 'client_A_test',
data: [
{ id: '1', title: 'Task 1', completed: true },
{ id: '2', title: 'Task 2 Realtime Test', completed: false }
]
});
const postReq = http.request('http://localhost:8085/api/state', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
}, (res) => {
console.log('✅ PASS: Client A state mutation committed to Edge Server DB');
});
postReq.write(postData);
postReq.end();
}, 500);