jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371956 )

Change subject: fix leaking threads in integration tests
......................................................................


fix leaking threads in integration tests

The RdfRepository in AbstractRdfRepositoryIntegrationTestBase wasn't closed
properly on each test, which make randomized testing leaked thread detector
unhappy. This should help make tests more reliable.

Change-Id: Ie3496814a320f77641142b01e1c99da416b2e2ba
---
M 
tools/src/test/java/org/wikidata/query/rdf/tool/AbstractRdfRepositoryIntegrationTestBase.java
1 file changed, 28 insertions(+), 18 deletions(-)

Approvals:
  Smalyshev: Looks good to me, approved
  jenkins-bot: Verified
  Gehel: Looks good to me, but someone else must approve



diff --git 
a/tools/src/test/java/org/wikidata/query/rdf/tool/AbstractRdfRepositoryIntegrationTestBase.java
 
b/tools/src/test/java/org/wikidata/query/rdf/tool/AbstractRdfRepositoryIntegrationTestBase.java
index fa39003..5f439a3 100644
--- 
a/tools/src/test/java/org/wikidata/query/rdf/tool/AbstractRdfRepositoryIntegrationTestBase.java
+++ 
b/tools/src/test/java/org/wikidata/query/rdf/tool/AbstractRdfRepositoryIntegrationTestBase.java
@@ -33,7 +33,7 @@
     /**
      * Repository to test with.
      */
-    private final RdfRepositoryForTesting rdfRepository;
+    private RdfRepositoryForTesting rdfRepository;
 
     /**
      * Build the test against prod wikidata.
@@ -44,7 +44,34 @@
 
     public AbstractRdfRepositoryIntegrationTestBase(WikibaseUris uris) {
         this.uris = uris;
+    }
+
+    /**
+     * Initializes the {@link RdfRepository} before each test.
+     *
+     * Since randomized testing ThreadLeakControl checks for leaked thread, not
+     * closing properly the RdfRepository after each test causes random false
+     * negative in the test results. Initializing the RdfRepository for each
+     * test might be slightly less performant, but at least it ensures
+     * reproducible tests.
+     */
+    @Before
+    public void initRdfRepository() {
         rdfRepository = new RdfRepositoryForTesting("wdq");
+        rdfRepository.clear();
+    }
+
+    /**
+     * Closes the {@link RdfRepository} after each test.
+     *
+     * @throws Exception on error
+     */
+    @After
+    public void clearAndShutdownRdfRepository() throws Exception {
+        if (rdfRepository != null) {
+            rdfRepository.clear();
+            rdfRepository.close();
+        }
     }
 
     /**
@@ -59,23 +86,6 @@
      */
     public RdfRepositoryForTesting rdfRepository() {
         return rdfRepository;
-    }
-
-    /**
-     * Clear the repository so one test doesn't interfere with another.
-     */
-    @Before
-    public void clear() {
-        rdfRepository.clear();
-    }
-
-    /**
-     * Close the repository at the end.
-     * @throws Exception on error
-     */
-    @After
-    public void closeRepo() throws Exception {
-        rdfRepository.close();
     }
 
     /**

-- 
To view, visit https://gerrit.wikimedia.org/r/371956
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3496814a320f77641142b01e1c99da416b2e2ba
Gerrit-PatchSet: 2
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: Gehel <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to