@Test
public void testBackgroundExecutorSetsEnvironmentCorrectly()
        throws InterruptedException {

    InterProcessCommunication outgoing = new MessageQueue();
    ConcurrentMap<AccessToken, RemoteMethodResponse> responses = Maps
            .newConcurrentMap();
    String environment1 = Random.getSimpleString();
    String environment2 = Random.getSimpleString();
    MockConcourseRuntime runtime = new MockConcourseRuntime();
    BackgroundExecutor executor = PluginExecutors
            .newCachedBackgroundExecutor(outgoing, responses);
    CountDownLatch latch = new CountDownLatch(2);
    final AtomicBoolean passed = new AtomicBoolean(true);
    executor.execute(environment1, () -> {
        try {
            Assert.assertEquals(environment1, runtime.environment());
            latch.countDown();
        }
        catch (AssertionError e) {
            passed.set(false);
            e.printStackTrace();
        }
    });
    executor.execute(environment2, () -> {
        try {
            Assert.assertEquals(environment2, runtime.environment());
            latch.countDown();
        }
        catch (AssertionError e) {
            passed.set(false);
            e.printStackTrace();
        }
    });
    latch.await();
    Assert.assertTrue(passed.get());
}