Files
bun.sh/test/js/third_party/socket.io/socket.io-socket-timeout.test.ts
Jarred Sumner e848c3f226 Get Bun.write tests to pass on Windows and bun:sqlite tests to pass (#8393)
* Move ReadFile and WriteFile to separate file

* Use libuv for Bun.write()

* Update windows_event_loop.zig

* build

* Get bun-write tests to pass. Implement Bun.write with two files.

* UPdate

* Update

* Update failing test list

* update

* More

* More

* More

* More

* Mark the rest

* ok

* oops

* Update bun-write.test.js

* Update blob.zig

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dave Caruso <me@paperdave.net>
Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
2024-01-23 20:03:56 -08:00

137 lines
3.6 KiB
TypeScript

import { Server } from "socket.io";
import { describe, it, expect } from "bun:test";
import { success, fail, createClient } from "./support/util.ts";
// Hanging tests are disabled because they cause the test suite to hang
describe.skip("timeout", () => {
it("should timeout if the client does not acknowledge the event", done => {
const io = new Server(0);
const client = createClient(io, "/");
try {
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), client);
}, 200);
io.on("connection", socket => {
socket.timeout(50).emit("unknown", err => {
clearTimeout(timeout);
try {
expect(err).toBeInstanceOf(Error);
success(done, io, client);
} catch (err) {
fail(done, io, err, client);
}
});
});
} catch (err) {
fail(done, io, err, client);
}
});
it("should timeout if the client does not acknowledge the event in time", done => {
const io = new Server(0);
const client = createClient(io, "/");
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), client);
}, 500);
client.on("echo", (arg, cb) => {
cb(arg);
});
let count = 0;
io.on("connection", socket => {
socket.timeout(0).emit("echo", 42, err => {
try {
expect(err).toBeInstanceOf(Error);
count++;
} catch (err) {
clearTimeout(timeout);
fail(done, io, err, client);
}
});
});
setTimeout(() => {
clearTimeout(timeout);
try {
expect(count).toBe(1);
success(done, io, client);
} catch (err) {
fail(done, io, err, client);
}
}, 200);
});
it("should not timeout if the client does acknowledge the event", done => {
const io = new Server(0);
const client = createClient(io, "/");
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), client);
}, 200);
client.on("echo", (arg, cb) => {
cb(arg);
});
io.on("connection", socket => {
socket.timeout(50).emit("echo", 42, (err, value) => {
clearTimeout(timeout);
try {
expect(err).toBe(null);
expect(value).toBe(42);
success(done, io, client);
} catch (err) {
fail(done, io, err, client);
}
});
});
});
it("should timeout if the client does not acknowledge the event (promise)", done => {
const io = new Server(0);
const client = createClient(io, "/");
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), client);
}, 200);
io.on("connection", async socket => {
try {
await socket.timeout(50).emitWithAck("unknown");
clearTimeout(timeout);
fail(done, io, new Error("timeout"), client);
} catch (err) {
clearTimeout(timeout);
expect(err).toBeInstanceOf(Error);
success(done, io, client);
}
});
});
it("should not timeout if the client does acknowledge the event (promise)", done => {
const io = new Server(0);
const client = createClient(io, "/");
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), client);
}, 200);
client.on("echo", (arg, cb) => {
cb(arg);
});
io.on("connection", async socket => {
try {
const value = await socket.timeout(50).emitWithAck("echo", 42);
clearTimeout(timeout);
expect(value).toBe(42);
success(done, io, client);
} catch (err) {
clearTimeout(timeout);
fail(done, io, err, client);
}
});
});
});