mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-07 18:02:30 +00:00
Resume held replication results on application readiness
Trigger queued result processing on Commonlib readiness while preserving explicit suspension. Cover both transitions with focused tests.
This commit is contained in:
@@ -3,7 +3,9 @@ import { createServiceContext } from "@vrtmrz/livesync-commonlib/context";
|
||||
import { VERSIONING_DOCID, type EntryDoc } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||
import { REMOTE_FEATURE_GENERATION } from "@vrtmrz/livesync-commonlib/replication";
|
||||
import { promiseWithResolvers } from "octagonal-wheels/promises";
|
||||
import { EVENT_APPLICATION_READY } from "@/common/events";
|
||||
import { useReplicationFeature } from "./index";
|
||||
import { ReplicateResultProcessor } from "./ReplicateResultProcessor";
|
||||
|
||||
type BooleanHandler = (showMessage: boolean) => Promise<boolean>;
|
||||
type ParseHandler = (documents: PouchDB.Core.ExistingDocument<EntryDoc>[]) => Promise<boolean>;
|
||||
@@ -95,6 +97,7 @@ function setup(options: SetupOptions = {}) {
|
||||
return {
|
||||
beforeReplicateHandlers,
|
||||
centralRemoteHandlers,
|
||||
context: services.context,
|
||||
createRemoteResource,
|
||||
dispose,
|
||||
get parseHandler() {
|
||||
@@ -168,6 +171,22 @@ describe("replication serviceFeature composition", () => {
|
||||
expect(createRemoteResource).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("continues held results when Commonlib establishes application readiness", () => {
|
||||
const continueHeldDocuments = vi
|
||||
.spyOn(ReplicateResultProcessor.prototype, "continueHeldDocuments")
|
||||
.mockImplementation(() => undefined);
|
||||
try {
|
||||
const { context } = setup();
|
||||
expect(continueHeldDocuments).not.toHaveBeenCalled();
|
||||
|
||||
context.events.emitEvent(EVENT_APPLICATION_READY);
|
||||
|
||||
expect(continueHeldDocuments).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
continueHeldDocuments.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("requests owner retirement without awaiting the transition from result application", async () => {
|
||||
const retirement = promiseWithResolvers<boolean>();
|
||||
const onCloseActiveReplication = vi.fn(() => retirement.promise);
|
||||
|
||||
Reference in New Issue
Block a user