refactor(ws): event layout (#10376)

* refactor(ws): event layout

BREAKING CHANGE: All events now emit shard id as its own param

* fix: worker event forwarding

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
DD
2024-07-24 21:40:34 +03:00
committed by GitHub
parent fcd35ea2e7
commit bf6761a44a
7 changed files with 137 additions and 134 deletions

View File

@@ -91,7 +91,7 @@ vi.mock('node:worker_threads', async () => {
op: WorkerReceivePayloadOp.Event,
shardId: message.shardId,
event: WebSocketShardEvents.Dispatch,
data: memberChunkData,
data: [memberChunkData],
};
this.emit('message', response);
@@ -204,10 +204,13 @@ test('spawn, connect, send a message, session info, and destroy', async () => {
};
await manager.send(0, payload);
expect(mockSend).toHaveBeenCalledWith(0, payload);
expect(managerEmitSpy).toHaveBeenCalledWith(WebSocketShardEvents.Dispatch, {
...memberChunkData,
shardId: 0,
});
expect(managerEmitSpy).toHaveBeenCalledWith(
WebSocketShardEvents.Dispatch,
{
...memberChunkData,
},
0,
);
expect(mockRetrieveSessionInfo).toHaveBeenCalledWith(0);
expect(mockUpdateSessionInfo).toHaveBeenCalledWith(0, { ...sessionInfo, sequence: sessionInfo.sequence + 1 });