Skip to content

Commit

Permalink
test(server): should call onComplete if socket terminates
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Nov 3, 2020
1 parent c4be80d commit 3f5c42e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,45 @@ describe('Subscribe', () => {
}),
);
});

it('should call `onComplete` callback even if socket terminates abruptly', async (done) => {
const server = await startTServer({
onComplete: () => {
done();
},
});

const client = await createTClient(server.url);
client.ws.send(
stringifyMessage<MessageType.ConnectionInit>({
type: MessageType.ConnectionInit,
}),
);

await client.waitForMessage(({ data }) => {
expect(parseMessage(data).type).toBe(MessageType.ConnectionAck);
});

client.ws.send(
stringifyMessage<MessageType.Subscribe>({
id: '1',
type: MessageType.Subscribe,
payload: {
query: 'subscription { ping }',
},
}),
);
await server.waitForOperation();

// just to make sure we're streaming
server.pong();
await client.waitForMessage(({ data }) => {
expect(parseMessage(data).type).toBe(MessageType.Next);
});

// terminate socket abruptly
client.ws.terminate();
});
});

describe('Keep-Alive', () => {
Expand Down

0 comments on commit 3f5c42e

Please sign in to comment.