MCPcopy Index your code
hub / github.com/ccxt/ccxt / testSafe

Method testSafe

java/tests/src/main/java/tests/exchange/TestMain.java:425–537  ·  view source on GitHub ↗
(Object methodName2, Exchange exchange, Object... optionalArgs)

Source from the content-addressed store, hash-verified

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

Callers 2

runTestsMethod · 0.95
loadExchangeMethod · 0.95

Calls 14

getArgMethod · 0.95
isLessThanMethod · 0.95
testMethodMethod · 0.95
isEqualMethod · 0.95
isInstanceMethod · 0.95
isTrueMethod · 0.95
addMethod · 0.95
subtractMethod · 0.95
multiplyMethod · 0.95
getRootExceptionMethod · 0.80
jsonMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected