Path: blob/master/src/packages/backend/conat/test/time.test.ts
1450 views
/*1DEVELOPMENT:23pnpm test ./time.test.ts4*/56import { timeClient, createTimeService } from "@cocalc/conat/service/time";7import time, { getSkew } from "@cocalc/conat/time";8import { before, after } from "@cocalc/backend/conat/test/setup";910beforeAll(before);1112describe("get time from conat", () => {13it("tries to get the time before the skew, so it is not initialized yet", () => {14expect(time).toThrow("clock skew not known");15});1617it("gets the skew, so that time is initialized", async () => {18const skew = await getSkew();19expect(Math.abs(skew)).toBeLessThan(1000);20});2122it("gets the time, which should be close to our time on a test system", () => {23// times in ms, so divide by 1000 so expecting to be within a second24expect(time() / 1000).toBeCloseTo(Date.now() / 1000, 0);25});2627it("time is a number", () => {28expect(typeof time()).toBe("number");29});30});3132describe("start the time server and client and test that it works", () => {33it("starts the time server and queries it", async () => {34createTimeService();35const client = timeClient();36const t = await client.time();37expect(Math.abs(Date.now() - t)).toBeLessThan(200);38});39});4041afterAll(after);424344