@VisibleForTesting
  void configureCallbackInterval(Task task) {
    boolean isRunningForeachStep = false;
    boolean isMaestroTaskCreated = false;
    boolean isFirstPollingCycle =
        task != null && task.getPollCount() <= Constants.FIRST_POLLING_COUNT_LIMIT;
    if (task != null && task.getOutputData().containsKey(Constants.STEP_RUNTIME_SUMMARY_FIELD)) {
      StepRuntimeSummary runtimeSummary =
          StepHelper.retrieveRuntimeSummary(objectMapper, task.getOutputData());
      Long callbackInSecs = stepRuntimeCallbackDelayPolicy.getCallBackDelayInSecs(runtimeSummary);
      if (callbackInSecs != null) {
        LOG.trace(
            "Set customized callback [{}] in seconds for step [{}]",
            callbackInSecs,
            runtimeSummary.getIdentity());
        task.setCallbackAfterSeconds(callbackInSecs);
      }

      StepRuntimeState state = runtimeSummary.getRuntimeState();
      isRunningForeachStep =
          (runtimeSummary.getType() == StepType.FOREACH
              && state.getStatus() == StepInstance.Status.RUNNING);
      isMaestroTaskCreated = state.getStatus() == StepInstance.Status.CREATED;
      isFirstPollingCycle =
          isFirstPollingCycle
              && state.getCreateTime() != null
              && System.currentTimeMillis() - state.getCreateTime()
                  < Constants.FIRST_POLL_TIME_BUFFER_IN_MILLIS;
    }

    boolean isStartTaskStarted =
        task != null && Constants.DEFAULT_START_STEP_NAME.equals(task.getReferenceTaskName());
    // a workaround to reduce start boostrap delay for the first few polling calls
    if ((isRunningForeachStep || isMaestroTaskCreated || isStartTaskStarted)
        && isFirstPollingCycle) {
      LOG.debug(
          "Update callback to 0 for task uuid [{}] for the first few polling calls",
          task.getTaskId());
      task.setCallbackAfterSeconds(0);
    }
  }
@Test
  public void testConfigureCallBackForStartTaskWithFirstPolling() {
    // Start task with first polling will have 0-delay callback
    Task task = new Task();
    task.setReferenceTaskName(Constants.DEFAULT_START_STEP_NAME);
    task.setCallbackAfterSeconds(30L);
    task.setPollCount(Constants.FIRST_POLLING_COUNT_LIMIT);
    maestroWorkflowExecutor.configureCallbackInterval(task);
    verify(callbackPolicy, times(0)).getCallBackDelayInSecs(any());
    assertEquals(0L, task.getCallbackAfterSeconds());

    // if it is not start task
    task.setCallbackAfterSeconds(30L);
    task.setReferenceTaskName(Constants.DEFAULT_END_STEP_NAME);
    maestroWorkflowExecutor.configureCallbackInterval(task);
    verify(callbackPolicy, times(0)).getCallBackDelayInSecs(any());
    assertEquals(30L, task.getCallbackAfterSeconds());

    // if it polled too many times
    task.setPollCount(Constants.FIRST_POLLING_COUNT_LIMIT + 1);
    maestroWorkflowExecutor.configureCallbackInterval(task);
    verify(callbackPolicy, times(0)).getCallBackDelayInSecs(any());
    assertEquals(30L, task.getCallbackAfterSeconds());
  }