### Question:
PageCacheFlusher extends Thread { void halt() { halted = true; halt.await(); if ( error != null ) { throwIfUnchecked( error ); throw new RuntimeException( error ); } } PageCacheFlusher( PageCache pageCache ); @Override void run();  }### Answer:
@Test( timeout = 10_000 ) public void shouldWaitForCompletionInHalt() throws Exception { PageCache pageCache = mock( PageCache.class ); Barrier.Control barrier = new Barrier.Control(); doAnswer( invocation -> { barrier.reached(); return null; } ).when( pageCache ).flushAndForce(); PageCacheFlusher flusher = new PageCacheFlusher( pageCache ); flusher.start(); barrier.await(); Future<Object> halt = t2.execute( state -> { flusher.halt(); return null; } ); t2.get().waitUntilWaiting( details -> details.isAt( PageCacheFlusher.class, "halt" ) ); barrier.release(); halt.get(); }