Skip to content
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

refactor(postage): enable parallel test #4656

Closed
wants to merge 2 commits into from

Conversation

ersonp
Copy link

@ersonp ersonp commented Apr 24, 2024

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Enable parallel testing in pkg/postage by adding t.Parallel() to test functions, convert some code to helper functions to fix scope issues, use t.Cleanup() instead of defer in Parallel tests, and remove disable paralleltest on pkg/postage from .golangci.yml.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

closes #3831

Screenshots (if appropriate):

@istae istae requested review from istae, acha-bill and martinconic May 28, 2024 11:39

// tests a valid stamp
t.Run("valid stamp", func(t *testing.T) {
t.Parallel()

owner, signer := generateOwnerAndSigner(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to generate/get owner, signer every time for each test?

Copy link
Author

Choose a reason for hiding this comment

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

If we generate/get owner, signer just once as we were doing before, then the test fails with the following error

ethersphere/bee/v2/pkg/postage

--- FAIL: TestStamperStamping (0.01s)
    --- FAIL: TestStamperStamping/reuse_index_but_get_new_timestamp_for_mutable_or_immutable_batch (0.00s)
        /Users/ersonpereira/Workspace/work/bee/pkg/postage/stamper_test.go:142: expected no error, got owner mismatch
    --- FAIL: TestStamperStamping/valid_stamp (0.00s)
        /Users/ersonpereira/Workspace/work/bee/pkg/postage/stamper_test.go:53: expected no error, got owner mismatch
FAIL
FAIL	github.com/ethersphere/bee/v2/pkg/postage	0.513s
FAIL

So generating owner, signer for each test fixes this issue.

Copy link
Contributor

@acha-bill acha-bill left a comment

Choose a reason for hiding this comment

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

LGTM
+1 for @martinconic's comment

@istae
Copy link
Member

istae commented Nov 29, 2024

we recently parallelized these tests

@istae istae closed this Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enable paralleltest lint check in pkg/postage
4 participants