Switch HTTP Server
This commit is contained in:
39
lib/PsychicHttp/benchmark/eventsource-client-test.js
Normal file
39
lib/PsychicHttp/benchmark/eventsource-client-test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const EventSource = require('eventsource');
|
||||
const url = 'http://192.168.2.131/events';
|
||||
|
||||
async function eventSourceClient() {
|
||||
console.log(`Starting test`);
|
||||
for (let i = 0; i < 1000000; i++)
|
||||
{
|
||||
if (i % 100 == 0)
|
||||
console.log(`Count: ${i}`);
|
||||
|
||||
let eventSource = new EventSource(url);
|
||||
|
||||
eventSource.onopen = () => {
|
||||
//console.log('EventSource connection opened.');
|
||||
};
|
||||
|
||||
eventSource.onerror = (error) => {
|
||||
console.error('EventSource error:', error);
|
||||
|
||||
// Close the connection on error
|
||||
eventSource.close();
|
||||
};
|
||||
|
||||
await new Promise((resolve) => {
|
||||
eventSource.onmessage = (event) => {
|
||||
//console.log('Received message:', event.data);
|
||||
|
||||
// Close the connection after receiving the first message
|
||||
eventSource.close();
|
||||
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
eventSourceClient();
|
||||
Reference in New Issue
Block a user