Skip to content

Commit

Permalink
Flaky IndexingServiceTest.shouldDeliverUpdatesThatOccurDuringPopulati…
Browse files Browse the repository at this point in the history
…onToPopulator test fix
  • Loading branch information
MishaDemianenko committed Mar 8, 2018
1 parent 84ae7cf commit 2101e92
Showing 1 changed file with 17 additions and 6 deletions.
Expand Up @@ -112,7 +112,6 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.RETURNS_MOCKS;
Expand Down Expand Up @@ -143,7 +142,6 @@
import static org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode.TRIGGER_REBUILD_ALL;
import static org.neo4j.logging.AssertableLogProvider.inLog;
import static org.neo4j.register.Registers.newDoubleLongRegister;
import static org.neo4j.test.mockito.answer.AwaitAnswer.afterAwaiting;

public class IndexingServiceTest
{
Expand Down Expand Up @@ -230,8 +228,7 @@ public void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Ex
// given
when( populator.newPopulatingUpdater( storeView ) ).thenReturn( updater );

CountDownLatch latch = new CountDownLatch( 1 );
doAnswer( afterAwaiting( latch ) ).when( populator ).add( anyList() );
CountDownLatch populationLatch = new CountDownLatch( 1 );

Barrier.Control populationStartBarrier = new Barrier.Control();
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter()
Expand All @@ -241,6 +238,20 @@ public void indexPopulationScanStarting()
{
populationStartBarrier.reached();
}

@Override
public void indexPopulationScanComplete()
{
try
{
populationLatch.await();
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt();
throw new RuntimeException( "Index population monitor was interrupted", e );
}
}
};
IndexingService indexingService =
newIndexingServiceWithMockedDependencies( populator, accessor, withData( addNodeUpdate( 1, "value1" ) ), monitor );
Expand All @@ -261,10 +272,10 @@ public void indexPopulationScanStarting()
updater.process( value2 );
}

latch.countDown();
populationLatch.countDown();

waitForIndexesToComeOnline( indexingService, 0 );
verify( populator, timeout( 1000 ) ).close( true );
verify( populator ).close( true );

// then
assertEquals( InternalIndexState.ONLINE, proxy.getState() );
Expand Down

0 comments on commit 2101e92

Please sign in to comment.