Skip to content

Commit fa9c829

Browse files
committed
refactor sticky tests
1 parent b327064 commit fa9c829

File tree

3 files changed

+84
-83
lines changed

3 files changed

+84
-83
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { before, after, wait } from "@cocalc/backend/conat/test/setup";
2+
import { STICKY_QUEUE_GROUP } from "@cocalc/conat/core/client";
3+
import { createCluster } from "./util";
4+
5+
beforeAll(before);
6+
7+
describe("create cluster of two nodes, and verify that *sticky* subs properly work", () => {
8+
let server1, server2, client1, client1b, client2;
9+
it("create two distinct servers and link them", async () => {
10+
({ server: server1, client: client1 } = await createCluster({
11+
systemAccountPassword: "squeamish",
12+
}));
13+
client1b = server1.client();
14+
({ server: server2, client: client2 } = await createCluster({
15+
systemAccountPassword: "ossifrage",
16+
}));
17+
await server1.addSuperclusterLink({
18+
client: client2,
19+
clusterName: server2.clusterName,
20+
});
21+
await server2.addSuperclusterLink({
22+
client: client1,
23+
clusterName: server1.clusterName,
24+
});
25+
});
26+
27+
let sub1, sub1b;
28+
let recv1 = 0,
29+
recv1b = 0;
30+
const subject = "5077.org";
31+
it("make two subscriptions with the same sticky queue group", async () => {
32+
sub1 = await client1.sub(subject, { queue: STICKY_QUEUE_GROUP });
33+
(async () => {
34+
for await (const _ of sub1) {
35+
recv1++;
36+
}
37+
})();
38+
sub1b = await client1b.sub(subject, { queue: STICKY_QUEUE_GROUP });
39+
(async () => {
40+
for await (const _ of sub1b) {
41+
recv1b++;
42+
}
43+
})();
44+
});
45+
46+
let count = 50;
47+
it("send messages and note they all go to the same target -- first the easy sanity check all on the same node", async () => {
48+
await client1.waitForInterest(subject);
49+
for (let i = 0; i < count; i++) {
50+
await client1.publish(subject, "hi");
51+
}
52+
await wait({ until: () => recv1 + recv1b >= count });
53+
expect(recv1 + recv1b).toEqual(count);
54+
expect(recv1 * recv1b).toEqual(0);
55+
});
56+
57+
it("send messages and note they all go to the same target -- next the hard case across the cluster", async () => {
58+
await client2.waitForInterest(subject);
59+
for (let i = 0; i < count; i++) {
60+
await client2.publish(subject, "hi");
61+
}
62+
await wait({ until: () => recv1 + recv1b >= 2 * count });
63+
expect(recv1 + recv1b).toEqual(2 * count);
64+
expect(recv1 * recv1b).toEqual(0);
65+
});
66+
});
67+
68+
afterAll(after);

src/packages/backend/conat/test/supercluster/supercluster.test.ts

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,18 @@ pnpm test `pwd`/supercluster.test.ts
55
66
*/
77

8-
import {
9-
before,
10-
after,
11-
initConatServer,
12-
once,
13-
delay,
14-
wait,
15-
} from "@cocalc/backend/conat/test/setup";
8+
import { before, after, delay, once, wait } from "@cocalc/backend/conat/test/setup";
169
import {
1710
superclusterLink,
1811
superclusterStreams,
1912
superclusterService,
2013
trimSuperclusterStreams,
2114
} from "@cocalc/conat/core/supercluster";
2215
import { isEqual } from "lodash";
23-
import { STICKY_QUEUE_GROUP } from "@cocalc/conat/core/client";
16+
import { createCluster } from "./util";
2417

2518
beforeAll(before);
2619

27-
let clusterName = 0;
28-
async function createCluster(opts?) {
29-
clusterName += 1;
30-
const server = await initConatServer({
31-
clusterName: `${clusterName}`,
32-
id: "0",
33-
systemAccountPassword: "foo",
34-
...opts,
35-
});
36-
const client = server.client();
37-
return { server, client };
38-
}
39-
4020
describe("create a supercluster enabled socketio server and test that the streams update as they should", () => {
4121
let server, client;
4222
it("create a server with supercluster support enabled", async () => {
@@ -391,65 +371,4 @@ describe("test trimming the interest stream", () => {
391371
});
392372
});
393373

394-
describe.only("create cluster of two nodes, and verify that *sticky* subs properly work", () => {
395-
let server1, server2, client1, client1b, client2;
396-
it("create two distinct servers and link them", async () => {
397-
({ server: server1, client: client1 } = await createCluster({
398-
systemAccountPassword: "squeamish",
399-
}));
400-
client1b = server1.client();
401-
({ server: server2, client: client2 } = await createCluster({
402-
systemAccountPassword: "ossifrage",
403-
}));
404-
await server1.addSuperclusterLink({
405-
client: client2,
406-
clusterName: server2.clusterName,
407-
});
408-
await server2.addSuperclusterLink({
409-
client: client1,
410-
clusterName: server1.clusterName,
411-
});
412-
});
413-
414-
let sub1, sub1b;
415-
let recv1 = 0,
416-
recv1b = 0;
417-
const subject = "5077.org";
418-
it("make two subscriptions with the same sticky queue group", async () => {
419-
sub1 = await client1.sub(subject, { queue: STICKY_QUEUE_GROUP });
420-
(async () => {
421-
for await (const _ of sub1) {
422-
recv1++;
423-
}
424-
})();
425-
sub1b = await client1b.sub(subject, { queue: STICKY_QUEUE_GROUP });
426-
(async () => {
427-
for await (const _ of sub1b) {
428-
recv1b++;
429-
}
430-
})();
431-
});
432-
433-
let count = 50;
434-
it("send messages and note they all go to the same target -- first the easy sanity check all on the same node", async () => {
435-
await client1.waitForInterest(subject);
436-
for (let i = 0; i < count; i++) {
437-
await client1.publish(subject, "hi");
438-
}
439-
await wait({ until: () => recv1 + recv1b >= count });
440-
expect(recv1 + recv1b).toEqual(count);
441-
expect(recv1 * recv1b).toEqual(0);
442-
});
443-
444-
it("send messages and note they all go to the same target -- next the hard case across the cluster", async () => {
445-
await client2.waitForInterest(subject);
446-
for (let i = 0; i < count; i++) {
447-
await client2.publish(subject, "hi");
448-
}
449-
await wait({ until: () => recv1 + recv1b >= 2 * count });
450-
expect(recv1 + recv1b).toEqual(2 * count);
451-
expect(recv1 * recv1b).toEqual(0);
452-
});
453-
});
454-
455374
afterAll(after);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { initConatServer } from "@cocalc/backend/conat/test/setup";
2+
3+
let clusterName = 0;
4+
export async function createCluster(opts?) {
5+
clusterName += 1;
6+
const server = await initConatServer({
7+
clusterName: `${clusterName}`,
8+
id: "0",
9+
systemAccountPassword: "foo",
10+
...opts,
11+
});
12+
const client = server.client();
13+
return { server, client };
14+
}

0 commit comments

Comments
 (0)