Skip to content

test(framework): fix test quality issues#6653

Closed
Little-Peony wants to merge 9 commits intotronprotocol:developfrom
Little-Peony:fix_tests
Closed

test(framework): fix test quality issues#6653
Little-Peony wants to merge 9 commits intotronprotocol:developfrom
Little-Peony:fix_tests

Conversation

@Little-Peony
Copy link
Copy Markdown

What does this PR do?

Systematically fix five categories of test quality issues across framework, actuator, and plugins modules (44 files, 6 commits):

1. Silent-pass tests

  • Add Assert.fail() after code expected to throw exceptions (FetchInvDataMsgHandlerTest, MerkleTreeTest, CredentialsTest, etc.)
  • Fix assertEquals(actual, expected) argument order → assertEquals(expected, actual)

2. Thread / resource leaks

  • Replace bare Executors.newFixedThreadPool() / new Thread[] with ExecutorServiceManager in LogBlockQueryTest, TransactionRegisterTest, ConcurrentHashMapTest; add shutdownAndAwaitTermination
  • Fix InterruptedException swallowed silently → restore interrupt flag in PropUtilTest, DBIteratorTest, SnapshotImplTest, ProposalControllerTest, BlockStoreTest, PbftTest
  • Fix SolidityNode not shutting down correctly in SolidityNodeTest; patch SolidityNode.java shutdown path

3. Dead code / phantom fixtures

  • Remove @After methods cleaning paths never written by any test (DbMoveTest)
  • Remove never-called private static helpers (writeProperty(), deleteDir()) in ArchiveManifestTest, DbArchiveTest
  • Remove unreachable test code in FreezeTest, EventParserTest, RelayServiceTest, etc.

4. Stale / obsolete tests

  • Remove moreThanFrozenNumber test in FreezeBalanceActuatorTest — the corresponding actuator error path no longer exists

5. Test infrastructure unification

  • Extract ClassLevelAppContextFixture (with shutdownChannel / shutdownChannels helpers) to unify AppContext and gRPC channel lifecycle across service tests
  • Migrate CredentialsTest from JUnit 3 (junit.framework.TestCase) to JUnit 4 + Mockito; remove dependency on real SecureRandom
  • Fix package typo: keystroekeystore
  • Add Mockito.verify() assertions in InventoryMsgHandlerTest, PeerStatusCheckMockTest

Why are these changes required?

These issues caused tests to pass silently even when the code under test was broken, leaked threads between test runs (causing flakiness in parallel execution), and kept dead code that obscured the real test intent.

This PR has been tested by:

  • All changed tests pass locally (./gradlew :framework:test :actuator:test :plugins:test)

Breaking Changes

None. Test-only changes except SolidityNode.java shutdown fix (additive only).

Little-Peony and others added 6 commits April 6, 2026 16:23
- FetchInvDataMsgHandlerTest: add Assert.fail() before catch blocks so
  tests fail when expected exceptions are not thrown; fix assertEquals
  argument order (expected, actual)
- ConcurrentHashMapTest: restore commented-out Assert.fail() for
  ItemNotFoundException; replace printStackTrace() with interrupt flag
  restoration and proper logging; fail main thread on interrupted join
- InventoryMsgHandlerTest: add Mockito.verify() to assert
  isBlockUnsolidified() is called in the unsolidified-block scenario
- PeerStatusCheckMockTest: add Mockito.verify() to assert statusCheck()
  is invoked by the scheduler after init()
- MerkleTreeTest: replace Assert.assertFalse(true) with Assert.fail()
  for clearer failure message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- DbLiteTest: remove dead null-dbPath reassignment before init() call;
  restore thread interrupt flag on InterruptedException in
  generateSomeTransactions()
- DbMoveTest: remove legacy @after destroy() that cleaned a hardcoded
  path never written by any test; remove dead deleteDir() helper and
  OUTPUT_DIRECTORY constant; remove now-unused After import
- DbTest: narrow INPUT_DIRECTORY and cli fields from public to protected
- ArchiveManifestTest, DbArchiveTest: remove copy-pasted writeProperty()
  and deleteDir() private static methods that were never called; clean
  up unused imports
- DbLiteRocksDbV2Test: rename testToolsWithRocksDB to
  testToolsWithRocksDbV2 to match the LevelDB v1/v2 naming convention

Note: testMvForRocksDB is a pre-existing failure unrelated to these changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lanceActuatorTest

The method tested a "max frozen number is: X" error that no longer exists
in FreezeBalanceActuator. The actuator was updated to check
"frozenCount must be 0 or 1" instead, and a second freeze with
frozenCount=1 now succeeds rather than throwing. Remove the now-unused
ChainConstant import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nd fix test quality issues

- Replace Executors.newFixedThreadPool / bare new Thread[] with
  ExecutorServiceManager in LogBlockQueryTest, TransactionRegisterTest,
  ConcurrentHashMapTest; add proper shutdownAndAwaitTermination
- Fix InterruptedException handling: restore interrupt flag instead of
  swallowing in PropUtilTest, DBIteratorTest, SnapshotImplTest,
  ProposalControllerTest, BlockStoreTest, PbftTest
- Remove dead/unreachable test code in FreezeTest, EventParserTest,
  EventParserJsonTest, BlockFilterCapsuleTest, MessageTest,
  RelayServiceTest, DelegationServiceTest
- Fix package typo: rename keystroe.CredentialsTest → keystore.CredentialsTest;
  rewrite test using JUnit Assert and Mockito instead of junit.framework.TestCase
- Minor cleanup: unused imports, whitespace, AccountAssetStoreTest assertion style

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Sunny6889 Sunny6889 changed the title test: fix test quality issues in framework, actuator and plugins test(framework): fix test quality issues in framework, actuator and plugins Apr 8, 2026
@Little-Peony Little-Peony changed the title test(framework): fix test quality issues in framework, actuator and plugins test: fix test quality issues in framework, actuator and plugins Apr 8, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Sunny6889 Sunny6889 changed the title test: fix test quality issues in framework, actuator and plugins test(framework): fix test quality issues in framework, actuator and plugins Apr 8, 2026
Little-Peony and others added 2 commits April 8, 2026 15:25
Move to local .git/info/exclude instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Sunny6889 Sunny6889 changed the title test(framework): fix test quality issues in framework, actuator and plugins test(framework): fix test quality issues Apr 8, 2026
@Sunny6889 Sunny6889 closed this Apr 8, 2026
@Sunny6889 Sunny6889 reopened this Apr 8, 2026
@Little-Peony
Copy link
Copy Markdown
Author

Closing in favor of a clean PR with the same changes.

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