@Test
public void shouldCountDecoratedResourcesOnNonQueuedStates() {

  Workflow workflow = workflowUsingResources(WORKFLOW_ID1, "foo", "bar");
  when(resourceDecorator.decorateResources(
      any(RunState.class), any(WorkflowConfiguration.class), anySet()))
      .thenReturn(ImmutableSet.of("baz", "GLOBAL_STYX_CLUSTER"));
  when(config.globalConcurrency()).thenReturn(Optional.of(17L));
  setResourceLimit("baz", 3);
  initWorkflow(workflow);
  WorkflowInstance i0 = instance(WORKFLOW_ID1, "i0");
  WorkflowInstance i1 = instance(WORKFLOW_ID1, "i1");
  WorkflowInstance i2 = instance(WORKFLOW_ID1, "i2");
  WorkflowInstance i3 = instance(WORKFLOW_ID1, "i3");
  WorkflowInstance i4 = instance(WORKFLOW_ID1, "i4");
  populateActiveStates(
      RunState.create(i0, State.QUEUED, time.get()),
      RunState.create(i1, State.SUBMITTING, time.get()),
      RunState.create(i2, State.PREPARE, time.get()),
      RunState.create(i3, State.TERMINATED, time.get()),
      RunState.create(i4, State.QUEUED, time.get()));
  scheduler.tick();
  verify(resourceDecorator).decorateResources(eq(RunState.create(i0, State.QUEUED, time.get())),
      eq(workflow.configuration()),
      eq(Set.of("foo", "bar", "GLOBAL_STYX_CLUSTER")));
  verify(resourceDecorator).decorateResources(eq(RunState.create(i4, State.QUEUED, time.get())),
      eq(workflow.configuration()),
      eq(Set.of("foo", "bar", "GLOBAL_STYX_CLUSTER")));
  verify(stateManager, times(2)).receiveIgnoreClosed(argThat(
      either(is(Event.dequeue(i0, ImmutableSet.of("baz", "GLOBAL_STYX_CLUSTER"))))
          .or(is(Event.dequeue(i4, ImmutableSet.of("baz", "GLOBAL_STYX_CLUSTER"))))),
      anyLong());
}