-
Notifications
You must be signed in to change notification settings - Fork 3
fix: PD/Store CI problem #11
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
base: master
Are you sure you want to change the base?
Conversation
The test `testBalancePartitionLeader` was prone to a ConcurrentModificationException because the `TaskScheduleService` could still be running background tasks when the cleanup method `getStoreNodeService().getStoreInfoMeta().removeAll()` was called. These background tasks might be iterating over data that `removeAll()` modifies, leading to the exception. This commit addresses the issue by: 1. Introducing an `@After` method (`tearDown`) in `TaskScheduleServiceTest.java`. 2. In the `tearDown` method, the `TaskScheduleService` instance (`this.service`) is now explicitly shut down using `this.service.shutDown()` before any cleanup operations are performed. 3. The call to `getStoreNodeService().getStoreInfoMeta().removeAll()` has been moved from the `testBalancePartitionLeader` method into the new `tearDown` method to ensure it runs after the service shutdown. This change ensures that all background activity is stopped before data cleanup, preventing potential concurrent modifications.
@codecov-ai-reviewer review |
On it! We are reviewing the PR and will provide feedback shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a teardown step to stop background tasks before cleaning up store metadata, preventing ConcurrentModificationException
in testBalancePartitionLeader
.
- Introduces an
@After
-annotatedtearDown
to shut downTaskScheduleService
and callremoveAll()
- Moves the
removeAll()
call out oftestBalancePartitionLeader
- Adds the necessary JUnit
@After
import
Comments suppressed due to low confidence (1)
hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java:50
- The TODO testStoreOffline method is missing an @test annotation and won't execute; consider adding @test or marking it @ignore to clarify its status.
public void testStoreOffline() {
@After | ||
public void tearDown() { | ||
if (this.service != null) { | ||
this.service.shutDown(); |
Copilot
AI
Jun 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutDown() initiates shutdown but returns immediately; consider adding an awaitTermination(timeout) call after shutDown() to ensure all background tasks have fully stopped before cleanup.
this.service.shutDown(); | |
this.service.shutDown(); | |
try { | |
this.service.awaitTermination(30, TimeUnit.SECONDS); | |
} catch (InterruptedException e) { | |
Thread.currentThread().interrupt(); | |
throw new RuntimeException("Failed to await termination of TaskScheduleService", e); | |
} |
Copilot uses AI. Check for mistakes.
this.service.shutDown(); | ||
} | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); |
Copilot
AI
Jun 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the shutdown and cleanup logic in a try/finally block so that removeAll() always runs even if shutDown() throws an exception.
this.service.shutDown(); | |
} | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
try { | |
this.service.shutDown(); | |
} finally { | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
} | |
} |
Copilot uses AI. Check for mistakes.
PR DescriptionThis pull request aims to improve the reliability and maintainability of the Click to see moreKey Technical ChangesThe key technical change is the addition of the Architecture DecisionsThe architectural decision is to adopt a centralized cleanup strategy using JUnit's Dependencies and InteractionsThis change primarily affects the Risk ConsiderationsThe primary risk is that the Notable Implementation DetailsThe |
@After | ||
public void tearDown() { | ||
if (this.service != null) { | ||
this.service.shutDown(); | ||
} | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvement: Adding a centralized tearDown method is excellent for test hygiene. This ensures consistent cleanup after each test method and prevents state leakage between tests.
this.service.shutDown(); | ||
} | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding null check for defensive programming: While the service null check is good, consider also checking if getStoreNodeService() returns null before calling methods on it to prevent potential NullPointerException.
this.service.shutDown(); | |
} | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
@After | |
public void tearDown() { | |
if (this.service != null) { | |
this.service.shutDown(); | |
} | |
if (getStoreNodeService() != null && getStoreNodeService().getStoreInfoMeta() != null) { | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
} | |
} |
getPdConfig().getPartition().setShardCount(1); | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent refactoring: Moving the cleanup code from the individual test method to the centralized tearDown method improves maintainability and ensures consistent cleanup across all tests. This follows the DRY principle and reduces code duplication.
@After | ||
public void tearDown() { | ||
if (this.service != null) { | ||
this.service.shutDown(); | ||
} | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider exception handling: The tearDown method should handle potential exceptions during cleanup to prevent masking test failures. Consider wrapping cleanup operations in try-catch blocks and logging any cleanup failures.
@After | |
public void tearDown() { | |
if (this.service != null) { | |
this.service.shutDown(); | |
} | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
} | |
@After | |
public void tearDown() { | |
try { | |
if (this.service != null) { | |
this.service.shutDown(); | |
} | |
} catch (Exception e) { | |
// Log cleanup failure but don't fail the test | |
System.err.println("Failed to shutdown service: " + e.getMessage()); | |
} | |
try { | |
if (getStoreNodeService() != null && getStoreNodeService().getStoreInfoMeta() != null) { | |
getStoreNodeService().getStoreInfoMeta().removeAll(); | |
} | |
} catch (Exception e) { | |
// Log cleanup failure but don't fail the test | |
System.err.println("Failed to clear store info meta: " + e.getMessage()); | |
} | |
} |
@After | ||
public void tearDown() { | ||
if (this.service != null) { | ||
this.service.shutDown(); | ||
} | ||
getStoreNodeService().getStoreInfoMeta().removeAll(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider test isolation: Ensure that the tearDown method completely resets the system state. You might want to verify that all resources are properly cleaned up and consider adding additional cleanup operations if needed for complete test isolation.
The test
testBalancePartitionLeader
was prone to a ConcurrentModificationException because theTaskScheduleService
could still be running background tasks when the cleanup methodgetStoreNodeService().getStoreInfoMeta().removeAll()
was called. These background tasks might be iterating over data thatremoveAll()
modifies, leading to the exception.This commit addresses the issue by:
@After
method (tearDown
) inTaskScheduleServiceTest.java
.tearDown
method, theTaskScheduleService
instance (this.service
) is now explicitly shut down usingthis.service.shutDown()
before any cleanup operations are performed.getStoreNodeService().getStoreInfoMeta().removeAll()
has been moved from thetestBalancePartitionLeader
method into the newtearDown
method to ensure it runs after the service shutdown.This change ensures that all background activity is stopped before data cleanup, preventing potential concurrent modifications.