Skip to content

Commit b623c4d

Browse files
committed
fix a testing mistake regarding the path to persist server data
- this was a mistake in the unit tests that overwrite my dev data path...
1 parent 468bf4f commit b623c4d

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/packages/backend/conat/test/cluster/node-discovery.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
waitForConsistentState,
77
} from "@cocalc/backend/conat/test/setup";
88
import { createClusterNode } from "./util";
9+
import { isEqual } from "lodash";
910

1011
beforeAll(before);
1112

@@ -61,17 +62,32 @@ describe("test automatic node discovery (and forgetting)", () => {
6162
});
6263
});
6364

64-
const count = 5;
65+
// WORRY -- with count bigger, e.g., 5, sometimes this doesn't work.
66+
// It might be an indicator of an issue.
67+
const count = 3;
68+
it(`check state is consistent -- before adding more ${count} nodes`, async () => {
69+
await waitForConsistentState(nodes.map((x) => x.server));
70+
});
71+
6572
it(`add ${count} more nodes`, async () => {
6673
for (let i = 3; i < 3 + count; i++) {
6774
await create(`node${i}`);
6875
await nodes[i].server.join(nodes[i - 1].server.address());
6976
}
77+
});
78+
79+
it("wait until every node knows about every other node", async () => {
7080
const total = nodes.length;
81+
const all = new Set(nodes.map((x) => x.server.address()));
7182
await wait({
7283
until: () => {
7384
for (let i = 0; i < total; i++) {
74-
if (nodes[i].server.clusterAddresses(clusterName).length != total) {
85+
if (
86+
!isEqual(
87+
all,
88+
new Set(nodes[i].server.clusterAddresses(clusterName)),
89+
)
90+
) {
7591
return false;
7692
}
7793
}
@@ -80,7 +96,7 @@ describe("test automatic node discovery (and forgetting)", () => {
8096
});
8197
});
8298

83-
it("check state is consistent", async () => {
99+
it(`wait for cluster to have consistent state -- after adding ${count} nodes`, async () => {
84100
await waitForConsistentState(nodes.map((x) => x.server));
85101
});
86102

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function initConatServer(
3636
}
3737

3838
const server = createConatServer(options);
39-
if (false && server.state != "ready") {
39+
if (server.state != "ready") {
4040
await once(server, "ready");
4141
}
4242
return server;
@@ -126,11 +126,12 @@ export async function restartPersistServer() {
126126
export let client;
127127
export async function before() {
128128
tempDir = await mkdtemp(join(tmpdir(), "conat-test"));
129+
syncFiles.local = join(tempDir, "local");
130+
syncFiles.archive = join(tempDir, "archive");
131+
129132
server = await createServer();
130133
client = connect();
131134
persistServer = createPersistServer({ client });
132-
syncFiles.local = join(tempDir, "local");
133-
syncFiles.archive = join(tempDir, "archive");
134135
setConatClient({
135136
conat: connect,
136137
getLogger,
@@ -150,7 +151,7 @@ export function connect(opts?): Client {
150151
// other thinks it is.
151152
export async function waitForConsistentState(
152153
servers: ConatServer[],
153-
timeout = 20000,
154+
timeout = 10000,
154155
): Promise<void> {
155156
if (servers.length <= 1) {
156157
return;

0 commit comments

Comments
 (0)