This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
simplify TimeLimiter, fixing its tests #1088
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
* previous implementation was a bit hastily implemented and much more complicated than needed: trying to support concurrency but not doing it well, while we don't actually need any of it. * unit testing was very flakey, in particular in circleCI there's lots of timing inaccuracy leading to broken tests * it was inaccurate, for shortlived operations it would be negligible but for longer operations it is not. While our use case operations should be short, it is nice to be able to fix this while we're at it. So now we simplify the design a lot, basically reduce it to a non-concurrent accounting structure, removing all channels, goroutines and context, making the accounting more correct and the testing more robust.
Dieterbe
force-pushed
the
fix-time-limiter
branch
from
October 10, 2018 09:35
ab9d95d
to
8dab8f0
Compare
Dieterbe
changed the title
WIP: simplify TimeLimiter, fixing its tests
simplify TimeLimiter, fixing its tests
Oct 10, 2018
this fixes borken tests like
e.g. as seen in unrelated PR's such as #1021 |
contrary to what i said in #1087 I now think we shouldn't add benchmarks to this, because:
|
woodsaj
reviewed
Oct 18, 2018
idx/memory/time_limit.go
Outdated
// NewTimeLimiter creates a new TimeLimiter. | ||
func NewTimeLimiter(window, limit time.Duration, now time.Time) *TimeLimiter { | ||
if limit > window { | ||
panic(fmt.Sprintf("NewTimeLimiter: invalid configuration. limit %s does not fit within window %s", limit, window)) |
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.
dont panic, return an error. Let the caller decide if they want to panic or not.
Dieterbe
force-pushed
the
fix-time-limiter
branch
from
October 21, 2018 19:51
6637e03
to
d2552ec
Compare
@woodsaj PTAL |
woodsaj
approved these changes
Oct 23, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
much more complicated than needed:
trying to support concurrency but not doing it well, while
we don't actually need any of it.
lots of timing inaccuracy leading to broken tests
but for longer operations it is not. While our use case operations
should be short, it is nice to be able to fix this while we're at it.
So now we simplify the design a lot, basically reduce it to
a non-concurrent accounting structure, removing all channels,
goroutines and context, making the accounting more correct
and the testing more robust.