forked from memcachier/memjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lotofconnstest.js
executable file
·56 lines (46 loc) · 1.18 KB
/
lotofconnstest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! node
const MemJS = require(".");
async function nextTick() {
return new Promise((resolve) => setImmediate(resolve));
}
const clients = [];
async function body() {
// local memcached is default 1024 max connections
for (let i = 0; i < 1025; i++) {
const client = MemJS.Client.create(undefined, {timeout: 1, connTimeout: 2, retries: 1});
console.log("created", i);
client.servers.forEach((server) => {
server.onConnect((sock) => {
console.log("connected", i);
sock.once("close", (err) => {
console.log("closed", i, err);
})
sock.once("error", (err) => {
console.log("error handler", i, err);
})
})
})
try {
await client.get("foo");
console.log(i)
} catch (error) {
console.log("error", error, i);
}
clients.push(client);
}
}
async function main() {
try {
await body();
console.log("smoketest ok");
} catch (error) {
console.error("fatal", error);
process.exit(1);
} finally {
clients.forEach((client) => {
client.servers.forEach((server) => server._socket?.removeAllListeners("close"));
client.quit()
});
}
}
main();