From 6f6bceae9fc9217bcbcbed382b644b5b214d40e9 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 1 Apr 2024 19:36:51 +0200 Subject: [PATCH] fix: resolve module import deadlock Signed-off-by: Marcel Klehr --- src/lib/Account.ts | 2 +- src/lib/strategies/Default.ts | 8 +++++--- src/lib/strategies/Merge.ts | 8 ++++---- test/selenium-runner.js | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/Account.ts b/src/lib/Account.ts index dc945c6c48..8be0a0d806 100644 --- a/src/lib/Account.ts +++ b/src/lib/Account.ts @@ -237,7 +237,7 @@ export default class Account { } else { // if there is a pending continuation, we resume it - this.syncProcess = DefaultSyncProcess.fromJSON( + this.syncProcess = await DefaultSyncProcess.fromJSON( mappings, localResource, this.server, diff --git a/src/lib/strategies/Default.ts b/src/lib/strategies/Default.ts index 1798903149..71f0454ce3 100644 --- a/src/lib/strategies/Default.ts +++ b/src/lib/strategies/Default.ts @@ -10,8 +10,6 @@ import { TAdapter } from '../interfaces/Adapter' import { FailsafeError, InterruptedSyncError } from '../../errors/Error' import NextcloudBookmarksAdapter from '../adapters/NextcloudBookmarks' -import MergeSyncProcess from './Merge' -import UnidirectionalSyncProcess from './Unidirectional' export default class SyncProcess { protected mappings: Mappings @@ -979,20 +977,24 @@ export default class SyncProcess { } } - static fromJSON(mappings:Mappings, + static async fromJSON(mappings:Mappings, localTree:TLocalTree, server:TAdapter, progressCb:(progress:number)=>void, json: any) { let strategy: SyncProcess + let MergeSyncProcess: typeof SyncProcess + let UnidirectionalSyncProcess: typeof SyncProcess switch (json.strategy) { case 'default': strategy = new SyncProcess(mappings, localTree, server, progressCb) break case 'merge': + MergeSyncProcess = (await import('./Merge')).default strategy = new MergeSyncProcess(mappings, localTree, server, progressCb) break case 'unidirectional': + UnidirectionalSyncProcess = (await import('./Unidirectional')).default strategy = new UnidirectionalSyncProcess(mappings, localTree, server, progressCb) } strategy.setProgress(json) diff --git a/src/lib/strategies/Merge.ts b/src/lib/strategies/Merge.ts index f93be68094..5a5a9571df 100644 --- a/src/lib/strategies/Merge.ts +++ b/src/lib/strategies/Merge.ts @@ -2,11 +2,11 @@ import { ItemLocation, TItemLocation } from '../Tree' import Diff, { Action, ActionType, CreateAction, MoveAction } from '../Diff' import Scanner from '../Scanner' import * as Parallel from 'async-parallel' -import Default from './Default' +import DefaultSyncProcess, { ISerializedSyncProcess } from './Default' import Mappings, { MappingSnapshot } from '../Mappings' import Logger from '../Logger' -export default class MergeSyncProcess extends Default { +export default class MergeSyncProcess extends DefaultSyncProcess { async getDiffs():Promise<{localDiff:Diff, serverDiff:Diff}> { // If there's no cache, diff the two trees directly const newMappings = [] @@ -168,9 +168,9 @@ export default class MergeSyncProcess extends Default { Logger.log('Merge strategy: Load complete tree from server') this.serverTreeRoot = await this.server.getBookmarksTree(true) } - toJSON() { + toJSON(): ISerializedSyncProcess { return { - ...Default.prototype.toJSON.apply(this), + ...DefaultSyncProcess.prototype.toJSON.apply(this), strategy: 'merge' } } diff --git a/test/selenium-runner.js b/test/selenium-runner.js index ba170fd724..3b0ea7724e 100644 --- a/test/selenium-runner.js +++ b/test/selenium-runner.js @@ -92,6 +92,7 @@ installConsoleHandler() } await driver.get(testUrl) + console.log('Opened test page') let logs = [], fin