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

acc: Use time.Duration to configure testserver delay #2531

Merged
merged 1 commit into from
Mar 21, 2025
Merged

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Mar 20, 2025

Changes

Use time.Duration for the testserver delay. It conveniently zero-initializes, so by default, there is no delay.

Why

The TOML library natively supports time.Duration, so we should use it.

@@ -384,10 +384,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
items := strings.Split(stub.Pattern, " ")
require.Len(t, items, 2)
server.Handle(items[0], items[1], func(req testserver.Request) any {
if stub.DelaySeconds != nil {
time.Sleep(time.Duration((*stub.DelaySeconds) * float64(time.Second)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type-wrangling triggered me to make the change.

// Artificial delay to simulate slow responses.
// Configure as "1ms", "2s", "3m", etc.
// See [time.ParseDuration] for details.
Delay time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

This should still be a pointer, otherwise you cannot override it from child directory with 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can put 0 and it won't sleep then

A negative or zero duration causes Sleep to return immediately.
https://pkg.go.dev/time#Sleep

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'm aware, I'm talking about merge algorithm. See #2369 for context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ServerStub is a list entry, so there is no way to override it.

Also, note that the pattern and response fields are not pointers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I missed the part where it's part of ServerStub, I thought it's a global setting.

@@ -6,4 +6,4 @@ Response.Body = '''
"numProtoSuccess": 2
}
'''
DelaySeconds = 5
Delay = "5s"
Copy link
Contributor

Choose a reason for hiding this comment

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

question - does it need to be changed? Can it still accept plain 5 or 0.01 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it only accepts ints, and ints are nanos (the type of time.Duration).

Copy link
Contributor

@denik denik left a comment

Choose a reason for hiding this comment

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

see comment about pointer

@pietern pietern requested a review from denik March 21, 2025 13:54
@pietern pietern added this pull request to the merge queue Mar 21, 2025
Merged via the queue into main with commit ed88115 Mar 21, 2025
9 checks passed
@pietern pietern deleted the acceptance-delay branch March 21, 2025 16:20
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