-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
@@ -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))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
).
There was a problem hiding this 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
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.