@Test
public void testImmediateJobFailure() {

  DyneinJobSpec jobSpec =
      DyneinJobSpec.builder()
          .name("AddJob")
          .queueName("test-error")
          .schedulePolicy(
              JobSchedulePolicy.builder().type(JobScheduleType.IMMEDIATE).delayMillis(0L).build())
          .build();
  CompletableFuture<Void> error = new CompletableFuture<>();
  error.completeExceptionally(new Exception());
  when(asyncClient.add(jobSpecTransformer.serializeJobSpec(jobSpec), "test-error"))
      .thenReturn(error);
  CompletableFuture<Void> ret = scheduler.createJob(jobSpec);
  verify(asyncClient).add(jobSpecTransformer.serializeJobSpec(jobSpec), "test-error");
  try {
    ret.get(1000, TimeUnit.MILLISECONDS);
  } catch (TimeoutException timeout) {
    fail(
        "Future does not seem to complete when failure in adding to destination queue (IMMEDIATE).");
  } catch (Exception ex) {
  }
}