Skip to content

Commit

Permalink
Unflake IndexingServiceTest
Browse files Browse the repository at this point in the history
There were Mockito.verify calls accepting timeouts, which on some machines would
run out before the condition was triggered. Solution here is to explicitly wait
for the condition before and just verify afterwards. Problem is that the way the
test is set up there's a race between the populator and verifier because an
IndexProxy is marked as failed (in flip) before actually calling
IndexPopulator#close(boolean), so the verify call still has a timeout, although
now the time between those two conditions should be microseconds.
  • Loading branch information
tinwelint committed Jun 30, 2017
1 parent e2c986c commit 3e28102
Showing 1 changed file with 14 additions and 4 deletions.
Expand Up @@ -653,9 +653,16 @@ public void closingOfValidatedUpdatesShouldCloseUpdaters() throws Exception

private void waitForIndexesToComeOnline( IndexingService indexing, long... indexRuleIds )
throws IndexNotFoundKernelException
{
waitForIndexesToGetIntoState( indexing, ONLINE, indexRuleIds );
}

private void waitForIndexesToGetIntoState( IndexingService indexing, InternalIndexState state,
long... indexRuleIds )
throws IndexNotFoundKernelException
{
long end = currentTimeMillis() + SECONDS.toMillis( 30 );
while ( !allOnline( indexing, indexRuleIds ) )
while ( !allInState( indexing, state, indexRuleIds ) )
{
if ( currentTimeMillis() > end )
{
Expand All @@ -664,11 +671,12 @@ private void waitForIndexesToComeOnline( IndexingService indexing, long... index
}
}

private boolean allOnline( IndexingService indexing, long[] indexRuleIds ) throws IndexNotFoundKernelException
private boolean allInState( IndexingService indexing, InternalIndexState state,
long[] indexRuleIds ) throws IndexNotFoundKernelException
{
for ( long indexRuleId : indexRuleIds )
{
if ( indexing.getIndexProxy( indexRuleId ).getState() != InternalIndexState.ONLINE )
if ( indexing.getIndexProxy( indexRuleId ).getState() != state )
{
return false;
}
Expand Down Expand Up @@ -698,7 +706,7 @@ public void recoveredUpdatesShouldBeApplied() throws Exception
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter()
{

private Set<IndexEntryUpdate<LabelSchemaDescriptor>> updates = new HashSet<>();
private final Set<IndexEntryUpdate<LabelSchemaDescriptor>> updates = new HashSet<>();

@Override
public void applyingRecoveredData( PrimitiveLongSet recoveredNodeIds )
Expand Down Expand Up @@ -898,6 +906,7 @@ public void shouldStoreIndexFailureWhenFailingToCreateOnlineAccessorAfterPopulat

// when
indexing.createIndexes( IndexRule.indexRule( indexId, index, PROVIDER_DESCRIPTOR ) );
waitForIndexesToGetIntoState( indexing, InternalIndexState.FAILED, indexId );
verify( populator, timeout( 1000 ).times( 2 ) ).close( closeArgs.capture() );

// then
Expand Down Expand Up @@ -933,6 +942,7 @@ public void shouldStoreIndexFailureWhenFailingToCreateOnlineAccessorAfterRecover
ArgumentCaptor<Boolean> closeArgs = ArgumentCaptor.forClass( Boolean.class );

// when
waitForIndexesToGetIntoState( indexing, InternalIndexState.FAILED, indexId );
verify( populator, timeout( 1000 ).times( 2 ) ).close( closeArgs.capture() );

// then
Expand Down

0 comments on commit 3e28102

Please sign in to comment.