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]>
(cherry picked from commit 1efb00a)
  • Loading branch information
porunov committed Jul 10, 2024
1 parent 3588c4c commit e63ff5f
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 e63ff5f

@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: e63ff5f Previous: 1e098d6 Ratio
org.janusgraph.JanusGraphSpeedBenchmark.basicAddAndDelete 12729.75478350142 ms/op 13224.371596091765 ms/op 0.96
org.janusgraph.GraphCentricQueryBenchmark.getVertices 906.2808263077792 ms/op 939.9812517851383 ms/op 0.96
org.janusgraph.MgmtOlapJobBenchmark.runClearIndex 216.1016267833333 ms/op 217.29932048514493 ms/op 0.99
org.janusgraph.MgmtOlapJobBenchmark.runReindex 336.65915424916665 ms/op 341.2495420845238 ms/op 0.99
org.janusgraph.JanusGraphSpeedBenchmark.basicCount 231.48811239262022 ms/op 278.40204374307757 ms/op 0.83
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 7726.53121781894 ms/op 4989.676889934371 ms/op 1.55
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingEmitRepeatSteps 17553.596143069997 ms/op 17611.849970189523 ms/op 1.00
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithSmallBatch 19642.48616663394 ms/op 19793.124546376966 ms/op 0.99
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.vertexCentricPropertiesFetching 56909.13737723333 ms/op 56181.93877586666 ms/op 1.01
org.janusgraph.CQLMultiQueryBenchmark.getAllElementsTraversedFromOuterVertex 8165.317365145001 ms/op 8598.330603551365 ms/op 0.95
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithDoubleUnion 407.04529346552937 ms/op 375.92614089582463 ms/op 1.08
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesAllPropertiesWithUnlimitedBatch 4871.054260512945 ms/op 4143.1598921080285 ms/op 1.18
org.janusgraph.CQLMultiQueryBenchmark.getNames 10108.38731931984 ms/op 8572.994391137943 ms/op 1.18
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesThreePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 5946.261920487219 ms/op 5722.549980819107 ms/op 1.04
org.janusgraph.CQLMultiQueryBenchmark.getLabels 7872.017481884409 ms/op 7333.488489649441 ms/op 1.07
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFilteredByAndStep 473.3394545421628 ms/op 424.226132984096 ms/op 1.12
org.janusgraph.CQLMultiQueryBenchmark.getVerticesFromMultiNestedRepeatStepStartingFromSingleVertex 12812.614890676923 ms/op 12536.954676567058 ms/op 1.02
org.janusgraph.CQLMultiQueryBenchmark.getVerticesWithCoalesceUsage 375.05361951918604 ms/op 369.92693850792364 ms/op 1.01
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithAllMultiQuerySlicesUnderMaxRequestsPerConnection 14453.826849076191 ms/op 14531.929740078982 ms/op 0.99
org.janusgraph.CQLMultiQueryBenchmark.getIdToOutVerticesProjection 251.70972011979927 ms/op 251.9395098555724 ms/op 1.00
org.janusgraph.CQLMultiQueryMultiSlicesBenchmark.getValuesMultiplePropertiesWithUnlimitedBatch 13940.649574333913 ms/op 14879.925123906381 ms/op 0.94
org.janusgraph.CQLMultiQueryBenchmark.getNeighborNames 10217.15841116882 ms/op 8531.257465790834 ms/op 1.20
org.janusgraph.CQLMultiQueryBenchmark.getElementsWithUsingRepeatUntilSteps 8851.494583298505 ms/op 9331.601352568956 ms/op 0.95
org.janusgraph.CQLMultiQueryBenchmark.getAdjacentVerticesLocalCounts 8512.474519119009 ms/op 9026.050176947727 ms/op 0.94

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

Please sign in to comment.