Skip to content

multi: Various test improvements.#3612

Merged
davecgh merged 3 commits intodecred:masterfrom
jholdstock:tests
Feb 5, 2026
Merged

multi: Various test improvements.#3612
davecgh merged 3 commits intodecred:masterfrom
jholdstock:tests

Conversation

@jholdstock
Copy link
Member

Making use of t.Context and t.Cleanup to make some minor improvements to existing tests. Took inspiration from decred/dcrdex#3491 and then got carried away making further changes.

The Context returned by t.Context() is automatically canceled when tests
complete, (before cleanup-registered functions are called), therefore
manually creating and closing a func is not required.
The directories created by t.TempDir are always new and unique, and are
automatically deleted after the tests complete, therefore manually
deleting them before/after tests is not required.
Making effective use of t.Cleanup removes the need for test helper
functions to return teardown callbacks, and allows the teardown to exist
in just one place.
@davecgh davecgh changed the title Various test improvements multi: Various test improvements. Feb 5, 2026
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

I was worried about the fact t.Context wasn't introduced until Go 1.24, but it's only being done in the internal packages which require that now, so no issue there.

It really doesn't matter for any of this code, but one short line is cleaner than two.

Thanks for the PR!

@davecgh davecgh added this to the 2.2.0 milestone Feb 5, 2026
@davecgh davecgh merged commit 8a8791f into decred:master Feb 5, 2026
34 checks passed
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