Skip to content

Commit

Permalink
Modified multi threading testing more accurately test threading
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil buddharaju committed Jun 27, 2023
1 parent 1bae299 commit 32a7adf
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,46 @@ public void testSearchCoordinatorStatsMulti() throws InterruptedException {
int numTasks = randomIntBetween(5, 50);

Thread[] threads = new Thread[numTasks];
Phaser phaser = new Phaser(numTasks + 1);

Phaser phaser = new Phaser(numTasks);

CountDownLatch countDownLatch = new CountDownLatch(numTasks);
for (int i = 0; i < numTasks; i++) {
threads[i] = new Thread(() -> {
phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onDFSPreQueryPhaseStart(ctx);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onDFSPreQueryPhaseEnd(ctx, tookTime);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onCanMatchPhaseStart(ctx);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onCanMatchPhaseEnd(ctx, tookTime);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onQueryPhaseStart(ctx);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onQueryPhaseEnd(ctx, tookTime);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onFetchPhaseStart(ctx);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onFetchPhaseEnd(ctx, tookTime);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onExpandSearchPhaseStart(ctx);

phaser.arriveAndAwaitAdvance();
testCoordinatorStats.onExpandSearchPhaseEnd(ctx, tookTime);
countDownLatch.countDown();
});
threads[i].start();
}
phaser.arriveAndAwaitAdvance();

countDownLatch.await();

assertEquals(numTasks, testCoordinatorStats.getDFSPreQueryTotal());
Expand Down

0 comments on commit 32a7adf

Please sign in to comment.