Skip to content

Commit

Permalink
illustrating hang in repo.find
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed May 13, 2024
1 parent 7a48691 commit f87b8de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,4 @@ final class RepoWebsocketIntegrationTests: XCTestCase {
XCTAssertEqual(foundDocHandle.id, handle.id)
XCTAssertTrue(RepoHelpers.equalContents(doc1: foundDocHandle.doc, doc2: handle.doc))
}

func testFindWithRandomId() async throws {
let repo = Repo(sharePolicy: SharePolicy.agreeable)
let websocket = WebSocketProvider(.init(reconnectOnError: false, loggingAt: .tracing))
await repo.addNetworkAdapter(adapter: websocket)

let url = try XCTUnwrap(URL(string: syncDestination))
try await websocket.connect(to: url)

let randomId = DocumentId()
do {
let _ = try await repo.find(id: randomId)
XCTFail("Repo shouldn't return a new, empty document for a random Document ID")
} catch let error as Errors.Unavailable {
XCTAssertEqual(error.id, randomId)
} catch {
XCTFail("Unknown error returned")
}
}
}
23 changes: 23 additions & 0 deletions Tests/AutomergeRepoTests/RepoFindTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Automerge
@testable import AutomergeRepo
import AutomergeUtilities
import XCTest

final class RepoFindTest: XCTestCase {
func testRepoFindWithoutNetworkingActive() async throws {
let repo = Repo(sharePolicy: SharePolicy.agreeable)
let websocket = WebSocketProvider(.init(reconnectOnError: false, loggingAt: .tracing))
await repo.addNetworkAdapter(adapter: websocket)

let unavailableExpectation = expectation(description: "find should throw an Unavailable error")
Task {
do {
let handle = try await repo.find(id: DocumentId()) // never completes, never errors
print(handle)
} catch {
unavailableExpectation.fulfill()
}
}
await fulfillment(of: [unavailableExpectation], timeout: 5)
}
}

0 comments on commit f87b8de

Please sign in to comment.