@Test
  public void shouldConsumeAllBuildCausesInServerHealth() throws Exception {
    pipelineScheduleQueue.schedule(
        "mingle", BuildCause.createManualForced(modifyOneFile(mingleConfig), Username.ANONYMOUS));
    pipelineScheduleQueue.schedule(
        "evolve", BuildCause.createManualForced(modifyOneFile(evolveConfig), Username.ANONYMOUS));

    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    assertThat(pipelineScheduleQueue.toBeScheduled().size(), is(0));
  }
  @Test
  public void shouldRemoveBuildCauseIfPipelineNotExist() throws Exception {
    configHelper.addPipeline("cruise", "dev", repository);
    goConfigService.forceNotifyListeners();
    scheduleHelper.autoSchedulePipelinesWithRealMaterials("mingle", "evolve", "cruise");

    Assertions.assertWillHappen(
        2,
        PipelineScheduleQueueMatcher.numberOfScheduledPipelinesIsAtLeast(pipelineScheduleQueue),
        Timeout.FIVE_SECONDS);
    int originalSize = pipelineScheduleQueue.toBeScheduled().size();
    assertThat(originalSize, greaterThan(1));
    configHelper.initializeConfigFile();
    goConfigService.forceNotifyListeners();

    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    assertThat(pipelineScheduleQueue.toBeScheduled().size(), is(0));
  }
 @After
 public void teardown() throws Exception {
   if (pipelineWithTwoStages != null) {
     pipelineWithTwoStages.onTearDown();
   }
   dbHelper.onTearDown();
   pipelineScheduleQueue.clear();
   testRepo.tearDown();
   FileUtil.deleteFolder(new File("pipelines"));
   configHelper.onTearDown();
 }
  @Test
  public void shouldRemoveBuildCauseIfAnyExceptionIsThrown() throws Exception {
    configHelper.addPipeline("cruise", "dev", repository);
    goConfigService.forceNotifyListeners();
    goConfigService
        .getCurrentConfig()
        .pipelineConfigByName(new CaseInsensitiveString("cruise"))
        .get(0)
        .jobConfigByConfigName(new CaseInsensitiveString("unit"))
        .setRunOnAllAgents(true);
    scheduleHelper.autoSchedulePipelinesWithRealMaterials("cruise");

    goConfigService.forceNotifyListeners();

    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    assertThat(pipelineScheduleQueue.toBeScheduled().size(), is(0));
  }