[TEST] Remove sleeps and latch timeouts from ClusterServiceTests

Tests relying on sleeps and latch timeouts are prone to weird timing issues
and hard to read / understand error messages. This commit moves towards a more
deterministic error model and replaces empty fails with real exceptions.
This commit is contained in:
Simon Willnauer 2015-06-22 09:51:51 +02:00
parent 2e762f078d
commit c7285d9d19
1 changed files with 18 additions and 4 deletions

View File

@ -74,14 +74,14 @@ public class ClusterServiceTests extends ElasticsearchIntegrationTest {
try {
block.await();
} catch (InterruptedException e) {
fail();
throw new RuntimeException(e);
}
return currentState;
}
@Override
public void onFailure(String source, Throwable t) {
fail();
throw new RuntimeException(t);
}
});
@ -109,9 +109,23 @@ public class ClusterServiceTests extends ElasticsearchIntegrationTest {
}
});
assertThat(timedOut.await(500, TimeUnit.MILLISECONDS), equalTo(true));
timedOut.await();
block.countDown();
Thread.sleep(100); // sleep a bit to double check that execute on the timed out update task is not called...
final CountDownLatch allProcessed = new CountDownLatch(1);
clusterService1.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {
@Override
public void onFailure(String source, Throwable t) {
throw new RuntimeException(t);
}
@Override
public ClusterState execute(ClusterState currentState) {
allProcessed.countDown();
return currentState;
}
});
allProcessed.await(); // executed another task to double check that execute on the timed out update task is not called...
assertThat(executeCalled.get(), equalTo(false));
}