@Test
public void testCleanupWorkflowInstances() throws Exception {

  WorkflowInstance wi1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
  startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
  // reload instances, because operations have no id before
  wi1 = service.getWorkflowById(wi1.getId());
  service.cleanupWorkflowInstances(0, WorkflowState.FAILED);
  assertEquals(2, service.getWorkflowInstances(new WorkflowQuery()).size());
  service.cleanupWorkflowInstances(0, WorkflowState.SUCCEEDED);
  assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
  for (WorkflowOperationInstance op : wi1.getOperations()) {
    assertEquals(0, serviceRegistry.getChildJobs(op.getId()).size());
  }
}