Skip to content

Commit cfc00c4

Browse files
committed
fix: Fix interrupt tests with NextcloudBookmarks
Signed-off-by: Marcel Klehr <[email protected]>
1 parent fa70aa3 commit cfc00c4

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/lib/adapters/NextcloudBookmarks.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
6767
private bookmarkLock: AsyncLock
6868
private list: Bookmark<typeof ItemLocation.SERVER>[]
6969
private tree: Folder<typeof ItemLocation.SERVER>
70-
private abortController: AbortController
71-
private abortSignal: AbortSignal
7270
private canceled = false
7371
private cancelCallback: () => void = null
7472
private lockingInterval: any
@@ -85,8 +83,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
8583
this.server = server
8684
this.fetchQueue = new PQueue({ concurrency: 12 })
8785
this.bookmarkLock = new AsyncLock()
88-
this.abortController = new AbortController()
89-
this.abortSignal = this.abortController.signal
9086
}
9187

9288
static getDefaultValues(): NextcloudBookmarksConfig {
@@ -158,9 +154,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
158154
this.capabilities = await this.getNextcloudCapabilities()
159155
await this.checkFeatureJavascriptLinks()
160156

161-
this.abortController = new AbortController()
162-
this.abortSignal = this.abortController.signal
163-
164157
if (this.lockingInterval) {
165158
clearInterval(this.lockingInterval)
166159
}
@@ -172,7 +165,12 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
172165
} else if (!this.locked) {
173166
throw new ResourceLockedError()
174167
}
175-
this.lockingInterval = setInterval(() => !this.ended && this.acquireLock(), LOCK_INTERVAL)
168+
this.lockingInterval = setInterval(() => {
169+
if (!this.ended) {
170+
this.acquireLock()
171+
.catch(() => { /* pass */ })
172+
}
173+
}, LOCK_INTERVAL)
176174
}
177175

178176
async onSyncComplete(): Promise<void> {
@@ -190,7 +188,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
190188
cancel() {
191189
this.canceled = true
192190
this.fetchQueue.clear()
193-
this.abortController.abort()
194191
this.cancelCallback && this.cancelCallback()
195192
}
196193

@@ -851,6 +848,9 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
851848
? 'Basic ' + Base64.encode(this.server.username + ':' + this.server.password)
852849
: 'Bearer ' + this.ticket
853850

851+
const abortController = new AbortController()
852+
const abortSignal = abortController.signal
853+
854854
try {
855855
res = await this.fetchQueue.add(() => {
856856
Logger.log(`FETCHING ${verb} ${url}`)
@@ -863,13 +863,14 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
863863
Authorization: authString,
864864
...headers
865865
},
866-
signal: this.abortSignal,
866+
signal: abortSignal,
867867
...(body && !['get', 'head'].includes(verb.toLowerCase()) && { body }),
868868
}),
869869
new Promise((resolve, reject) =>
870870
setTimeout(() => {
871871
timedOut = true
872872
reject(new RequestTimeoutError())
873+
abortController.abort()
873874
}, TIMEOUT)
874875
),
875876
])

src/test/test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,14 +6909,19 @@ describe('Floccus', function() {
69096909
describe(`${stringifyAccountData(ACCOUNT_DATA)} benchmark ${ACCOUNT_DATA.serverRoot ? 'subfolder' : 'root'}`, function() {
69106910
context('with two clients', function() {
69116911
this.timeout(120 * 60000) // timeout after 2h
6912+
const BENCHMARK_SIZE = 1000
69126913
let account1, account2, RUN_INTERRUPTS = false
69136914
let timeouts = []
69146915
let i = 0
69156916
let timer = null
69166917
const setInterrupt = () => {
69176918
if (!timeouts.length) {
69186919
timeouts = new Array(1000).fill(0).map((_, index) =>
6919-
ACCOUNT_DATA.type === 'nextcloud-bookmarks' ? random.int(50000, 150000) : random.int(200, Math.round(4000 + (20000 - 4000) * (index % 20) / 20))
6920+
ACCOUNT_DATA.type === 'nextcloud-bookmarks'
6921+
// Produce random numbers of timeouts between 30s and increasing numbers between 30s and 180s (increasing for streches of 20, then going back to 30s)
6922+
? random.int(30000, Math.round(30000 + (180000 - 30000) * (index % 20) / 20))
6923+
// Produce random numbers of timeouts between 4s and increasing numbers between 4s and 20s (increasing for streches of 20, then going back to 4s)
6924+
: random.int(200, Math.round(4000 + (20000 - 4000) * (index % 20) / 20))
69206925
)
69216926
}
69226927
const timeout = timeouts[(i++) % 1000]
@@ -7060,7 +7065,7 @@ describe('Floccus', function() {
70607065
}
70617066
}
70627067

7063-
await createTree(localRoot, 0, 1000)
7068+
await createTree(localRoot, 0, BENCHMARK_SIZE)
70647069

70657070
const tree1Initial = await account1.localTree.getBookmarksTree(true)
70667071
await account1.sync()
@@ -7211,7 +7216,7 @@ describe('Floccus', function() {
72117216
}
72127217
}
72137218

7214-
await createTree(localRoot, 0, 1000)
7219+
await createTree(localRoot, 0, BENCHMARK_SIZE)
72157220

72167221
let tree1Initial = await account1.localTree.getBookmarksTree(true)
72177222
await account1.sync()
@@ -7442,7 +7447,7 @@ describe('Floccus', function() {
74427447
}
74437448
}
74447449

7445-
await createTree(localRoot, 0, 1000)
7450+
await createTree(localRoot, 0, BENCHMARK_SIZE)
74467451

74477452
let tree1Initial = await account1.localTree.getBookmarksTree(true)
74487453
await account1.sync()
@@ -7684,7 +7689,7 @@ describe('Floccus', function() {
76847689
}
76857690
}
76867691

7687-
await createTree(localRoot, 0, 1000)
7692+
await createTree(localRoot, 0, BENCHMARK_SIZE)
76887693

76897694
let tree1Initial = await account1.localTree.getBookmarksTree(true)
76907695
await account1.sync()
@@ -7922,7 +7927,7 @@ describe('Floccus', function() {
79227927
}
79237928
}
79247929

7925-
await createTree(localRoot, 0, 1000)
7930+
await createTree(localRoot, 0, BENCHMARK_SIZE)
79267931

79277932
let tree1Initial = await account1.localTree.getBookmarksTree(true)
79287933
await syncAccountWithInterrupts(account1)
@@ -8179,7 +8184,7 @@ describe('Floccus', function() {
81798184
}
81808185
}
81818186

8182-
await createTree(localRoot, 0, 1000)
8187+
await createTree(localRoot, 0, BENCHMARK_SIZE)
81838188

81848189
let tree1Initial = await account1.localTree.getBookmarksTree(true)
81858190
await account1.sync()
@@ -8423,7 +8428,7 @@ describe('Floccus', function() {
84238428
}
84248429
}
84258430

8426-
await createTree(localRoot, 0, 1000)
8431+
await createTree(localRoot, 0, BENCHMARK_SIZE)
84278432

84288433
let tree1Initial = await account1.localTree.getBookmarksTree(true)
84298434
await account1.sync()

0 commit comments

Comments
 (0)