Skip to content

Commit

Permalink
[Electric-Coin-Company#1179] Handle false positive getSubtreeRoots wh…
Browse files Browse the repository at this point in the history
…en connectivity is down

- 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

[Electric-Coin-Company#1179] Handle false positive getSubtreeRoots when connectivity is down

- unit test for the timeout getSubtreeRoot added

[Electric-Coin-Company#1179] Handle false positive getSubtreeRoots when connectivity is down (Electric-Coin-Company#1222)

- warning fixed
  • Loading branch information
LukasKorba committed Sep 7, 2023
1 parent 6e0fb85 commit aecb07f
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 aecb07f

Please sign in to comment.