Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/get-port.test.ts
1447 views
1
import getPort, { getPorts } from "./get-port";
2
3
describe("test getting a random available port", () => {
4
it("tests it", async () => {
5
const port = await getPort();
6
expect(port).toBeGreaterThan(1024);
7
});
8
});
9
10
describe("test getPorts -- getting many ports at once in parallel", () => {
11
const count = 1000;
12
it(`get ${count} ports at once, thus testing it isn't too slow and also nice to see no conflicts`, async () => {
13
const start = Date.now();
14
const w = await getPorts(count);
15
expect(new Set(w).size).toBe(count);
16
// takes ~200ms to get 5000 of them on my laptop, but with heavy load
17
// it can be much slower.
18
expect(Date.now() - start).toBeLessThan(4000);
19
});
20
});
21
22