Skip to content

Commit

Permalink
add a pause because race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
pvh committed Aug 22, 2024
1 parent 5148e55 commit 41ea961
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/automerge-repo/src/DocHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ export class DocHandle<T> extends EventEmitter<DocHandleEvents<T>> {
* Creates a fixed "view" of an automerge document at the given point in time represented
* by the `heads` passed in. The return value is the same type as docSync() and will return
* undefined if the object hasn't finished loading.
* @returns
*
* @remarks
* Note that our Typescript types do not consider change over time and the current version
* of Automerge doesn't check types at runtime, so if you go back to an old set of heads
* that doesn't match the heads here, Typescript will not save you.
*
* @returns An Automerge.Doc<T> at the point in time.
*/
view(heads: A.Heads): A.Doc<T> | undefined {
if (!this.isReady()) {
Expand Down
6 changes: 3 additions & 3 deletions packages/automerge-repo/test/Repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,7 @@ describe("Repo", () => {
})

it("synchronizes changes from bobRepo to charlieRepo when loading from storage", async () => {
const { bobRepo, bobStorage, charlieRepo, aliceHandle, teardown } =
await setup()
const { bobRepo, bobStorage, teardown } = await setup()

// We create a repo that uses bobStorage to put a document into its imaginary disk
// without it knowing about it
Expand All @@ -846,7 +845,6 @@ describe("Repo", () => {
})
await bobRepo2.flush()

console.log("loading from disk", inStorageHandle.url)
// Now, let's load it on the original bob repo (which shares a "disk")
const bobFoundIt = bobRepo.find<TestDoc>(inStorageHandle.url)
await bobFoundIt.whenReady()
Expand All @@ -855,6 +853,8 @@ describe("Repo", () => {
// (This behaviour is mostly test-validation, we are already testing load/save elsewhere.)
assert.deepStrictEqual(await bobFoundIt.doc(), { foo: "foundOnFakeDisk" })

await pause(10)

// We should have a docSynchronizer and its peers should be alice and charlie
assert.strictEqual(
bobRepo.synchronizer.docSynchronizers[bobFoundIt.documentId]?.hasPeer(
Expand Down

0 comments on commit 41ea961

Please sign in to comment.