test(server-test): enable run single unit test#2940
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables running individual unit tests from the CoreTestSuite without executing the entire test suite. Previously, running a single test class directly would fail because the graph initialization only occurred when running the full CoreTestSuite with JUnit's Suite runner.
Changes:
- Removed unused
Assertimport sinceAssert.assertNotNull(graph)assertion is no longer needed - Modified
graph()method to perform lazy initialization when graph is null, ensuring tests can run independently
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java
Show resolved
Hide resolved
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java
Outdated
Show resolved
Hide resolved
| synchronized (CoreTestSuite.class){ | ||
| if (graph == null) { | ||
| initEnv(); | ||
| init(); |
There was a problem hiding this comment.
The initEnv() and init() methods can throw exceptions. If an exception occurs inside the synchronized block:
graphremainsnull- Subsequent calls will retry initialization (possibly desirable, but may cause repeated failures)
Consider whether failed initialization should be remembered to provide a clearer error message on subsequent calls, or at minimum document this behavior.
Also, there's an ordering dependency: initEnv() must complete before init(). While this works with the current registered flag, consider whether you need additional error handling if initEnv() succeeds but init() fails.
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java
Show resolved
Hide resolved
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java
Show resolved
Hide resolved
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| init(); | ||
| } catch (Throwable e) { | ||
| LOG.error("Failed to initialize HugeGraph instance", e); | ||
| graph = null; |
There was a problem hiding this comment.
The assignment graph = null is redundant here. At this point in the code flow, graph is guaranteed to be null because it's only assigned a value in the init() method at line 95. This redundant assignment has no effect and can be removed.
Purpose of the PR
Main Changes
Verifying these changes
Does this PR potentially affect the following parts?
Documentation Status
Doc - TODODoc - DoneDoc - No Need