Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented May 13, 2025

Migrate test cleanup functions to use Go's built-in t.Cleanup mechanism across test utilities and test files

This change refactors test cleanup handling across multiple test files and utilities to use Go's built-in t.Cleanup mechanism instead of explicitly returning and managing cleanup functions. Key changes include:

  • Modified StartAnvil in anvil.go to use t.Cleanup instead of returning cleanup functions
  • Updated test utility functions in api.go including NewReplicationAPIClient, NewMetadataAPIClient, and NewTestAPIServer to handle cleanup internally
  • Refactored multiple test setup functions across packages to remove explicit cleanup function returns and defer statements
  • Removed TestCleanup test in anvil_test.go as it's no longer relevant with the new cleanup approach

📍Where to Start

Start with the core changes in anvil.go and api.go which define the new cleanup approach that propagates through all other test files.


Macroscope summarized ff36caf.

Summary by CodeRabbit

  • Refactor

    • Simplified test resource cleanup by removing explicit cleanup functions in favor of automatic cleanup registration, streamlining test setup and teardown across multiple test files.
    • Updated various helper and setup function signatures to no longer return cleanup functions.
    • Removed manual deferred cleanup calls in tests, leveraging the testing framework’s built-in cleanup mechanism.
    • Deleted obsolete test code related to manual cleanup handling.
  • Tests

    • Adjusted test logic to use the new automatic cleanup approach, ensuring consistent and reliable resource management during test execution.

@mkysel mkysel requested a review from a team as a code owner May 13, 2025 20:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 13, 2025

## Walkthrough

This change refactors test setup and teardown across multiple packages by removing explicit cleanup functions and defers. Instead, cleanup logic is now registered directly within helper functions using the testing framework's `t.Cleanup` mechanism. This affects test utilities, blockchain, API, indexer, and related test files, simplifying resource management and function signatures.

## Changes

| Files/Group                                                                                       | Change Summary                                                                                                                                                                                                                 |
|-------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| pkg/testutils/anvil/anvil.go, pkg/testutils/anvil/anvil_test.go                                 | `StartAnvil` no longer returns a cleanup function; resource cleanup is registered with `t.Cleanup`. Tests remove cleanup handling and delete the cleanup verification test.                                                   |
| pkg/testutils/api/api.go                                                                        | API client/server creation helpers no longer return cleanup functions or accept context parameters; cleanup is handled internally via `t.Cleanup`. Function signatures updated accordingly.                                   |
| pkg/api/message/newestEnvelope_test.go, pkg/api/message/publish_test.go, pkg/api/query_test.go  | Tests remove capture and invocation of cleanup functions from API client helpers; only necessary values are assigned.                                                                                                         |
| pkg/api/message/subscribe_test.go, pkg/api/metadata/cursor_test.go                              | Test setup helpers' signatures changed to omit cleanup return; all call sites updated to remove deferred cleanup calls.                                                                                                       |
| pkg/api/payer/clientManager_test.go, pkg/api/payer/publish_test.go, pkg/api/payer/service_test.go | Tests and helpers updated to remove explicit cleanup returns and defers; resource cleanup registered with `t.Cleanup` where needed. Helper signatures updated.                                                                |
| pkg/blockchain/blockchainPublisher_test.go, pkg/blockchain/migrator/migrator_test.go            | Helper functions for test setup no longer return cleanup functions; cleanup handled with `t.Cleanup`. Tests updated to remove deferred cleanup calls and variables.                                                            |
| pkg/blockchain/ratesAdmin_test.go, pkg/blockchain/registryCaller_test.go                        | Tests and helpers updated to remove explicit cleanup handling for Anvil or registry helpers; cleanup now handled internally or omitted.                                                                                        |
| pkg/blockchain/registryAdmin_test.go                                                            | `buildRegistry` signature changed to omit cleanup return; context cancellation registered with `t.Cleanup`. Tests updated to remove deferred cleanup.                                                                         |
| pkg/blockchain/rpcLogStreamer_test.go                                                          | Test updated to remove explicit cleanup for Anvil instance; only RPC URL is captured.                                                                                                                                        |
| pkg/indexer/e2e_test.go, pkg/indexer/storer/groupMessage_test.go, pkg/indexer/storer/identityUpdate_test.go | Helper functions and tests updated to remove cleanup returns and deferred calls; context cancellation and resource cleanup handled with `t.Cleanup`.                                    |
| pkg/server/server_test.go                                                                       | API client creation in tests updated to remove context and cleanup handling; only server address is used.                                                                                                                    |
| pkg/testutils/contracts_test.go                                                                | Tests updated to remove cleanup handling for Anvil; only RPC URL is captured.                                                                                                                                                |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Test
    participant HelperFunction
    participant Resource

    Test->>HelperFunction: Call setup helper (e.g., StartAnvil, buildPublisher)
    HelperFunction->>Resource: Allocate resource (e.g., start server/process)
    HelperFunction->>Test: Return resource handle(s)
    HelperFunction->>HelperFunction: Register cleanup with t.Cleanup
    Test->>Resource: Use resource in test
    Note over HelperFunction,Resource: Cleanup is triggered automatically after test via t.Cleanup

Possibly related PRs

  • Update tests to use local anvil #630: Related to test environment setup and cleanup management improvements involving Anvil-based blockchain test environments and explicit cleanup functions.

Suggested reviewers

  • neekolas

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 golangci-lint (1.64.8)</summary>
> 
> Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
> Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->

<!-- announcements_start -->

> [!TIP]
> <details>
> <summary>⚡️ Faster reviews with caching</summary>
> 
> - CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure `Review - Disable Cache` at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the `Data Retention` setting under your Organization Settings.
> 
> Enjoy the performance boost—your workflow just got faster.
> 
> </details>

<!-- announcements_end -->

---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between ff36caf1bc762efb6d857ee97f48ad0e80e7cc44 and 63f405d5cf12d9919490fd5319c3c2ab0a5cf60e.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `pkg/testutils/api/api.go` (6 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* pkg/testutils/api/api.go

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (5)</summary>

* GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
* GitHub Check: Test (Node)
* GitHub Check: Upgrade Tests
* GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
* GitHub Check: Code Review

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcABpIcVwvOkgAIgBZeCIqGgiQxmjMbG5IADNsDDF4fAxkAkhsRBJIAHF8AHIZbHgvXDB4LE0AYUyMbMg2BlhMJGZ0Bgp8RDL0vBb1eGl0DHoaRFw8lulQ2MgAdzRkBwFmdRp6OQqqvmYAa1kq30PrOz7mAUpIAHYADgBODQwWDVIaYUh+Ei5NBifAUMrAyDDFZeDpEfi5NLrDIkLI5fKFcQleGTbBEWD4PADbzibjRTEbXJbZCYehzFHiJYdCIIphKASHEiAgCSpRoaHo+AxJAAHrT4Ax1F55P5cNgKBhUct6MxMGgiJqGL1+viikTwrgEWtcMgMPg9pBolIqOC6o1IAJmq12lgAAbdI3cH0DURI0YRfCIll0w04vo5Do0dVoHyyDRGADSJHkzEU8EZDGoxVKKEKXmwSgq3FohYwaIt1R9AGVcM5cABBDASFpBk2ErBcn2YLteDREfBB8qVBv+2PZIMpYF8C2YCGq9UGgN5Aqm0qAxvwU5eZxK82zcTs+S9ovIAdobjwUfj+zYIboZA+gByJD2NhIcoLfZtlYQo9IsGC4D64Sft+8QkC21YtkBIEouwkFapA0F7NAIRIY2lBOkGeyUCCSKkKsEY6hgeogpuCaUFRKb7OosAYTOuI+oCcDVP4UIwnwMo0CsZQUdS8C0tUVr2HBxrbn2zITFMyASM4xSVDw0K3NRiDhP4OZdrWkAy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7pt/WJUW/jZ0EEOdqinraVmPUra1dd26XrFQO234tdou9AhDr12Y6pdYeHHcJPDWBrGlDdXkb0ocH+iBl9VYMcXkhW4AXVtIfAFO35JUAxAhs8+KHofiyAWJZwpskuNS5PzghOKnPqh00IScmu3A5lr/1o4BQBAACj8fQNWAaz9qaqbWevzU4adENyKRrLZFVbVBU5pXSEQbHXXlAcB+WHdU90qhzDci9XHVrXDz5Uq1GJCJTKXxU6175wCLAYuhD4EDU82UmMcq3KM5wiCmb1EsP3JiKR6shSgMPbIFg7CZhtZczRCDKLAQ1u5KI4pFaoizzzdpcE+1RjUdURKjBr7N2B7GEW8y/Yvu4uKHDLhoAK4DvF5YUQThqAG4KcZuF/rZiiYYo0kxADFEPQkxaAMUcKanFbhQBg6AAZgABsBYXIM4QEAMAvguB6wbkAEC4HaAPwAAKxfBmUfwL4LkAAAsPwcUAAAYSAPwTg18AYAMBmDzBpuIYC/24HsDLB9gzQdoA0GGAhBzwrQD+B/BnCfwZg38HYO5ApD2BpQwwGwMMBPCKgdg2gGkO5BcDnBoQ8YHTj/71A8BkRUgcIwoGYo2RfQEAA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=xmtp/xmtpd&utm_content=789):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@graphite-app
Copy link

graphite-app bot commented May 13, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@mkysel mkysel changed the title Less cleanups Migrate test cleanup functions to use Go's built-in t.Cleanup mechanism across test utilities and test files May 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/testutils/api/api.go (1)

57-74: Consider refactoring NewPayerAPIClient to use t.Cleanup for consistency.

While other API client creation functions have been refactored to use t.Cleanup, NewPayerAPIClient still returns a cleanup function. For consistency, consider updating this function to match the pattern used in NewReplicationAPIClient and NewMetadataAPIClient.

-func NewPayerAPIClient(
-	t *testing.T,
-	ctx context.Context,
-	addr string,
-) (payer_api.PayerApiClient, func()) {
+func NewPayerAPIClient(
+	t *testing.T,
+	addr string,
+) payer_api.PayerApiClient {
 	dialAddr := fmt.Sprintf("passthrough://localhost/%s", addr)
 	conn, err := grpc.NewClient(
 		dialAddr,
 		grpc.WithTransportCredentials(insecure.NewCredentials()),
 		grpc.WithDefaultCallOptions(),
 	)
 	require.NoError(t, err)
 	client := payer_api.NewPayerApiClient(conn)
-	return client, func() {
-		err := conn.Close()
-		require.NoError(t, err)
-	}
+	t.Cleanup(func() {
+		require.NoError(t, conn.Close())
+	})
+	return client
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 891557f and ff36caf.

📒 Files selected for processing (22)
  • pkg/api/message/newestEnvelope_test.go (1 hunks)
  • pkg/api/message/publish_test.go (11 hunks)
  • pkg/api/message/subscribe_test.go (9 hunks)
  • pkg/api/metadata/cursor_test.go (4 hunks)
  • pkg/api/payer/clientManager_test.go (1 hunks)
  • pkg/api/payer/publish_test.go (3 hunks)
  • pkg/api/payer/service_test.go (1 hunks)
  • pkg/api/query_test.go (10 hunks)
  • pkg/blockchain/blockchainPublisher_test.go (5 hunks)
  • pkg/blockchain/migrator/migrator_test.go (7 hunks)
  • pkg/blockchain/ratesAdmin_test.go (1 hunks)
  • pkg/blockchain/registryAdmin_test.go (5 hunks)
  • pkg/blockchain/registryCaller_test.go (3 hunks)
  • pkg/blockchain/rpcLogStreamer_test.go (1 hunks)
  • pkg/indexer/e2e_test.go (3 hunks)
  • pkg/indexer/storer/groupMessage_test.go (4 hunks)
  • pkg/indexer/storer/identityUpdate_test.go (3 hunks)
  • pkg/server/server_test.go (2 hunks)
  • pkg/testutils/anvil/anvil.go (2 hunks)
  • pkg/testutils/anvil/anvil_test.go (2 hunks)
  • pkg/testutils/api/api.go (6 hunks)
  • pkg/testutils/contracts_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (16)
pkg/blockchain/rpcLogStreamer_test.go (1)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/api/message/newestEnvelope_test.go (1)
pkg/testutils/api/api.go (1)
  • NewTestReplicationAPIClient (213-219)
pkg/blockchain/ratesAdmin_test.go (1)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/testutils/contracts_test.go (2)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/testutils/contracts.go (1)
  • DeployNodesContract (178-180)
pkg/api/message/publish_test.go (1)
pkg/testutils/api/api.go (1)
  • NewTestReplicationAPIClient (213-219)
pkg/server/server_test.go (1)
pkg/testutils/api/api.go (1)
  • NewReplicationAPIClient (38-55)
pkg/testutils/anvil/anvil_test.go (1)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/api/payer/clientManager_test.go (1)
pkg/testutils/api/api.go (1)
  • NewTestAPIServer (100-211)
pkg/blockchain/registryAdmin_test.go (4)
pkg/blockchain/registryAdmin.go (1)
  • INodeRegistryAdmin (20-34)
pkg/blockchain/registryCaller.go (1)
  • INodeRegistryCaller (15-19)
pkg/testutils/log.go (1)
  • NewLog (17-25)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/indexer/storer/groupMessage_test.go (4)
pkg/indexer/storer/groupMessage.go (1)
  • GroupMessageStorer (23-27)
pkg/testutils/store.go (1)
  • NewDB (65-70)
pkg/db/queries/db.go (1)
  • New (19-21)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/indexer/e2e_test.go (4)
pkg/db/queries/db.go (2)
  • Queries (23-25)
  • New (19-21)
pkg/testutils/log.go (1)
  • NewLog (17-25)
pkg/testutils/store.go (1)
  • NewDB (65-70)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/api/query_test.go (1)
pkg/testutils/api/api.go (1)
  • NewTestReplicationAPIClient (213-219)
pkg/indexer/storer/identityUpdate_test.go (4)
pkg/indexer/storer/identityUpdate.go (1)
  • IdentityUpdateStorer (32-37)
pkg/mocks/mlsvalidate/mock_MLSValidationService.go (1)
  • MockMLSValidationService (19-21)
pkg/testutils/store.go (1)
  • NewDB (65-70)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/api/message/subscribe_test.go (1)
pkg/testutils/api/api.go (2)
  • ApiServerMocks (94-98)
  • NewTestReplicationAPIClient (213-219)
pkg/blockchain/migrator/migrator_test.go (4)
pkg/blockchain/registryAdmin.go (1)
  • INodeRegistryAdmin (20-34)
pkg/blockchain/registryCaller.go (1)
  • INodeRegistryCaller (15-19)
pkg/testutils/log.go (1)
  • NewLog (17-25)
pkg/testutils/anvil/anvil.go (1)
  • StartAnvil (48-77)
pkg/testutils/api/api.go (1)
pkg/api/server.go (1)
  • ApiServer (29-36)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Code Review
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Test (Node)
  • GitHub Check: Upgrade Tests
🔇 Additional comments (78)
pkg/api/payer/service_test.go (1)

68-68: Code cleanup improvement - good!

The change removes the explicit cleanup function return value from buildPayerService, which is part of a broader refactoring pattern across the codebase. Instead of requiring callers to explicitly defer cleanup functions, the cleanup is now registered directly with t.Cleanup() in the helper function, which simplifies test code and ensures proper resource cleanup.

pkg/blockchain/registryCaller_test.go (4)

10-10: Simplified test cleanup - LGTM

The signature of buildRegistry function has been updated to no longer return a cleanup function. This is part of a codebase-wide refactoring to register cleanup handlers with t.Cleanup() inside the helper functions rather than requiring explicit deferred cleanup calls in tests.


20-20: Consistent change pattern - LGTM

The removal of the cleanup function return value from buildRegistry has been applied consistently throughout all test functions, making the test code cleaner and less prone to cleanup errors.


30-30: Good refactoring consistency

The pattern of removing explicit cleanup functions is consistently applied here, simplifying the test code while still ensuring proper resource cleanup through t.Cleanup().


37-37: Refactoring completed correctly

The change is consistent with the overall refactoring pattern, removing the cleanup return value while preserving the necessary test functionality.

pkg/blockchain/ratesAdmin_test.go (1)

19-19: Improved cleanup management - LGTM

The StartAnvil function no longer returns a cleanup function that needs to be deferred. Instead, as shown in the relevant code snippet, it now registers the cleanup directly with t.Cleanup() internally:

t.Cleanup(func() {
    _ = cmd.Process.Kill()
    _ = cmd.Wait()
})

This is a good improvement to simplify test resource management.

pkg/api/message/publish_test.go (2)

25-25: Simplified test cleanup pattern - LGTM

The test helper function NewTestReplicationAPIClient has been updated to no longer return a cleanup function. Instead, cleanup is now handled internally via t.Cleanup(), which simplifies the test code by removing the need for explicit deferred cleanup calls.


81-81: Consistent cleanup simplification applied throughout

The pattern of removing explicit cleanup functions has been consistently applied throughout all test functions in this file. This is part of a codebase-wide refactoring to simplify resource management by embedding cleanup logic within the test lifecycle using t.Cleanup().

Also applies to: 98-98, 121-121, 138-138, 158-158, 202-202, 241-241, 281-281, 298-298, 342-342

pkg/blockchain/rpcLogStreamer_test.go (1)

48-48: Clean refactoring of resource management

The code now relies on t.Cleanup registration within the StartAnvil function instead of explicitly handling the cleanup function in the test. This is consistent with the broader cleanup simplification across the codebase.

pkg/testutils/contracts_test.go (2)

12-12: Simplified resource cleanup pattern

The refactoring removes the explicit cleanup function return value and deferred cleanup call, relying instead on internal cleanup registration in the StartAnvil function. This improves code clarity and reduces boilerplate.


18-18: Consistent cleanup approach applied

This change follows the same pattern of relying on automatic cleanup registration, making the test code more concise and less error-prone.

pkg/api/message/newestEnvelope_test.go (1)

64-64: Streamlined API client creation

The code now captures only three return values from NewTestReplicationAPIClient, discarding the cleanup function that was previously returned. Resource cleanup is now handled internally via t.Cleanup in the helper function, eliminating the need for explicit cleanup handling in tests.

pkg/api/query_test.go (2)

84-84: Standardized cleanup management

The test now relies on automated cleanup registration within NewTestReplicationAPIClient instead of explicitly handling cleanup. This simplifies test code and avoids potential resource leaks.


99-99: Consistent cleanup pattern applied throughout the file

All test cases have been refactored to follow the same pattern of omitting explicit cleanup functions, relying instead on the testing framework's built-in cleanup mechanism. This improves code consistency and maintainability.

Also applies to: 114-114, 132-132, 150-150, 167-167, 187-187, 207-207, 227-227, 244-244

pkg/server/server_test.go (2)

140-141: Cleanup management simplified through internal t.Cleanup

The code now uses the testing framework's built-in cleanup mechanism instead of returning and deferring explicit cleanup functions. This is a good improvement as it reduces boilerplate and makes tests less prone to resource leaks.


251-251: Clean API client creation without explicit cleanup

This change is consistent with the pattern applied throughout the codebase, removing the need to manage cleanup functions manually and instead relying on the testing framework's automatic resource management.

pkg/api/payer/clientManager_test.go (1)

25-26: Test server creation simplified with implicit cleanup

The test server creation no longer returns cleanup functions that need to be manually deferred. Instead, cleanup is registered internally with t.Cleanup() in the NewTestAPIServer function, as seen in the provided snippet from pkg/testutils/api/api.go. This makes the test code cleaner and more maintainable.

pkg/api/metadata/cursor_test.go (4)

28-31: Helper function signature simplified by removing cleanup function

The setupTest function no longer returns a cleanup function, aligning with the pattern of using t.Cleanup() within helper functions. The function signature is cleaner and the responsibility for cleanup is correctly handled by the test utilities.


89-89: Return statement simplified without cleanup function

This change completes the refactoring of the setupTest function by removing the cleanup function from the return values.


106-106: Test setup call no longer needs to defer cleanup

The test now correctly relies on the internal cleanup mechanism registered by NewTestMetadataAPIClient, removing the need for explicit cleanup handling.


146-146: Consistent cleanup approach in all test functions

Like the previous test function, this one also benefits from the simplified setup without manual cleanup handling.

pkg/indexer/storer/groupMessage_test.go (6)

21-24: Refactored helper function with improved cleanup management

The buildGroupMessageStorer function now registers context cancellation directly with t.Cleanup() rather than returning a cleanup function. This is a cleaner approach that ensures resources are properly released even if tests fail.


26-26: Anvil test environment with internal cleanup

The call to anvil.StartAnvil no longer requires capturing a cleanup function since the function now handles cleanup internally using t.Cleanup(). According to the relevant snippet, this ensures the Anvil process is properly terminated when the test completes.


43-43: Simplified return statement without cleanup function

The function now returns only the storer instance since cleanup is handled internally via the testing framework.


48-48: Test call without explicit cleanup handling

The test now uses the simplified helper function which internally registers cleanup tasks, removing the need for deferred cleanup calls in the test function itself.


89-89: Consistent use of internal cleanup in another test function

This test also benefits from the simplified helper function with internal cleanup registration.


123-123: Consistent cleanup approach across all test functions

The same pattern is applied throughout the test file, ensuring a consistent approach to resource management.

pkg/testutils/anvil/anvil.go (2)

47-48: Function signature simplified to use Go's testing cleanup feature.

The function signature now correctly reflects that StartAnvil returns only the URL string, removing the explicit cleanup function return.


71-76: Good use of the t.Cleanup pattern.

This change leverages Go's testing framework's built-in cleanup mechanism. Using t.Cleanup ensures that resources are properly released when tests complete, even if they fail or panic. This approach is more maintainable and less error-prone than returning explicit cleanup functions.

pkg/testutils/anvil/anvil_test.go (3)

12-12: Test code simplified by removing manual cleanup handling.

The test now correctly uses the updated StartAnvil function which internally registers cleanup with t.Cleanup.


26-29: Struct simplified by removing unnecessary cleanup field.

Cleanup is now handled by the testing framework via t.Cleanup in the StartAnvil function, so the struct no longer needs to store the cleanup function.


35-37: Simplified concurrent test setup by eliminating manual cleanup.

This change reflects the updated StartAnvil function signature and reduces the complexity of concurrent test management by removing manual cleanup handling.

pkg/blockchain/registryAdmin_test.go (10)

14-16: Simplified function signature by removing explicit cleanup return.

The function signature has been updated to remove the explicit cleanup function return, aligning with the pattern of using t.Cleanup for resource management.


18-18: Added proper context cancellation using t.Cleanup.

This change ensures that the context is properly cancelled when the test completes, preventing potential resource leaks.


20-20: Updated StartAnvil usage to match new signature.

The code now correctly uses the updated StartAnvil function which no longer returns a cleanup function.


41-42: Simplified return by removing explicit cleanup function.

The function now returns only the registry, caller, and context, as cleanup is handled internally via t.Cleanup.


67-68: Updated function call to match new buildRegistry signature.

This test now correctly uses the updated buildRegistry function signature, removing the need for explicit cleanup handling.


84-85: Updated function call to match new buildRegistry signature.

Test properly updated to use the simplified function signature.


90-91: Updated function call to match new buildRegistry signature.

Test properly updated to use the simplified function signature.


100-101: Updated function call to match new buildRegistry signature.

Test properly updated to use the simplified function signature.


107-108: Updated function call to match new buildRegistry signature.

Test properly updated to use the simplified function signature.


114-115: Updated function call to match new buildRegistry signature.

Test properly updated to use the simplified function signature.

pkg/blockchain/migrator/migrator_test.go (9)

17-19: Simplified function signature by removing explicit cleanup return.

The function signature has been updated to remove the explicit cleanup function return, aligning with the pattern of using t.Cleanup for resource management.


21-23: Added proper context cancellation using t.Cleanup.

This change ensures that the context is properly cancelled when the test completes, preventing potential resource leaks.


25-25: Updated StartAnvil usage to match new signature.

The code now correctly uses the updated StartAnvil function which no longer returns a cleanup function.


36-38: Added client cleanup using t.Cleanup.

This change ensures that the blockchain client is properly closed when the test completes, preventing potential resource leaks from unclosed connections.


56-57: Simplified return by removing explicit cleanup function.

The function now returns only the registry objects, as cleanup is handled internally via t.Cleanup. This simplifies the interface and reduces the burden on callers.


80-81: Updated function call to match new setupRegistry signature.

Test properly updated to use the simplified function signature.


103-104: Updated function call to match new setupRegistry signature.

Test properly updated to use the simplified function signature.


125-126: Updated function call to match new setupRegistry signature.

Test properly updated to use the simplified function signature.


134-135: Updated function call to match new setupRegistry signature.

Test properly updated to use the simplified function signature.

pkg/blockchain/blockchainPublisher_test.go (7)

15-17: Clean and improved test helper signature

The function now uses t.Cleanup(cancel) to automatically handle context cancellation rather than returning a cleanup function. This makes the API simpler and reduces the risk of forgetting to call cleanup functions.


19-19: Proper usage of the updated anvil.StartAnvil

The function correctly uses the updated anvil.StartAnvil which now handles its own cleanup through t.Cleanup() internally, simplifying this code.


40-42: Good resource management with t.Cleanup

Using t.Cleanup to close the client ensures resources are properly released when the test completes, regardless of whether the test passes or fails.


56-57: Simplified return statement

The return statement now only returns the publisher object without a cleanup function, improving readability and usability.


60-61: Cleaner test setup

Test now simply calls buildPublisher without having to manage cleanup, improving readability and reducing boilerplate.


115-116: Consistent application of cleanup pattern

Same clean pattern applied here as in the previous test.


167-168: Consistent cleanup pattern in concurrent test

The concurrent test also benefits from the simplified setup without explicit cleanup.

pkg/indexer/e2e_test.go (4)

24-28: Improved function signature with implicit cleanup

The function signature is cleaner now, returning only the necessary objects without the cleanup function. The cleanup is properly registered with t.Cleanup(cancel) to ensure resources are released when the test completes.


32-33: Simplified anvil usage

Properly uses the updated anvil.StartAnvil function which now handles its own cleanup through t.Cleanup() internally.


49-50: Streamlined return values

The function now returns only the essential objects needed by the test, making it clearer what the function provides.


85-86: Cleaner test setup

The test now has a more straightforward setup without needing to manage cleanup explicitly, improving readability.

pkg/indexer/storer/identityUpdate_test.go (5)

24-28: Improved test helper signature with automatic cleanup

The function signature has been simplified by removing the cleanup function return. Context cancellation is now properly registered with t.Cleanup(), ensuring resources are cleaned up automatically when the test completes.


30-31: Simplified anvil initialization

Correctly uses the updated anvil.StartAnvil function which now handles its own cleanup internally, eliminating the need for explicit cleanup management.


48-49: Cleaner return statement

The function now returns only the storer and validation service without a cleanup function, simplifying the API and improving readability.


53-54: Streamlined test setup

Test now simply calls buildIdentityUpdateStorer without needing to capture or defer a cleanup function, reducing boilerplate code.


111-112: Consistent cleanup pattern application

The same cleanup pattern is consistently applied throughout the tests, ensuring all use the simplified approach.

pkg/api/message/subscribe_test.go (4)

28-31: Streamlined test setup function

The function signature has been simplified by removing the cleanup function return. The code now properly relies on t.Cleanup registrations within the NewTestReplicationAPIClient helper, improving code clarity.


89-90: Cleaner return statement

The function now returns only the necessary API client, database handle, and mocks without an explicit cleanup function, simplifying the API.


128-129: Simplified test implementation

Test now calls setupTest without capturing or deferring a cleanup function, making the test code more concise and easier to read.


148-149: Consistent cleanup pattern across all tests

The cleanup pattern is consistently applied throughout all test functions, ensuring a uniform approach to resource management.

Also applies to: 169-170, 190-191, 232-233, 253-254, 274-275

pkg/api/payer/publish_test.go (3)

69-97: Good refactoring to use t.Cleanup instead of returning a cleanup function.

The function signature has been simplified by removing the return of a cleanup function, and instead using t.Cleanup(cancel) to register the context cancellation. This is a cleaner approach that leverages Go's testing framework for automatic resource cleanup.


101-102: Clean update to the test call site.

The call to buildPayerService has been correctly updated to no longer capture or defer a cleanup function, matching the function's new signature.


176-180: Consistent application of the cleanup pattern.

Both the NewTestAPIServer and buildPayerService calls have been updated to no longer capture or defer cleanup functions, maintaining consistency with the new approach of using t.Cleanup internally.

pkg/testutils/api/api.go (4)

38-55: Excellent use of t.Cleanup for connection management.

The function has been refactored to no longer return a cleanup function, instead using t.Cleanup to register connection closure. This simplifies the function's interface and ensures cleanup happens automatically when the test completes.


76-92: Good refactoring to use t.Cleanup for connection management.

Similar to NewReplicationAPIClient, this function now uses t.Cleanup to handle connection closure automatically, resulting in cleaner test code.


100-211: Good refactoring of NewTestAPIServer to use t.Cleanup.

The function has been updated to register server shutdown and context cancellation with t.Cleanup instead of returning a cleanup function. This is a cleaner approach that automatically handles resource cleanup when tests complete.


213-227: Clean updates to test client creation functions.

Both NewTestReplicationAPIClient and NewTestMetadataAPIClient have been correctly updated to no longer capture or defer cleanup functions, relying instead on the internal t.Cleanup calls. This results in simpler, more maintainable test code.

Copy link
Contributor

@neekolas neekolas left a comment

Choose a reason for hiding this comment

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

Go 1.24 FTW

@macroscopeapp
Copy link

macroscopeapp bot commented May 13, 2025

Modernize test cleanup by migrating test utility functions to use Go's built-in t.Cleanup mechanism

Refactors test utilities and test files across the codebase to leverage Go's built-in t.Cleanup mechanism instead of explicit cleanup functions. Key changes include:

  • Modifies core test utilities in anvil.go and api.go to register cleanup handlers directly using t.Cleanup rather than returning cleanup functions
  • Updates test helper functions like buildRegistry, buildPublisher, and setupTest across multiple packages to remove cleanup function returns
  • Removes explicit cleanup handling (defer cleanup()) from test functions in favor of automatic cleanup registration
  • Adjusts function signatures throughout test files to remove cleanup function parameters and returns

📍Where to Start

Start with the core test utility changes in anvil.go and api.go, as these define the new cleanup pattern that propagates through all other test files.


Macroscope summarized 63f405d.

@mkysel mkysel merged commit e5c6594 into main May 13, 2025
9 checks passed
@mkysel mkysel deleted the mkysel/less-cleanups branch May 13, 2025 20:33
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.

3 participants