-
Notifications
You must be signed in to change notification settings - Fork 989
test: add unit test for cluster #3135
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3135 +/- ##
===========================================
+ Coverage 37.04% 45.48% +8.44%
===========================================
Files 460 460
Lines 32997 32997
===========================================
+ Hits 12224 15010 +2786
+ Misses 19547 16726 -2821
- Partials 1226 1261 +35 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
This PR adds comprehensive unit test coverage for the cluster package and fixes a critical boundary check bug in the argument matcher that could cause index out of bounds panics.
Key changes:
- Fixed boundary check in
ArgumentConditionMatcherfromindex > len(...)toindex >= len(...)to prevent array access errors - Added extensive unit tests covering cluster operations, load balancing algorithms, routing conditions, and metrics
- Standardized test IP addresses from
192.168.1.xto127.0.0.1with different ports in P2C load balancer tests
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cluster/router/condition/matcher/argument.go | Fixed boundary check bug to prevent index out of bounds when accessing invocation arguments |
| cluster/utils/version_test.go | Tests for version parsing, comparison, and validation with various formats |
| cluster/utils/adaptivesvc_test.go | Tests for adaptive service error detection and handling |
| cluster/router/script/instance/instances_pool_test.go | Tests for script router instance pool including wrapper lifecycle and JavaScript instance retrieval |
| cluster/router/options_test.go | Tests for router configuration options builders (contains tests validating buggy behavior) |
| cluster/router/condition/matcher/base_test.go | Tests for base condition matcher functionality and value extraction |
| cluster/router/condition/matcher/attachment_test.go | Tests for attachment-based condition matching with various key formats |
| cluster/router/condition/matcher/argument_test.go | Tests for argument-based condition matching including boundary cases |
| cluster/metrics/utils_test.go | Tests for invoker and instance key generation utilities |
| cluster/metrics/local_metrics_test.go | Tests for local metrics storage with concurrency validation |
| cluster/loadbalance/util_test.go | Tests for weight calculation including warmup and priority handling |
| cluster/loadbalance/p2c/loadbalance_test.go | Updated test IP addresses to use localhost with different ports |
| cluster/loadbalance/iwrr/iwrr_test.go | Tests for interleaved weighted round-robin queue operations and GCD calculations |
| cluster/loadbalance/aliasmethod/alias_method_test.go | Tests for alias method weighted selection algorithm |
| cluster/cluster/mock_test.go | Tests for mock invoker and cluster implementations |
| cluster/cluster/interceptor_invoker_test.go | Tests for interceptor chain building and invocation order |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
please review the copilot's comment. |
ok |
|



Summary
Improve unit test coverage for the
clusterpackage and fix a boundary check bug in argument matcher.Changes
Add unit tests for cluster package functionality:
cluster/cluster/:interceptor_invoker_test.go: Interceptor chain building and managementmock_test.go: Mock invoker and cluster implementationscluster/loadbalance/:aliasmethod/alias_method_test.go: Alias method picker for weighted load balancingiwrr/iwrr_test.go: Interleaved weighted round-robin queue operationsutil_test.go: Weight calculation with warmup and priority handlingcluster/metrics/:local_metrics_test.go: Local metrics storage and concurrent accessutils_test.go: Invoker and instance key generation utilitiescluster/router/:condition/matcher/argument_test.go: Argument condition matchercondition/matcher/attachment_test.go: Attachment condition matchercondition/matcher/base_test.go: Base condition matcher and sortingoptions_test.go: Router configuration optionsscript/instance/instances_pool_test.go: Script router instance poolcluster/utils/:adaptivesvc_test.go: Adaptive service error handlingversion_test.go: Version parsing and comparisonFix bug in
cluster/router/condition/matcher/argument.go:index > len(...)toindex >= len(...)to prevent index out of range panicChecklist
develop