/** @return reschedule time duration in milliseconds */
  public long executeReturnRescheduleDurationMilliseconds() {

    // TODO - is the following assertion something that should be re-activated?
    // SKLogger.sAssert(getClass(), (accumulatedTestBytes == 0L));

    TestExecutor scheduledTestExecutor = new TestExecutor(tc);
    long time = System.currentTimeMillis();

    // The events in the queue are run through, until all are processed.
    // So, we must start by clearing-out all tests that pre-date the current time.
    while (true) {
      QueueEntry entry = entries.peek();
      if (entry != null && !canExecute(entry, time) && entry.getSystemTimeMilliseconds() < time) {
        entries.remove();
        SKLogger.d(this, "removing test scheduled at: " + entry.getSystemTimeAsDebugString());
      } else {
        break;
      }
    }

    boolean result = true;
    boolean fail = false;
    if (canExecute(time)) {
      scheduledTestExecutor.start();

      while (canExecute(time)) {
        QueueEntry entry = entries.remove();
        long maximumTestUsage = tc.config == null ? 0 : tc.config.maximumTestUsage;
        // if data cap is going to be breached do not run test
        // the datacap condition is successful if the datacap is not reached

        boolean dataCapLikelyToBeReachedFlag =
            SK2AppSettings.getSK2AppSettingsInstance().isDataCapLikelyToBeReached(maximumTestUsage);
        // If we're not going to reach the limit, then success is true.
        // If we're going to reach the limit, then success is false.
        boolean dataCapSuccessFlag = !dataCapLikelyToBeReachedFlag;
        DatacapCondition dc = new DatacapCondition(dataCapSuccessFlag);

        if (dc.isSuccess()) {
          ConditionGroupResult tr = scheduledTestExecutor.executeBackgroundTestGroup(entry.groupId);
          accumulatedTestBytes += scheduledTestExecutor.getAccumulatedTestBytes();
          result = tr.isSuccess;
        } else {
          SKLogger.d(this, "Active metrics won't be collected due to potential datacap breach");
          scheduledTestExecutor
              .getResultsContainer()
              .addFailedCondition(DatacapCondition.JSON_DATACAP);
        }
        scheduledTestExecutor.getResultsContainer().addCondition(dc.getCondition());
      }

      scheduledTestExecutor.stop();
      scheduledTestExecutor.save("scheduled_tests", -1);
    }

    extendSize();

    if (fail) {
      RetryFailAction failAction = tc.config.retryFailAction;
      if (failAction != null) {
        return tc.config.retryFailAction.delay; // reschedule
      } else {
        SKLogger.e(this, "can't find on test fail action, just skipping the test.");
        entries.remove();
      }
    }

    return getSleepTimeDurationMilliseconds();
  }