Skip to content

Commit

Permalink
added AbortController support -- couple of failing tests but it's too…
Browse files Browse the repository at this point in the history
… late
  • Loading branch information
pvh committed Jan 4, 2025
1 parent 5fa277f commit 70ed5dc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/automerge-repo/test/Repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,50 @@ describe("Repo", () => {
})
})

describe("Repo.find() abort behavior", () => {
it("aborts immediately if signal is already aborted", async () => {
const repo = new Repo()
const controller = new AbortController()
controller.abort()

await expect(
repo.find(generateAutomergeUrl(), { signal: controller.signal })
).rejects.toThrow("Operation aborted")
})

it("can abort while waiting for ready state", async () => {
// Create a repo with no network adapters so document can't become ready
const repo = new Repo()
const handle = repo.create()
const url = handle.url

const controller = new AbortController()

// Start find and abort after a moment
const findPromise = repo.find(handle.url, { signal: controller.signal })
setTimeout(() => controller.abort(), 10)

await expect(findPromise).rejects.toThrow("Operation aborted")
})

it("returns handle immediately when skipReady is true, even with abort signal", async () => {
const repo = new Repo()
const controller = new AbortController()
const url = generateAutomergeUrl()

const handle = await repo.find(url, {
skipReady: true,
signal: controller.signal,
})

expect(handle).toBeDefined()

// Abort shouldn't affect the result since we skipped ready
controller.abort()
expect(handle.url).toBe(url)
})
})

const warn = console.warn
const NO_OP = () => {}

Expand Down

0 comments on commit 70ed5dc

Please sign in to comment.