Skip to content

Commit f41c4e2

Browse files
committed
Trigger websocket bugs
1 parent cf5a245 commit f41c4e2

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

‎tests/Hammer.js‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ let closedClientConnections = 0;
1717

1818
let listenSocket;
1919

20+
function getRandomInt(max) {
21+
return Math.floor(Math.random() * Math.floor(max));
22+
}
23+
2024
/* Perform random websockets/ws action */
2125
function performRandomClientAction(ws) {
22-
console.log("performing random ws action");
23-
26+
uWS.print('Random client action');
2427
ws.send('test message from client');
28+
uWS.print('Random client action, done');
2529
}
2630

2731
/* Perform random uWebSockets.js action */
@@ -31,7 +35,7 @@ function establishNewConnection() {
3135

3236
ws.on('open', () => {
3337
/* Open more connections */
34-
if (++openedClientConnections < 10) {
38+
if (++openedClientConnections < 1) {
3539
establishNewConnection();
3640
} else {
3741
/* Stop listening */
@@ -43,40 +47,56 @@ function establishNewConnection() {
4347
});
4448

4549
ws.on('message', (data) => {
50+
console.log('client got message: ' + data);
4651
performRandomClientAction(ws);
4752
});
4853

4954
ws.on('close', () => {
50-
performRandomClientAction(ws);
55+
console.log("client was closed");
56+
//performRandomClientAction(ws);
5157
});
5258
}
5359

5460

5561
function performRandomServerAction(ws) {
56-
console.log("performing random server action");
57-
58-
ws.send('a test message');
62+
//uWS.print('Random server action');
63+
switch (getRandomInt(1)) {
64+
case 0: {
65+
ws.close();
66+
break;
67+
}
68+
case 1: {
69+
ws.send('a test message', false);
70+
break;
71+
}
72+
}
73+
//uWS.print('Done with random server action');
5974
}
6075

6176
const app = uWS./*SSL*/App({
6277
key_file_name: 'misc/key.pem',
6378
cert_file_name: 'misc/cert.pem',
6479
passphrase: '1234'
6580
}).ws('/*', {
66-
/*compression: 0,
81+
compression: 0,
6782
maxPayloadLength: 16 * 1024 * 1024,
68-
idleTimeout: 10,*/
83+
idleTimeout: 10,
6984

7085
open: (ws, req) => {
86+
uWS.print('Server open event');
7187
performRandomServerAction(ws);
88+
uWS.print('Server open event, returning');
7289
},
7390
message: (ws, message, isBinary) => {
91+
console.log('server got message: ' + message.byteLength);
7492
performRandomServerAction(ws);
7593
},
7694
drain: (ws) => {
95+
// todo: dont send over a certain backpressure
7796
//performRandomServerAction(ws);
7897
},
7998
close: (ws, code, message) => {
99+
console.log('server was closed');
80100
//performRandomServerAction(ws);
81101
}
82102
}).any('/*', (res, req) => {

0 commit comments

Comments
 (0)