Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-4242 fix flaky test #4261

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.time.StopWatch;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.query.BindingSet;
Expand Down Expand Up @@ -56,6 +62,8 @@ public abstract class TupleQueryResultTest {

private final Random random = new Random(43252333);

private List<WeakReference<TupleQueryResult>> unclosedQueryResults;

@BeforeEach
public void setUp() throws Exception {
System.setProperty("org.eclipse.rdf4j.repository.debug", "true");
Expand All @@ -64,6 +72,8 @@ public void setUp() throws Exception {

buildQueries();
addData();
unclosedQueryResults = new ArrayList<>();

}

@AfterEach
Expand Down Expand Up @@ -249,16 +259,26 @@ public void testNotClosingResult() {
}

@Test
public void testNotClosingResultWithoutDebug() {
public void testNotClosingResultWithoutDebug() throws InterruptedException {
System.setProperty("org.eclipse.rdf4j.repository.debug", "false");

StopWatch stopWatch = StopWatch.createStarted();

con.begin();
con.add(RDF.TYPE, RDF.TYPE, RDF.PROPERTY);
con.commit();

for (int i = 0; i < 100; i++) {
try (RepositoryConnection repCon = rep.getConnection()) {
evaluateQueryWithoutClosing(repCon);
System.gc();
Thread.sleep(1);
while (unclosedQueryResults.stream().map(Reference::get).anyMatch(Objects::nonNull)) {
System.gc();
Thread.sleep(100);
assertTrue(stopWatch.getTime(TimeUnit.SECONDS) < 60, "Test timed out after 60 seconds");

}
}
}

Expand All @@ -271,6 +291,7 @@ private void evaluateQueryWithoutClosing(RepositoryConnection repCon) {
// see if open results hangs test
// DO NOT CLOSE THIS
TupleQueryResult evaluate = tupleQuery.evaluate();
unclosedQueryResults.add(new WeakReference<>(evaluate));
Assertions.assertNotNull(evaluate);
}

Expand Down