mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 20:01:36 +00:00
test(matrix): stabilize file sync store persistence checks
This commit is contained in:
@@ -2,8 +2,8 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { ISyncResponse } from "matrix-js-sdk";
|
||||
import * as jsonFiles from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import * as runtimeApi from "../../runtime-api.js";
|
||||
import { FileBackedMatrixSyncStore } from "./file-sync-store.js";
|
||||
|
||||
function createSyncResponse(nextBatch: string): ISyncResponse {
|
||||
@@ -142,7 +142,7 @@ describe("FileBackedMatrixSyncStore", () => {
|
||||
it("coalesces background persistence until the debounce window elapses", async () => {
|
||||
vi.useFakeTimers();
|
||||
const storagePath = createStoragePath();
|
||||
const writeSpy = vi.spyOn(jsonFiles, "writeJsonAtomic").mockResolvedValue();
|
||||
const writeSpy = vi.spyOn(runtimeApi, "writeJsonFileAtomically").mockResolvedValue();
|
||||
|
||||
const store = new FileBackedMatrixSyncStore(storagePath);
|
||||
await store.setSyncData(createSyncResponse("s111"));
|
||||
@@ -155,6 +155,7 @@ describe("FileBackedMatrixSyncStore", () => {
|
||||
expect(writeSpy).not.toHaveBeenCalled();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
await Promise.resolve();
|
||||
expect(writeSpy).toHaveBeenCalledTimes(1);
|
||||
expect(writeSpy).toHaveBeenCalledWith(
|
||||
storagePath,
|
||||
@@ -166,8 +167,9 @@ describe("FileBackedMatrixSyncStore", () => {
|
||||
lazyLoadMembers: true,
|
||||
},
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
|
||||
await store.flush();
|
||||
});
|
||||
|
||||
it("waits for an in-flight persist when shutdown flush runs", async () => {
|
||||
@@ -175,7 +177,7 @@ describe("FileBackedMatrixSyncStore", () => {
|
||||
const storagePath = createStoragePath();
|
||||
const writeDeferred = createDeferred();
|
||||
const writeSpy = vi
|
||||
.spyOn(jsonFiles, "writeJsonAtomic")
|
||||
.spyOn(runtimeApi, "writeJsonFileAtomically")
|
||||
.mockImplementation(async () => writeDeferred.promise);
|
||||
|
||||
const store = new FileBackedMatrixSyncStore(storagePath);
|
||||
|
||||
Reference in New Issue
Block a user