Skip to content

Commit e0eeb09

Browse files
committed
conat: basic service test
1 parent 1c3394f commit e0eeb09

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
33
DEVELOPMENT:
44
5-
pnpm test --forceExit service.test.ts
5+
pnpm test ./service.test.ts
66
77
*/
88

99
import { callNatsService, createNatsService } from "@cocalc/conat/service";
1010
import { once } from "@cocalc/util/async-utils";
11-
import "@cocalc/backend/conat";
11+
import { before, after } from "@cocalc/backend/conat/test/setup";
12+
import { wait } from "@cocalc/backend/conat/test/util";
13+
14+
beforeAll(before);
1215

1316
describe("create a service and test it out", () => {
1417
let s;
@@ -23,16 +26,34 @@ describe("create a service and test it out", () => {
2326
);
2427
});
2528

26-
it("closes the services", async () => {
29+
it("closes the services and observes it doesn't work anymore", async () => {
2730
s.close();
2831

2932
let t = "";
30-
// expect( ...).toThrow doesn't seem to work with this:
31-
try {
33+
await expect(async () => {
3234
await callNatsService({ service: "echo", mesg: "hi", timeout: 1000 });
33-
} catch (err) {
34-
t = `${err}`;
35-
}
36-
expect(t).toContain("Error: timeout");
35+
}).rejects.toThrowError("timeout");
36+
});
37+
});
38+
39+
describe("verify that you can create a service AFTER calling it and things to still work fine", () => {
40+
let result = "";
41+
it("call a service that does not exist yet", () => {
42+
(async () => {
43+
result = await callNatsService({ service: "echo3", mesg: "hello " });
44+
})();
45+
});
46+
47+
it("create the echo3 service and observe that it answer the request we made before the service was created", async () => {
48+
const s = createNatsService({
49+
service: "echo3",
50+
handler: (mesg) => mesg.repeat(3),
51+
});
52+
await wait({ until: () => result });
53+
expect(result).toBe("hello hello hello ");
54+
55+
s.close();
3756
});
3857
});
58+
59+
afterAll(after);

0 commit comments

Comments
 (0)