forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix flaky tests in IT pipeline #1321
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
Open
milanmajchrak
wants to merge
11
commits into
dtq-dev
Choose a base branch
from
fix/dspace-flaky-tests
base: dtq-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9bf258d
Fixed integration tests because they use to fail sometimes
milanmajchrak bb09815
test: stabilize flaky CI tests (Hibernate cleanup retry, Shibboleth a…
milanmajchrak 6e86590
test: fix flaky ITs at the source (live ORCID, Shibboleth config-relo…
milanmajchrak b6e300e
test: revert IT-env config-reload=false override
milanmajchrak 106de96
test: make Shibboleth auth-sequence override reload-safe (fix WWW-Aut…
milanmajchrak ead032f
test: add Hibernate concurrency monitor + CI upload to pinpoint @Afte…
milanmajchrak 0a88723
fix: don't close iterate() Hibernate stream from a finalize() (root c…
milanmajchrak 11c113b
fix: remove broken Context.finalize() that leaked finalizer-thread se…
milanmajchrak 0b2e9b7
test: remove flaky-CME diagnostic scaffolding and teardown retry (roo…
milanmajchrak 5375b50
revert: keep Context.finalize() (out of scope, not the CME cause)
milanmajchrak a30ca79
test: address review comments on flaky-test fix
milanmajchrak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
dspace-api/src/test/java/org/dspace/core/AbstractHibernateDAOIteratorIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * The contents of this file are subject to the license and copyright | ||
| * detailed in the LICENSE and NOTICE files at the root of the source | ||
| * tree and available online at | ||
| * | ||
| * http://www.dspace.org/license/ | ||
| */ | ||
| package org.dspace.core; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| import org.dspace.AbstractIntegrationTestWithDatabase; | ||
| import org.dspace.content.MetadataValue; | ||
| import org.dspace.content.factory.ContentServiceFactory; | ||
| import org.dspace.content.service.MetadataValueService; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Regression test for the intermittent {@code ConcurrentModificationException} thrown during | ||
| * {@code @After} integration-test cleanup and traced to | ||
| * {@link AbstractHibernateDAO#iterate(javax.persistence.Query)}. | ||
| * | ||
| * <p>That method used to close its Hibernate {@code Stream} from a {@code finalize()} override. {@code finalize()} | ||
| * runs on the GC Finalizer thread, so closing the stream there mutated the owning {@code Session}'s per-session, | ||
| * non-thread-safe JDBC {@code ResourceRegistry} (xref) concurrently with the thread that owns the session. That | ||
| * is a genuine data race which intermittently threw {@code ConcurrentModificationException} from | ||
| * {@code ResourceRegistryStandardImpl.releaseResources} during an unrelated commit/rollback. The fix closes the | ||
| * stream on the owning thread once the iteration is exhausted. This test guards against reintroducing any | ||
| * stream-closing finalizer on the returned iterator.</p> | ||
| */ | ||
| public class AbstractHibernateDAOIteratorIT extends AbstractIntegrationTestWithDatabase { | ||
|
|
||
| private final MetadataValueService metadataValueService = | ||
| ContentServiceFactory.getInstance().getMetadataValueService(); | ||
|
|
||
| /** | ||
| * Verifies that the iterator returned by {@link AbstractHibernateDAO#iterate(javax.persistence.Query)} | ||
| * (exercised here through {@code MetadataValueService.findByValueLike}) does not close its backing Hibernate | ||
| * stream from a {@code finalize()} override anywhere in its class hierarchy, and that it still iterates to | ||
| * exhaustion (closing its cursor on the owning thread) without error. No matching rows are required - the | ||
| * wrapper iterator is created regardless of the result count. | ||
| * | ||
| * @throws Exception passed through. | ||
| */ | ||
| @Test | ||
| public void iterateIteratorMustNotCloseStreamFromFinalizer() throws Exception { | ||
| Iterator<MetadataValue> iterator = | ||
| metadataValueService.findByValueLike(context, "no-such-metadata-value-" + System.nanoTime()); | ||
| assertNotNull(iterator); | ||
|
|
||
| // The returned iterator - and every class in its hierarchy up to Object - MUST NOT declare a finalize() | ||
| // override: closing the backing Hibernate Stream from the GC Finalizer thread is exactly the cross-thread | ||
| // access to the non-thread-safe per-session JDBC ResourceRegistry that caused the flaky | ||
| // ConcurrentModificationException. Walking the hierarchy also catches a finalizer reintroduced on a | ||
| // superclass/helper rather than on the anonymous leaf class. | ||
| for (Class<?> type = iterator.getClass(); type != null && type != Object.class; type = type.getSuperclass()) { | ||
| try { | ||
| type.getDeclaredMethod("finalize"); | ||
| fail("AbstractHibernateDAO.iterate() iterator must not declare a finalize() override (found on " | ||
| + type.getName() + ") - closing the Hibernate Stream on the GC Finalizer thread races the " | ||
| + "owning thread's non-thread-safe JDBC ResourceRegistry and intermittently throws " | ||
| + "ConcurrentModificationException."); | ||
| } catch (NoSuchMethodException expected) { | ||
| // good: no stream-closing finalizer on this class | ||
| } | ||
| } | ||
|
|
||
| // It must still iterate to exhaustion and close its cursor on THIS (the owning) thread without error. | ||
| while (iterator.hasNext()) { | ||
| assertNotNull(iterator.next()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
dspace-api/src/test/resources/org/dspace/external/orcid-expanded-search.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <!-- | ||
| Canned ORCID "expanded-search" response used by CachingOrcidRestConnectorTest so the test does NOT | ||
| depend on the live ORCID sandbox (https://pub.sandbox.orcid.org), whose dataset is periodically reset | ||
| and previously caused intermittent CI failures (e.g. num-found dropping below a hard-coded threshold). | ||
| Namespace/element names mirror org.orcid.jaxb.model.v3.release.search.expanded.ExpandedSearch. | ||
| The first result intentionally maps to the label "Connor, John" (family-names, given-names). | ||
| --> | ||
| <expanded-search:expanded-search num-found="1725" | ||
| xmlns:expanded-search="http://www.orcid.org/ns/expanded-search"> | ||
| <expanded-search:expanded-result> | ||
| <expanded-search:orcid-id>0000-0002-9150-2529</expanded-search:orcid-id> | ||
| <expanded-search:given-names>John</expanded-search:given-names> | ||
| <expanded-search:family-names>Connor</expanded-search:family-names> | ||
| </expanded-search:expanded-result> | ||
| <expanded-search:expanded-result> | ||
| <expanded-search:orcid-id>0000-0002-1208-2352</expanded-search:orcid-id> | ||
| <expanded-search:given-names>John</expanded-search:given-names> | ||
| <expanded-search:family-names>Kendrew</expanded-search:family-names> | ||
| <expanded-search:credit-name>John Kendrew</expanded-search:credit-name> | ||
| </expanded-search:expanded-result> | ||
| </expanded-search:expanded-search> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.