Skip to content

Commit 3e0a443

Browse files
committed
update unit tests for new sticky routing -- basically delete the tests that involve internal implementation details in one file... since those are classic "bad unit tests"
1 parent 8a5aa40 commit 3e0a443

File tree

3 files changed

+4
-66
lines changed

3 files changed

+4
-66
lines changed

src/packages/backend/conat/test/cluster/cluster-sticky-state.test.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/*
21
import {
32
before,
43
after,
54
defaultCluster as servers,
65
waitForConsistentState,
7-
wait,
86
addNodeToDefaultCluster,
97
} from "@cocalc/backend/conat/test/setup";
108
import { STICKY_QUEUE_GROUP } from "@cocalc/conat/core/client";
@@ -47,9 +45,6 @@ describe("ensure sticky state sync and use is working properly", () => {
4745
);
4846
// publishing causes a choice to be made and saved on servers[0]
4947
await clients[0].publish(`subject.${i}.foo`, "hello");
50-
expect(servers[0].sticky[`subject.${i}.*`]).not.toBe(undefined);
51-
// but no choice on servers[1]
52-
expect(servers[1].sticky[`subject.${i}.*`]).toBe(undefined);
5348
}
5449
});
5550

@@ -66,51 +61,12 @@ describe("ensure sticky state sync and use is working properly", () => {
6661
chosen = await Promise.race([p0(), p1()]);
6762
});
6863

69-
it(`sticky on servers[0] should have ${count} entries starting in "subject".`, async () => {
70-
const v = Object.keys(servers[0].sticky).filter((s) =>
71-
s.startsWith("subject."),
72-
);
73-
expect(v.length).toBe(count);
74-
});
75-
76-
it(`sticky on servers[1] should have no entries starting in "subject".`, async () => {
77-
const v = Object.keys(servers[1].sticky).filter((s) =>
78-
s.startsWith("subject."),
79-
);
80-
expect(v.length).toBe(0);
81-
});
82-
83-
it(`servers[1]'s link to servers[0] should *eventually* have ${count} entries starting in "subject."`, async () => {
84-
// @ts-ignore
85-
const link = servers[1].clusterLinksByAddress[servers[0].address()];
86-
let v;
87-
await wait({
88-
until: () => {
89-
v = Object.keys(link.sticky).filter((s) => s.startsWith("subject."));
90-
return v.length == count;
91-
},
92-
});
93-
expect(v.length).toBe(count);
94-
});
95-
9664
it("send message from clients[1] to each subject", async () => {
9765
for (let i = 0; i < count; i++) {
9866
await clients[1].publish(`subject.${i}.foo`);
9967
}
10068
});
10169

102-
// Sometimes this fails under very heavy load.
103-
// It's not a good test, because it probably hits some timeouts sometimes, and
104-
// it is testing internal structure/optimizations, not behavior.
105-
// Note also that minimizing sticky state computation is just an optimization so even if this test were failing
106-
// due to a bug, it might just mean things are slightly slower.
107-
// it(`sticky on servers[1] should STILL have no entries starting in "subject", since no choices had to be made`, async () => {
108-
// const v = Object.keys(servers[1].sticky).filter((s) =>
109-
// s.startsWith("subject."),
110-
// );
111-
// expect(v.length).toBe(0);
112-
// });
113-
11470
async function deliveryTest() {
11571
const sub = chosen == 0 ? subs0[0] : subs1[0];
11672

@@ -155,17 +111,6 @@ describe("ensure sticky state sync and use is working properly", () => {
155111
await waitForConsistentState(servers);
156112
});
157113

158-
it("double check the links have the sticky state", () => {
159-
for (const server of servers.slice(1)) {
160-
// @ts-ignore
161-
const link = server.clusterLinksByAddress[servers[0].address()];
162-
const v = Object.keys(link.sticky).filter((s) =>
163-
s.startsWith("subject."),
164-
);
165-
expect(v.length).toBe(count);
166-
}
167-
});
168-
169114
it(
170115
"in bigger, cluster, publish from every node to subject.0.foo",
171116
deliveryTest,
@@ -181,15 +126,6 @@ describe("ensure sticky state sync and use is working properly", () => {
181126
}
182127
sub.close();
183128
});
184-
185-
it("unjoining servers[0] from servers[1] should transfer the sticky state to servers[1]", async () => {
186-
await servers[1].unjoin({ address: servers[0].address() });
187-
const v = Object.keys(servers[1].sticky).filter((s) =>
188-
s.startsWith("subject."),
189-
);
190-
expect(v.length).toBe(count);
191-
});
192129
});
193130

194131
afterAll(after);
195-
*/

src/packages/backend/conat/test/sync/open-files.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ to open so they can fulfill their backend responsibilities:
88
99
DEVELOPMENT:
1010
11-
pnpm test ./open-files.test.ts
11+
pnpm test `pwd`/open-files.test.ts
1212
1313
*/
1414

src/packages/conat/core/sticky.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type Client } from "./client";
44
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
55
import { getLogger } from "@cocalc/conat/client";
66

7-
const DEBUG = true;
7+
const DEBUG = !!process.env.COCALC_DEBUG_CONAT_SERVER_STICKY;
88

99
const logger = getLogger("conat:core:sticky");
1010

@@ -122,6 +122,8 @@ export async function createStickyRouter({
122122
targets,
123123
target,
124124
});
125+
} else {
126+
logger.debug("handle request", { counter, madeChoice });
125127
}
126128
await mesg.respond({ target, ttl: clientTtl });
127129
} catch (err) {

0 commit comments

Comments
 (0)