(Object methodName2, Exchange exchange, Object... optionalArgs)
| 423 | } |
| 424 | |
| 425 | public java.util.concurrent.CompletableFuture<Object> testSafe(Object methodName2, Exchange exchange, Object... optionalArgs) |
| 426 | { |
| 427 | final Object methodName3 = methodName2; |
| 428 | return java.util.concurrent.CompletableFuture.supplyAsync(() -> { |
| 429 | Object methodName = methodName3; |
| 430 | // `testSafe` method does not throw an exception, instead mutes it. The reason we |
| 431 | // mute the thrown exceptions here is because we don't want to stop the whole |
| 432 | // tests queue if any single test-method fails. Instead, they are echoed with |
| 433 | // formatted message "[TEST_FAILURE] ..." and that output is then regex-matched by |
| 434 | // run-tests.js, so the exceptions are still printed out to console from there. |
| 435 | Object args = Helpers.getArg(optionalArgs, 0, new java.util.ArrayList<Object>(java.util.Arrays.asList())); |
| 436 | Object isPublic = Helpers.getArg(optionalArgs, 1, false); |
| 437 | Object maxRetries = 3; |
| 438 | Object argsStringified = exchange.json(args); // args.join() breaks when we provide a list of symbols or multidimensional array; "args.toString()" breaks bcz of "array to string conversion" |
| 439 | for (var i = 0; Helpers.isLessThan(i, maxRetries); i++) |
| 440 | { |
| 441 | try |
| 442 | { |
| 443 | (this.testMethod(methodName, exchange, args, isPublic)).join(); |
| 444 | return true; |
| 445 | } catch(Exception ex) |
| 446 | { |
| 447 | Object e = getRootException(ex); |
| 448 | Object isLoadMarkets = (Helpers.isEqual(methodName, "loadMarkets")); |
| 449 | Object isAuthError = (Helpers.isInstance(e, AuthenticationError.class)); |
| 450 | Object isNotSupported = (Helpers.isInstance(e, NotSupported.class)); |
| 451 | Object isOperationFailed = (Helpers.isInstance(e, OperationFailed.class)); // includes "DDoSProtection", "RateLimitExceeded", "RequestTimeout", "ExchangeNotAvailable", "OperationFailed", "InvalidNonce", ... |
| 452 | Object lastUrlMsg = ((Helpers.isTrue(this.wsTests))) ? "" : Helpers.add(Helpers.add(" (Last url: ", exchange.last_request_url), " )"); |
| 453 | if (Helpers.isTrue(isOperationFailed)) |
| 454 | { |
| 455 | // if last retry was gone with same `tempFailure` error, then let's eventually return false |
| 456 | if (Helpers.isTrue(Helpers.isEqual(i, Helpers.subtract(maxRetries, 1)))) |
| 457 | { |
| 458 | Object isOnMaintenance = (Helpers.isInstance(e, OnMaintenance.class)); |
| 459 | Object isExchangeNotAvailable = (Helpers.isInstance(e, ExchangeNotAvailable.class)); |
| 460 | Object shouldFail = null; |
| 461 | Object retSuccess = null; |
| 462 | if (Helpers.isTrue(isLoadMarkets)) |
| 463 | { |
| 464 | // if "loadMarkets" does not succeed, we must return "false" to caller method, to stop tests continual |
| 465 | retSuccess = false; |
| 466 | // we might not break exchange tests, if exchange is on maintenance at this moment |
| 467 | if (Helpers.isTrue(isOnMaintenance)) |
| 468 | { |
| 469 | shouldFail = false; |
| 470 | } else |
| 471 | { |
| 472 | shouldFail = true; |
| 473 | } |
| 474 | } else |
| 475 | { |
| 476 | // for any other method tests: |
| 477 | if (Helpers.isTrue(Helpers.isTrue(isExchangeNotAvailable) && !Helpers.isTrue(isOnMaintenance))) |
| 478 | { |
| 479 | // break exchange tests if "ExchangeNotAvailable" exception is thrown, but it's not maintenance |
| 480 | shouldFail = true; |
| 481 | retSuccess = false; |
| 482 | } else |
no test coverage detected