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

Capture variables in tests and add logging. #942

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fixchain/ratelimiter/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var testlimits = []int{1, 10, 50, 100, 1000}
func TestRateLimiterSingleThreaded(t *testing.T) {
for i, limit := range testlimits {
t.Run(fmt.Sprintf("%d ops/s", limit), func(t *testing.T) {
i, limit := i, limit
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch.

t.Parallel()
l := NewLimiter(limit)

Expand All @@ -42,13 +43,15 @@ func TestRateLimiterSingleThreaded(t *testing.T) {
if qps > float64(limit)*1.01 {
t.Errorf("#%d: Too many operations per second. Expected ~%d, got %f", i, limit, qps)
}
log.Infof("#%d: Expected ~%d, got %f", i, limit, qps)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is redundant. The expected value is part of the test name, and the qps only needs printing if it's not matching the expected value, which already happens 2 lines above.

Same below.

})
}
}

func TestRateLimiterGoroutines(t *testing.T) {
for i, limit := range testlimits {
t.Run(fmt.Sprintf("%d ops/s", limit), func(t *testing.T) {
i, limit := i, limit
t.Parallel()
l := NewLimiter(limit)

Expand All @@ -71,6 +74,7 @@ func TestRateLimiterGoroutines(t *testing.T) {
if qps > float64(limit)*1.01 {
t.Errorf("#%d: Too many operations per second. Expected ~%d, got %f", i, limit, qps)
}
log.Infof("#%d: Expected ~%d, got %f", i, limit, qps)
})
}
}