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

Get rid of internal/clock - Consolidate AfterFunc and Sleep in tests #39

Merged
merged 3 commits into from Nov 10, 2020

Conversation

rabbbit
Copy link
Contributor

@rabbbit rabbbit commented Oct 19, 2020

Resolves #3

Was looking at the open issues and #3 seemed to make sense - it was
also something that I saw in #37 so I thought I'd take a stab.

The reasoning is that less code + smaller interface is a good thing.

During the diff it turned out that:

  • our internal/clock has no tests
  • our internal/clock has at least two bugs:
    • one that I'm fixing here, related to not executing two timers
      if they're scheduled at the "now" boundry
    • one regarding adding time but not having a timer set for that
      specific time (not a problem for us, so not touching it)

By dropping afterFunc into Sleep we're able to deprecate the internal
fork altogether - there is a missing nap in andres-erbsen/clock.AfterFunc
that meant we needed our own fork. Now it's not needed.

internal/clock/clock.go Outdated Show resolved Hide resolved
internal/clock/clock.go Outdated Show resolved Hide resolved
rabbbit added a commit that referenced this pull request Oct 19, 2020
Something that came up in #39 - there's a fair bit of duplication
in the tests. A runner make current setup a bit easier/shorter,
but would make #39 much smaller.

There's no functional changes.
@rabbbit rabbbit mentioned this pull request Oct 19, 2020
rabbbit added a commit that referenced this pull request Oct 26, 2020
Add a test runner

Something that came up in #39 - there's a fair bit of duplication
in the tests. A runner make current setup a bit easier/shorter,
but would make #39 much smaller.

There's no functional changes.
@rabbbit rabbbit force-pushed the pawel/afterfunc branch 3 times, most recently from 0f0117b to 8f0d35a Compare November 1, 2020 02:09
@rabbbit
Copy link
Contributor Author

rabbbit commented Nov 1, 2020

Rebased it on top of #40 and it looks much better now.

I'll raise another PR trying to switch us to andres-erbsen/clock in parallel to make sure we cannot simply do that, without even landing this diff.

@rabbbit
Copy link
Contributor Author

rabbbit commented Nov 1, 2020

Raised #41 to test - verified that:

@cinchurge
Copy link

change overall looks good, but i think we should split it up into 3 separate changes:

  • the bug fix for the boundary check
  • the fix for the race condition
  • removal of AfterFunc along with updates to the test runner

what other work is needed in order to move off of the fork?

@rabbbit
Copy link
Contributor Author

rabbbit commented Nov 10, 2020

change overall looks good, but i think we should split it up into 3 separate changes:

  • the bug fix for the boundary check
  • the fix for the race condition
  • removal of AfterFunc along with updates to the test runner

what other work is needed in order to move off of the fork?

I'm happy to split the fixes, but I won't be adding tests for them - since we're this diff away from removing the fork.

The work needed - if this lands, we can drop the fork.

@rabbbit rabbbit changed the title Get rid of internal/clock #1 - Consolidate AfterFunc and Sleep in tests Get rid of internal/clock - Consolidate AfterFunc and Sleep in tests Nov 10, 2020
Resolves #3

Was looking at the open issues and #3 seemed to make sense - it was
also something that I saw in #37 so I thought I'd take a stab.

The reasoning is that less code + smaller interface is a good thing.

During the diff it turned out that:
- our internal/clock has no tests
- our internal/clock has at least two bugs:
-- one that I'm fixing here, related to not executing two timers
   if they're scheduled at the "now" boundry
-- one regarding adding time but not having a timer set for that
   specific time (not a problem for us, so not touching it)

Looking at the internal/clock, we see:
```
// Forked from github.com/andres-erbsen/clock to isolate a missing nap.
```

There's one extra nap in AfterFunc that I'm removing in this diff,
and so I'm hoping that by removing AfterFunc we'll eventually be able
to move off the fork.
Was untested and contained bugs.
Copy link

@cinchurge cinchurge left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for making the changes!

@rabbbit rabbbit merged commit e86515f into master Nov 10, 2020
@rabbbit rabbbit deleted the pawel/afterfunc branch November 10, 2020 18:57
@rabbbit rabbbit mentioned this pull request Nov 10, 2020
rabbbit pushed a commit that referenced this pull request Jun 6, 2022
Bobjohnson original version seems to be more used (again). Also see history in #39.
storozhukBM added a commit to storozhukBM/ratelimit that referenced this pull request Jun 6, 2022
Bobjohnson original version seems to be more used (again). Also see history in uber-go#39.
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.

Consolidate AfterFunc and Sleep in tests
2 participants