Skip to content

Conversation

@Balaji4
Copy link

@Balaji4 Balaji4 commented Jul 1, 2025

** Testing done **
Tested the code with ./gradlew clean build.

BUILD SUCCESSFUL in 12m 6s
113 actionable tasks: 102 executed, 11 up-to-date

Also tested with a giant private repo with thousands of unit tests (this base class also improved the test suite execution time by letting us run tests in parallel).


More details:
There are two changes in this PR:

Part 1:
We currently have BaseEngineTest (which runs setup() and teardown() at method level) and BaseEngineParTest (which runs setup() and teardown() at class level) in parseq library. Both are prone to race condition issues for ParseqUnitTestHelper instance as it will be setup and teared down in different tests simultaneously when tests are executed in parallel.

Added BaseEngineParSeqTest.java, which runs setup() and tearDown() at test suite level and will also make sure that the shared ParseqUnitTestHelper instance will not have any race condition issues. This will fix all the race condition issues and tests can be executed in parallel at suite level thereby reducing the test suite execution time.

Execution hierarchy for unit test setup and teardown methods with @before* and @after* annotations:
@BeforeSuite or @AfterSuite (executed only once per test suite)

@BeforeClass or @AfterClass (executed for every test class)

@BeforeMethod or @AfterMethod (executed for every test method)

Part 2:
jcenter is sunset as of Aug 15 2024 (source: https://jfrog.com/blog/jcenter-sunset/). Also, we are using an older version of build-info-extractor-gradle (the version doesn't exist in maven and gradle repository). Removing jcenter and updating build-info-extractor-gradle (bare minimum changes to fix build issues).

*
* @return ParSeqUnitTestHelper instance.
*/
protected static ParSeqUnitTestHelper getParSeqUnitTestHelper() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why expose this weirdly like this? Just make the instance protected?

Copy link
Author

Choose a reason for hiding this comment

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

I just recalled why I made it static:

I am making it singleton with this logic because I need one instance for the whole test suite so that I can setup and teardown PAR_SEQ_UNIT_TEST_HELPER in beforeSuite and afterSuite methods respectively.
BeforeSuite and AfterSuite methods run before any test's constuctor (or its base class's constructor). So making PAR_SEQ_UNIT_TEST_HELPER non-static will cause NPE issues.
Regarding why BeforeSuite and AfterSuite methods, I already commented the reason from line 33 to 35.

* com.linkedin.parseq.BaseEngineTest} executes setup()/teardown() at class level (which can cause
* race-conditions if two or more tests from the same class are executed in parallel).
*
* <p>2) It uses mutex locking mechanism to set up and tear down {@link ParSeqUnitTestHelper} to
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this static and not scoped per test class?

Copy link
Author

Choose a reason for hiding this comment

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

Same as above, need a singleton instance of ParSeqUnitTestHelper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants