Skip to content

Commit

Permalink
Improve flaky test QueryBackPressureTest to throw an exception faster…
Browse files Browse the repository at this point in the history
… on unexpected behaviour

Signed-off-by: Oleksandr Porunov <[email protected]>
  • Loading branch information
porunov committed Jul 10, 2024
1 parent 0154bf9 commit 1efb00a
Showing 1 changed file with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
package org.janusgraph.diskstorage.util.backpressure;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.util.concurrent.CountDownLatch;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static org.janusgraph.util.system.ExecuteUtil.gracefulExecutorServiceShutdown;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@Timeout(60000)
public class QueryBackPressureTest {

@Test
Expand All @@ -38,7 +45,7 @@ public void testNoExtraPermitsAreAddedWithSemaphoreProtectedReleaseQueryBackPres
for(int i=0;i<10;i++){
semaphore.releaseAfterQuery();
}
while (semaphore.availablePermits() != 5){
while (semaphore.availablePermits() < 5){
Thread.sleep(10);
}

Expand All @@ -62,7 +69,7 @@ public void testExtraPermitsAreAddedWithSemaphoreQueryBackPressure() throws Inte
for(int i=0;i<10;i++){
semaphore.releaseAfterQuery();
}
while (semaphore.availablePermits() != 10){
while (semaphore.availablePermits() < 10){
Thread.sleep(10);
}

Expand Down Expand Up @@ -99,25 +106,35 @@ private void testSemaphoreBasedQueryBackPressureInMultipleThreads(int backPressu
}
assertEquals(0, availablePermits(backPressure));

CountDownLatch acquiresCountDownLatch = new CountDownLatch(acquiresThreads);
List<Future<Boolean>> aquireFutureList = new ArrayList<>(acquiresThreads);
for(int i=0;i<acquiresThreads;i++){
acquireExecutorService.execute(() -> {
aquireFutureList.add(acquireExecutorService.submit(() -> {
backPressure.acquireBeforeQuery();
acquiresCountDownLatch.countDown();
});
return true;
}));
}
// Sleep for 2 seconds and check that no acquires are happened due to `backPressure` being exhausted
Thread.sleep(2000);
assertEquals(acquiresThreads, acquiresCountDownLatch.getCount());
aquireFutureList.forEach(booleanFuture -> assertFalse(booleanFuture.isDone()));

List<Future<Boolean>> releaseFutureList = new ArrayList<>(acquiresThreads);
for(int i=0;i<acquiresThreads;i++){
releaseExecutorService.execute(backPressure::releaseAfterQuery);
releaseFutureList.add(releaseExecutorService.submit(() -> {
backPressure.releaseAfterQuery();
return true;
}));
}

acquiresCountDownLatch.await();
releaseFutureList.forEach(booleanFuture -> {
try {
booleanFuture.get();
} catch (InterruptedException | ExecutionException e) {
fail("Couldn't release semaphore", e);
}
});

gracefulExecutorServiceShutdown(acquireExecutorService, Long.MAX_VALUE);
gracefulExecutorServiceShutdown(releaseExecutorService, Long.MAX_VALUE);
gracefulExecutorServiceShutdown(acquireExecutorService, 10000);
gracefulExecutorServiceShutdown(releaseExecutorService, 10000);

assertEquals(0, availablePermits(backPressure));

Expand All @@ -128,6 +145,8 @@ private void testSemaphoreBasedQueryBackPressureInMultipleThreads(int backPressu
backPressure.close();

assertEquals(backPressureLimit, availablePermits(backPressure));

aquireFutureList.forEach(booleanFuture -> assertTrue(booleanFuture.isDone()));
}

private int availablePermits(QueryBackPressure backPressure){
Expand Down

1 comment on commit 1efb00a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 1efb00a Previous: 1e098d6 Ratio
org.janusgraph.JanusGraphSpeedBenchmark.basicAddAndDelete 13064.507400321265 ms/op 13224.371596091765 ms/op 0.99
org.janusgraph.GraphCentricQueryBenchmark.getVertices 901.7824130248559 ms/op 939.9812517851383 ms/op 0.96
org.janusgraph.MgmtOlapJobBenchmark.runClearIndex 216.4771690257246 ms/op 217.29932048514493 ms/op 1.00
org.janusgraph.MgmtOlapJobBenchmark.runReindex 343.76870700128205 ms/op 341.2495420845238 ms/op 1.01
org.janusgraph.JanusGraphSpeedBenchmark.basicCount 232.80128483824285 ms/op 278.40204374307757 ms/op 0.84
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 5141.4451079438095 ms/op 4989.676889934371 ms/op 1.03
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingEmitRepeatSteps 17088.118099490195 ms/op 17611.849970189523 ms/op 0.97
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithSmallBatch 20073.528925488336 ms/op 19793.124546376966 ms/op 1.01
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.vertexCentricPropertiesFetching 59935.62464103334 ms/op 56181.93877586666 ms/op 1.07
org.janusgraph.CQLMultiQueryDropBenchmark.dropVertices 1568.1765321652874 ms/op 1552.2139994673607 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getAllElementsTraversedFromOuterVertex 8250.740713134091 ms/op 8598.330603551365 ms/op 0.96
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithDoubleUnion 380.4100542029249 ms/op 375.92614089582463 ms/op 1.01
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithUnlimitedBatch 4335.525038589459 ms/op 4143.1598921080285 ms/op 1.05
org.janusgraph.CQLMultiQueryBenchmark.getNames 8526.62129893739 ms/op 8572.994391137943 ms/op 0.99
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesThreePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 6081.343893862913 ms/op 5722.549980819107 ms/op 1.06
org.janusgraph.CQLMultiQueryBenchmark.getLabels 7315.653427825637 ms/op 7333.488489649441 ms/op 1.00
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFilteredByAndStep 426.1431452410973 ms/op 424.226132984096 ms/op 1.00
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFromMultiNestedRepeatStepStartingFromSingleVertex 12584.284128329447 ms/op 12536.954676567058 ms/op 1.00
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithCoalesceUsage 369.50236786859415 ms/op 369.92693850792364 ms/op 1.00
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 15077.343708242857 ms/op 14531.929740078982 ms/op 1.04
org.janusgraph.CQLMultiQueryBenchmark.getIdToOutVerticesProjection 250.2383849132445 ms/op 251.9395098555724 ms/op 0.99
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithUnlimitedBatch 15282.879946862999 ms/op 14879.925123906381 ms/op 1.03
org.janusgraph.CQLMultiQueryBenchmark.getNeighborNames 8450.146069522492 ms/op 8531.257465790834 ms/op 0.99
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingRepeatUntilSteps 9227.44303383386 ms/op 9331.601352568956 ms/op 0.99
org.janusgraph.CQLMultiQueryBenchmark.getAdjacentVerticesLocalCounts 8665.339896547448 ms/op 9026.050176947727 ms/op 0.96

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.