Skip to content

Commit

Permalink
fixe timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKolberg committed Dec 8, 2023
1 parent ea9b082 commit 2770f1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion _examples/golang-sse/webapp/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const sseResponse = async (
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
const timeout = 10 + 1 * 1000;
const timeout = (10 + 1) * 1000;

while (true) {
let value;
Expand Down
32 changes: 20 additions & 12 deletions _examples/golang-sse/webapp/tests/sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,24 @@ test("call onError with WebrpcStreamLostError on stream error", async () => {
expect(error).toEqual(new WebrpcStreamLostError());
});

test("call onError with WebrpcStreamLostError on stream timeout", async () => {
const mockFetch = createMockFetch({ closeStream: false });
const api = new Chat("", mockFetch);
let error: WebrpcError | undefined;

const onError = (err: WebrpcError) => {
error = err;
};

await api.subscribeMessages({ serverTimeoutSec: 10 }, { onMessage, onError });
test(
"call onError with WebrpcStreamLostError on stream timeout",
async () => {
const mockFetch = createMockFetch({ closeStream: false });
const api = new Chat("", mockFetch);
let error: WebrpcError | undefined;

const onError = (err: WebrpcError) => {
console.log("onError()", err);
error = err;
};

await api.subscribeMessages(
{ serverTimeoutSec: 10 },
{ onMessage, onError }
);

expect(error).toEqual(new WebrpcStreamLostError());
});
expect(error).toEqual(new WebrpcStreamLostError());
},
20 * 1000
);

0 comments on commit 2770f1b

Please sign in to comment.