Skip to content

staticaddr: deflake deposit manager test#1111

Open
starius wants to merge 1 commit intolightninglabs:masterfrom
starius:fix-deposit-test
Open

staticaddr: deflake deposit manager test#1111
starius wants to merge 1 commit intolightninglabs:masterfrom
starius:fix-deposit-test

Conversation

@starius
Copy link
Copy Markdown
Collaborator

@starius starius commented Apr 6, 2026

The sqlite and postgres race jobs were both hanging in deposit.TestManager. The test was observing the manager through implementation details that were not safe to share with the manager itself:

  • it replaced the manager's internal finalizedDepositChan and then waited on the same channel the manager consumes
  • it reused package-level block and confirmation channels across runs
  • it treated confirmationHeight+expiry as the last pre-expiry block even though the production IsExpired check uses >=
  • it relied on scheduler timing when asserting that no sign request had happened yet

Make the test assert on stable effects instead of internal channel ownership:

  • create per-test notifier channels in the test context
  • run the manager from a cancellable t.Context-derived context and assert clean shutdown
  • send the actual last pre-expiry height, then the expiry height
  • wait for the expiry sign and publish steps with bounded timeouts
  • verify finalization by waiting for the manager to remove the deposit from activeDeposits instead of racing its private finalization channel

This keeps the test aligned with the production expiry semantics and removes the race that only showed up reliably under -race.

Pull Request Checklist

  • Update release_notes.md if your PR contains major features, breaking changes or bugfixes

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses flaky test failures in the deposit manager by refactoring the test suite to rely on stable, observable effects rather than internal implementation details. By introducing per-test context management and replacing shared global channels with localized ones, the changes ensure that tests are isolated and deterministic, effectively resolving race conditions that were previously triggered under high-concurrency test environments.

Highlights

  • Test Isolation: Removed package-level channels in favor of per-test notifier channels within the test context to prevent cross-test interference.
  • Race Condition Resolution: Replaced reliance on internal manager channels with stable assertions on manager state and bounded timeouts to eliminate race conditions.
  • Lifecycle Management: Updated the manager to run within a cancellable context, ensuring clean shutdown and proper error propagation during tests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors TestManager in staticaddr/deposit/manager_test.go by migrating global test channels into a local context and improving test synchronization with timeouts and context-based cancellation. The review feedback highlights potential deadlocks during the manager's initialization and shutdown phases, and suggests using more robust timeout handling to avoid flakiness in CI environments.

The sqlite and postgres race jobs were both hanging in
deposit.TestManager. The test was observing the manager through
implementation details that were not safe to share with the manager
itself:

- it replaced the manager's internal finalizedDepositChan and then
  waited on the same channel the manager consumes
- it reused package-level block and confirmation channels across runs
- it treated confirmationHeight+expiry as the last pre-expiry block
  even though the production IsExpired check uses >=
- it relied on scheduler timing when asserting that no sign request
  had happened yet

Make the test assert on stable effects instead of internal channel
ownership:

- create per-test notifier channels in the test context
- run the manager from a cancellable t.Context-derived context and
  assert clean shutdown
- send the actual last pre-expiry height, then the expiry height
- wait for the expiry sign and publish steps with bounded timeouts
- verify finalization by waiting for the manager to remove the
  deposit from activeDeposits instead of racing its private
  finalization channel

This keeps the test aligned with the production expiry semantics
and removes the race that only showed up reliably under -race.
@starius starius force-pushed the fix-deposit-test branch from 67f6f30 to 3c49d7c Compare April 6, 2026 04:16
@starius starius marked this pull request as ready for review April 7, 2026 04:53
@hieblmi hieblmi requested review from bhandras and hieblmi April 9, 2026 11:10
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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