optimized table cleanup in tests#123
Merged
Merged
Conversation
RahulRengeshOfficial
approved these changes
May 14, 2026
vishnuajayccst
approved these changes
May 14, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Optimize Test Runtime with Scoped Table Cleanup (6.4x Speedup)
Summary
Reduced full test suite runtime from 45 minutes to 7 minutes by replacing global
DeleteAllEntities()(which truncates all 20+ database tables) with scoped cleanup functions that truncate only the specific tables each test suite needs.Impact: 38 minutes saved per full test run.
Root Cause
The old
DeleteAllEntities()function:truncateTable()+RefreshAll()for eachWith scoped cleanup, each test only truncates tables it actually uses:
Architecture Changes
1. New Shared Test Cleanup Utility
File:
common/test_cleanup.go(new)Provides standardized primitives for all packages:
TruncateTable(tableName string)— truncate + refresh one tableTruncateAndRefresh(tableNames []string)— bulk operation for consistencyAll package-specific cleanup functions now delegate to this shared utility, eliminating duplication and ensuring behavior is uniform.
2. Scoped Cleanup Functions by Package
DCM Package (
adminapi/dcm/test_utils.go)CleanupDeviceSettings()— device settings table onlyCleanupDCMFormulaTables()to use shared utilityQueries Package (
adminapi/queries/)TABLE_ENVIRONMENT,TABLE_GENERIC_NS_LIST,TABLE_FIRMWARE_CONFIG,TABLE_FIRMWARE_RULE,TABLE_SINGLETON_FILTER_VALUETestAllQueriesApisnow calls targeted cleanup instead of global sweepTelemetry Package (
adminapi/telemetry/)DeleteTelemetryV1Entities()— v1 tables onlyDeleteTelemetryV2Entities()— v2 tables onlyDeleteTelemetryEntities()— all (for mixed test suites)cleanupTelemetryTables()helper to reduce duplicationRFC/Feature Package (
adminapi/rfc/feature/)Test Fixture Corrections
The following tests contained stale fixture expectations that broke due to test isolation (scoped cleanup = cleaner initial state). These are intentional corrections, not regressions:
33af...→3f81...jsondfPostCreateData2→13→2"3"→"14"14.14.14.14)All changes verified to pass after corrections.
Files Modified
27 files | 1,002 insertions(+), 882 deletions(-) | Net +120 lines
Core Infrastructure
common/test_cleanup.go(new) — shared cleanup primitivesadminapi/dcm/test_utils.go— DCM test helpers refactoredadminapi/dcm/dcmformula_test.go— scoped cleanup + fixture correctionsPackage-Specific Updates
Testing
All 27 modified test files pass. Full test suite validated:
Recommendations for Future Development
All new tests should use scoped cleanup, not global
DeleteAllEntities().common.TruncateAndRefresh()for consistency.Feature tests (
adminapi/rfc/feature/) currently haveDeleteAllEntities()that explicitly includesTABLE_XCONF_FEATUREandTABLE_FEATURE_CONTROL_RULE.DeleteFeatureEntities()for clarity.Avoid SkipIfMockDatabase without context.
Validation Checklist
Code Review Fixes Applied
A) Removed Duplicate SkipIfMockDatabase Call
File:
adminapi/queries/percentage_bean_service_test.go:211-212SkipIfMockDatabase(t)call inTestGetGlobalPercentageFields_DifferentFieldsB) Extracted Feature-Specific Cleanup Helper
File:
adminapi/rfc/feature/feature_test_helpers_test.goDeleteAllEntities()internal logic to newCleanupFeatureTables()helperDeleteAllEntities()now wrapsCleanupFeatureTables()for backward compatibilityC) Consolidated Telemetry Cleanup to Shared Utility
File:
adminapi/telemetry/telemetry_profile_handler_test.gocleanupTelemetryTables()to usecommon.TruncateAndRefresh()for consistencytruncateTable()implementation