Skip to content

Commit ad9ed9a

Browse files
joes edits
1 parent 64176c6 commit ad9ed9a

4 files changed

Lines changed: 14 additions & 64 deletions

File tree

packages/ws-worker/src/channels/worker-queue.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ const connectToWorkerQueue = (
7474
didOpen = true;
7575
shouldReportConnectionError = true;
7676

77-
// Build join payload with capacity if provided
78-
const joinPayload = capacity !== undefined ? { capacity } : {};
79-
77+
const joinPayload = { capacity };
8078
const channel = socket.channel('worker:queue', joinPayload) as Channel;
8179

8280
channel.onMessage = (ev, load) => {

packages/ws-worker/src/mock/sockets.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,8 @@ export class MockSocket {
125125
if (!this.allChannels[topic]) {
126126
this.allChannels[topic] = mockChannel();
127127
}
128-
// Store params on the channel for testing purposes
129-
if (params) {
130-
// @ts-ignore
131-
this.allChannels[topic]._joinParams = params;
132-
}
128+
// @ts-ignore
129+
this.allChannels[topic]._joinParams = params;
133130
return this.allChannels[topic];
134131
}
135132
}

packages/ws-worker/test/channels/worker-queue.test.ts

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -108,55 +108,26 @@ test('should fail to connect with an invalid auth token', async (t) => {
108108

109109
test('should pass capacity in join payload when provided', (t) => {
110110
return new Promise((done) => {
111-
function createSocket(endpoint: string, _options: any) {
112-
const socket = new MockSocket(endpoint, {}, async () => {});
113-
114-
// Override channel method to capture join params
115-
const originalChannel = socket.channel.bind(socket);
116-
socket.channel = (topic: string, params?: any) => {
117-
const channel = originalChannel(topic, params);
118-
if (topic === 'worker:queue') {
119-
t.truthy(params);
120-
t.is(params.capacity, 10);
121-
}
122-
return channel;
123-
};
124-
125-
return socket;
126-
}
127-
128111
connectToWorkerQueue('www', 'a', 'secret', logger, {
129112
capacity: 10,
130-
SocketConstructor: createSocket as any,
131-
}).on('connect', () => {
132-
t.pass('connected with capacity');
113+
SocketConstructor: MockSocket as any,
114+
}).on('connect', ({ socket }) => {
115+
const channel = socket.allChannels['worker:queue'];
116+
// @ts-ignore - accessing test property
117+
t.is(channel._joinParams.capacity, 10);
133118
done();
134119
});
135120
});
136121
});
137122

138-
test('should not pass capacity in join payload when not provided', (t) => {
123+
test('should pass capacity in join payload when not provided', (t) => {
139124
return new Promise((done) => {
140-
function createSocket(endpoint: string, _options: any) {
141-
const socket = new MockSocket(endpoint, {}, async () => {});
142-
143-
// Override channel method to capture join params
144-
const originalChannel = socket.channel.bind(socket);
145-
socket.channel = (topic: string, params?: any) => {
146-
const channel = originalChannel(topic, params);
147-
if (topic === 'worker:queue') {
148-
t.deepEqual(params, {});
149-
}
150-
return channel;
151-
};
152-
153-
return socket;
154-
}
155-
156125
connectToWorkerQueue('www', 'a', 'secret', logger, {
157-
SocketConstructor: createSocket as any,
158-
}).on('connect', () => {
159-
t.pass('connected without capacity');
126+
SocketConstructor: MockSocket as any,
127+
}).on('connect', ({ socket }) => {
128+
const channel = socket.allChannels['worker:queue'];
129+
// @ts-ignore - accessing test property
130+
t.is(channel._joinParams.capacity, undefined);
160131
done();
161132
});
162133
});

packages/ws-worker/test/util/cli.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,3 @@ test('cli should handle array options correctly for env variables', (t) => {
108108

109109
t.deepEqual(args.statePropsToRemove, ['prop1', 'prop2', 'prop3']);
110110
});
111-
112-
test('cli should parse WORKER_CAPACITY from env', (t) => {
113-
process.env.WORKER_CAPACITY = '10';
114-
const argv = 'pnpm start'.split(' ');
115-
const args = cli(argv);
116-
117-
t.is(args.capacity, 10);
118-
});
119-
120-
test('cli should override WORKER_CAPACITY env with --capacity arg', (t) => {
121-
process.env.WORKER_CAPACITY = '10';
122-
const argv = 'pnpm start --capacity 20'.split(' ');
123-
const args = cli(argv);
124-
125-
t.is(args.capacity, 20);
126-
});

0 commit comments

Comments
 (0)