Speed up ITs by sharing the cluster across test methods#17682
Merged
Conversation
Each @Before/@after pair restarts the cluster for every test method, which makes management/syntax/auth-style ITs spend most of their wall time on cluster start/stop. Convert 37 ITs under integration-test/src/test/java/ org/apache/iotdb/db/it to start the cluster once per class, with each test cleaning up its own state via try/finally and quietly-ignoring helpers (e.g. dropFunctionQuietly, executeQuietly, cleanupAfterTest). Tests that mutate cluster topology, restart nodes, depend on accumulating global state (audit log), or rotate root credentials are intentionally left on @Before/@after.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17682 +/- ##
============================================
+ Coverage 40.38% 40.42% +0.04%
Complexity 2574 2574
============================================
Files 5178 5179 +1
Lines 349134 349261 +127
Branches 44665 44683 +18
============================================
+ Hits 140988 141205 +217
+ Misses 208146 208056 -90 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
User IDs are auto-incremented globally and do not reset when users are dropped between tests. With @BeforeClass/@afterclass sharing one cluster, the cleanup drops users but the ID counter keeps incrementing, causing assertions on specific IDs (10000, 10001, etc.) to fail. Replace user ID assertions with username-only checks in three places: - listUserPrivileges: remove hardcoded '10000' check - listUserPrivileges: LIST USER OF ROLE now checks username only - testCreateUserAndRole: compare username sets instead of userId,User pairs
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Motivation
Most ITs under
integration-test/src/test/java/org/apache/iotdb/db/it/use@Before/@Afterto start and stop the cluster on every test method. For a class with N tests this means N full cluster start/stop cycles (~5s each), which dominates wall time on management/syntax/auth-style suites where the actual test body finishes in tens of milliseconds.For example,
IoTDBSimpleQueryIThas 36 tests; previously it spent roughly 36 × 5s ≈ 3 min just on cluster lifecycle. After this change the same suite finishes in ~14s.Changes
Converted 37 ITs to start the cluster once per class:
@Before→@BeforeClass public static void setUp()@After→@AfterClass public static void tearDown()try { ... } finally { ... }and cleans up the state it created (drop database / drop function / drop user / drop role / revoke privileges / drop trigger / drop template / etc.) via small static helpers likedropFunctionQuietly,executeQuietly, orcleanupAfterTestthat swallow expected SQLExceptions.@BeforeClass.IoTDBMQTTServiceJsonITthe cluster moves to@BeforeClass/@AfterClasswhile per-test MQTT connection setup stays in@Before/@After(each test still gets its own connection).Tests intentionally left on
@Before/@AfterThese have semantics that are incompatible with sharing a cluster across tests:
IoTDBRecoverIT,IoTDBRecoverUnclosedIT,IoTDBRestartIT,IoTDBRestartRatisIT,IoTDBVerifyConnectionITIoTDBLoadLastCacheIT(parameterized),IoTDBLoadTsFileIT,metric/IoTDBMetricIT,iotconsensusv2/IoTDBIoTConsensusV23C3DBasicITBasequotas/IoTDBSpaceQuotaIT,audit/IoTDBAuditLogBasicIT,schema/IoTDBDeactivateTemplateIT,schema/IoTDBMetadataFetchIT,schema/IoTDBSchemaTemplateIT,IoTDBInsertWithQueryIT,aligned/IoTDBAlignedDataDeletionITauth/IoTDBUserRenameIT@BeforeClasswould run before@Parameterized.BeforeParam(cluster not yet up) —schema/quota/IoTDBClusterQuotaITCREATE USER user1and assert "no data → empty" on the same path —schema/regionscan/IoTDBActiveSchemaQueryITVerification
Spotless and
mvn test-compilepass on the integration-test module. Ran 4 batches of representative ITs locally:@Ignore)