Skip to content

Commit

Permalink
[#1179] Handle false positive getSubtreeRoots when connectivity is down
Browse files Browse the repository at this point in the history
- when getSubtreeRoots call fails on timeout, the connectivity is not present and the action must be terminated (throw) an error, this way when the connectivity is back, the State Machine starts over and getSubtreeRoots get a chance to properly decide if SBS is supported

[#1179] Handle false positive getSubtreeRoots when connectivity is down

- unit test for the timeout getSubtreeRoot added

[#1179] Handle false positive getSubtreeRoots when connectivity is down (#1222)

- warning fixed
  • Loading branch information
LukasKorba committed Aug 31, 2023
1 parent c49400d commit f1c61f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extension UpdateSubtreeRootsAction: Action {
for try await subtreeRoot in stream {
roots.append(subtreeRoot)
}
} catch ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut) {
throw ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut)
} catch {
logger.debug("getSubtreeRoots failed with error \(error.localizedDescription)")
err = error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ final class UpdateSubtreeRootsActionTests: ZcashTestCase {
}
}

func testUpdateSubtreeRootsAction_getSubtreeRootsTimeout() async throws {
let loggerMock = LoggerMock()

loggerMock.infoFileFunctionLineClosure = { _, _, _, _ in }

let tupple = setupAction(loggerMock)
let updateSubtreeRootsActionAction = tupple.action
tupple.serviceMock.getSubtreeRootsClosure = { _ in
AsyncThrowingStream { continuation in continuation.finish(throwing: ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut)) }
}

do {
let context = ActionContextMock.default()
context.updateSupportedSyncAlgorithmClosure = { _ in }

_ = try await updateSubtreeRootsActionAction.run(with: context) { _ in }
XCTFail("The test is expected to fail but continued.")
} catch ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut) {
// this is expected, the action must be terminated as there is no connectivity
} catch {
XCTFail(
"""
testUpdateSubtreeRootsAction_getSubtreeRootsTimeout is expected to fail with
ZcashError.serviceSubtreeRootsStreamFailed(LightWalletServiceError.timeOut)
but received \(error)".
"""
)
}
}

func testUpdateSubtreeRootsAction_getSubtreeRootsEmpty() async throws {
let loggerMock = LoggerMock()

Expand Down

0 comments on commit f1c61f8

Please sign in to comment.