Mailspring/packages/client-sync/spec/shared/interruptible-spec.es6
Halla Moore c11a7ff830 [client-sync] Interrupt long-running syncback tasks
Summary:
Interrupt retryable syncback tasks that are taking too long so that we can
return control to the sync loop. The sync loop will retry the task later.
This diff adds a `forceReject` param to `interrupt()` so that we can return
control immediately instead of waiting for the current operation to finish
(for instance, the syncback task could be stuck in an imap operation, and a
normal interrupt would still have to wait for that to finish before returning
control to the callee)

Part of T7978

Test Plan: specs

Reviewers: evan, spang, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D4269
2017-03-30 15:50:34 -07:00

21 lines
681 B
JavaScript

import Interruptible from '../../src/shared/interruptible'
describe("Interruptible", () => {
describe("when interrupted with forceReject", () => {
it("the run method rejects immediately", async () => {
function* neverResolves() {
yield new Promise(() => {})
}
const interruptible = new Interruptible()
const promise = interruptible.run(neverResolves)
interruptible.interrupt({forceReject: true})
try {
await promise;
} catch (err) {
expect(/interrupted/i.test(err.toString())).toEqual(true)
}
// The promse never resolves, so if it doesn't reject,
// this test will timeout.
})
})
})