socketio / socket.io-protocol

Socket.IO Protocol specification
https://socket.io
507 stars 62 forks source link

Difference between the socket.io-protocol and engine.io-protocol for the same test #29

Closed Totodore closed 1 year ago

Totodore commented 1 year ago

Hi !

I'm working on a socket.io server implementation in rust and I use a lot your socket.io and engine.io test-suite. I have some problems with the test should ignore WebSocket connection with same sid after upgrade though.

The implementation in the socket.io-protocol is :

const sid = await initLongPollingSession();

const socket = new WebSocket(
  `${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
);

await waitFor(socket, "open");
socket.send("2probe");
socket.send("5");

const socket2 = new WebSocket(
  `${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
);

await waitFor(socket2, "close");

The implementation in the engine.io-protocol is :

const sid = await initLongPollingSession();

const socket = new WebSocket(
  `${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
);

await waitFor(socket, "open");
socket.send("2probe");
socket.send("5");

const socket2 = new WebSocket(
  `${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
);
await waitFor(socket2, "error");

socket.send("4hello");

const { data } = await waitFor(socket, "message");

expect(data).to.eql("4hello");

In the first implementation it waits for the second socket to close whereas in the second implementation it waits for the second socket to throw an error. Therefore I have some problems testing my implementation :

First I had to make it return a 400 bad request when upgrading the second socket (to match the second implementation) but then to match the first implementation I had to gracefully close the connection (and then the second doesn't work correctly).

I suppose there is a solution to match both implementation in node but I don't know if I could do the same in rust.

Thanks for your help !