Increase sherdlock selector test coverage. #1505
Conversation
fac2330 to
e8ad5c4
Compare
|
Hi @Rozerxshashank , you are the master of the test coverage. Fantastic, thanks for the effort 🙏 |
|
@Rozerxshashank , are you on discord? |
|
@Rozerxshashank , same thing here. Please, use counterfeiter. Thanks 🙏 |
Yes @adecaro, I am on discord my username - shashank4956 |
Sure Thanks for telling. I will use counterfeiter from now on. |
fe1ea4d to
725c1aa
Compare
|
Hey @adecaro, I've updated the sherdlock package unit tests to utilize counterfeiter-generated fakes as requested. 🙌 |
|
@Rozerxshashank , please, generate all the mocks under the folder Thanks 🙏 PS: Please, check the linter as well. To fix |
e77f741 to
dfe4ea0
Compare
|
Hi @adecaro, I have updated the PR to move all mocks to the mocks/ subfolder and centralized the interfaces in interfaces.go to support the new structure. I also fixed the nlreturn lint issues and ran code formatting. 🙌😊 Once this gets approved, I'll focus on the remaining test coverage! Also, I’m very interested in applying for the LFX Mentorship for this project. Could you let me know if these types of contributions are a good start for my application, or if there is a specific area I should focus on to be a strong candidate? Thanks for your guidance! 🙏 |
10b3410 to
5b54181
Compare
|
Hi @Rozerxshashank , please, can you rebase the PR. There are conflicts that need to be resolved. |
7674cd7 to
4ab965f
Compare
|
@adecaro, Done with rebasing the PR.🙌 |
6bcf8e6 to
87e6bd4
Compare
87e6bd4 to
d1d992d
Compare
| cfg := postgres2.DefaultConfig(postgres2.WithDBName(t.Name())) | ||
| terminate, _, err := postgres2.StartPostgres(t.Context(), cfg, nil) | ||
| require.NoError(t, err) | ||
| if err != nil { |
| } | ||
|
|
||
| func key(tms *token.ManagementService) string { | ||
| func key(tms token.ManagementService) string { |
There was a problem hiding this comment.
why this? Why passing by value here?
There was a problem hiding this comment.
My bad! Totally missed that during the refactoring. I've switched it back to a pointer to avoid the extra copying.😅
There was a problem hiding this comment.
My bad, that was a leftover from some local debugging! I've removed it in the latest push. 😅
|
Hi @Rozerxshashank , left a few more comments. Thanks 🙏 |
d1d992d to
9c55b1e
Compare
9c55b1e to
425da59
Compare
|
@adecaro , I really appreciate you jumping in and fixing that HTLC scanner bug yourself. It was a big help. Thanks for the support! 🙏 |
425da59 to
a926cf3
Compare
9b6967e to
2f1ea52
Compare
| // Use generous tolerance for scheduling jitter | ||
| for i := 1; i < len(intervals); i++ { | ||
| assert.InDelta(t, 10*time.Millisecond, intervals[i], float64(10*time.Millisecond), | ||
| assert.InDelta(t, 10*time.Millisecond, intervals[i], float64(50*time.Millisecond), |
There was a problem hiding this comment.
This increase is to prevent flaky test failures in CI environments where scheduling jitter often causes delays to exceed the previous 10ms tolerance. I've added a code comment to document this justification.
|
@Rozerxshashank , we are in the good direction. Thanks much 🙏 |
2f1ea52 to
52975e0
Compare
|
@adecaro, I've addressed your feedback: I've reorganized the tests into component-specific files (eliminating unit_test.go) and increased the service.go statement coverage to 91.1%. I also resolved the stability issues in retry_test.go. Thanks 🙏 |
e78a855 to
defa2c7
Compare
defa2c7 to
7ee9c17
Compare
7ee9c17 to
279c11a
Compare
Signed-off-by: Shashank <yshashank959@gmail.com>
…nterfeiter Signed-off-by: Shashank <yshashank959@gmail.com>
Signed-off-by: Shashank <yshashank959@gmail.com>
Signed-off-by: Shashank <yshashank959@gmail.com>
Signed-off-by: Shashank <yshashank959@gmail.com>
Signed-off-by: Shashank <yshashank959@gmail.com>
279c11a to
f7fd80a
Compare
Description
This PR addresses Issue #1488 by significantly increasing the unit test coverage for the
token/services/selector/sherdlockpackage. Before these changes, the package lacked fundamental unit tests for its core logic, particularly around retry mechanisms and fetcher strategies.I've introduced a comprehensive test suite that now covers 91.1% of the statements in the package, ensuring the robustness of token selection logic, cache management, and service lifecycle.
Proposed Changes
1. Testability Refactoring
SelectorServiceand the internal loader to interact with a new internalTMS(Token Management Service) interface.PublicParameters()convenience method to the coreManagementServicestruct to facilitate interface implementation and SDK-wide testability. This decoupling allows for effective mocking of core services during unit testing.2. New Unit Test Suite (Component-Specific)
Instead of a generic
unit_test.go, tests are now organized by component:fetcher_unit_test.go): Added tests forLazyFetcher,CachedFetcher, andMixedFetcherto verify correct database interactions and cache refresh cycles.selector_test.go): Implemented tests for core Selector logic, covering edge cases like unit selection, locked tokens, and selector closure.StubbornSelectorand theretryutility, verifying exponential backoff, max retry exhaustion, and respectful handling of context cancellation.service_test.go): Targeted tests forSelectorServicemanager tracking, loader logic, and shutdown flows.3. Maintenance & Cleanup
go fmtandgolangci-lint(passed with 0 issues).retry_test.goto ensure stability in CI/CD environments.Testing & Coverage Evidence
The package was verified using the following metrics:
Related Issues
Fixes #1488