Skip to content

Commit

Permalink
fix: unit tests not passing due to expecting precheck status exceptio…
Browse files Browse the repository at this point in the history
…n instead of runtime exceptions

Signed-off-by: Daniel Akhterov <[email protected]>
  • Loading branch information
janaakhterov committed Jan 18, 2022
1 parent 03a54d9 commit 454af28
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ public O execute(Client client, Duration timeout) throws TimeoutException, Prech

// If we get an unhealthy node here, we've cycled through all the "good" nodes that have failed
// and have no choice but to try a bad one.
if (!node.isHealthy())
if (!node.isHealthy()) {
delay(node.getRemainingTimeForBackoff());
}

if (node.channelFailedToConnect()) {
logger.trace("Failed to connect channel for node {} for request #{}", node.getAccountId(), attempt);
Expand All @@ -234,7 +235,7 @@ public O execute(Client client, Duration timeout) throws TimeoutException, Prech
if(grpcRequest.shouldRetryExceptionally(lastException)) {
continue;
} else {
throw grpcRequest.mapStatusException();
throw new RuntimeException(lastException);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ com.hedera.hashgraph.sdk.AccountInfoTest.toProtobuf=[
"ownedNfts_": 0,
"maxAutomaticTokenAssociations_": 0,
"alias_": {
"hash": 0,
"hash": 1,
"bytes": "",
"validUtf8": true,
"empty": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void executeRetriableErrorDuringCall() {
throw new StatusRuntimeException(io.grpc.Status.ABORTED);
};

assertThrows(PrecheckStatusException.class, () -> tx.execute(client));
assertThrows(RuntimeException.class, () -> tx.execute(client));

verify(node3).channelFailedToConnect();
verify(node4).channelFailedToConnect();
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/test/java/com/hedera/hashgraph/sdk/Mocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public class Mocker implements AutoCloseable {
var responseIndex = index.getAndIncrement();

if (responseIndex >= response.size()) {
System.out.println("AAAAAAAAA");
responseObserver.onError(Status.Code.ABORTED.toStatus().asRuntimeException());
return;
}

var r = response.get(responseIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void exitOnAborted() throws PrecheckStatusException, TimeoutException, Interrupt
var responses = List.of(responses1);

try (var mocker = Mocker.withResponses(responses)) {
Assertions.assertThrows(StatusRuntimeException.class, () -> new AccountBalanceQuery().setAccountId(new AccountId(10)).execute(mocker.client));
Assertions.assertThrows(RuntimeException.class, () -> new AccountBalanceQuery().setAccountId(new AccountId(10)).execute(mocker.client));
}
}

Expand Down

0 comments on commit 454af28

Please sign in to comment.