Global sleep function for testing
- Dominant language
- Go
- Stars
- 10
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
`WithSleepFunc` is a great way to test retries without waiting for them, and allows assertions against the requested sleep time 👌🏼
However, threading this through from tests to the retryer can be tricky.
I'd love to be able to set it globally for the duration of a test like this:
```go
func TestRetryingThings(t *testing.T) {
oldSleepFunc := roko.GlobalSleepFunc
roko.GlobalSleepFunc = func(t time.Duration) {}
defer func() { roko.GlobalSleepFunc = nil }()
result := doThingsThatIndirectlyRetry()
// assert things
}
```
Or maybe it can be designed to be `defer`-friendly nested/reentrant-ish:
```go
func TestRetryingThings(t *testing.T) {
revert := roko.WithGlobalSleepFunc(func (t time.Duration) {})
defer revert() // restore whatever the previous global sleep func was
result := doThingsThatIndirectlyRetry()
// assert things
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the existing WithSleepFunc API and the retryer paths that consume it. Define a global or defer-friendly sleep-function API that supports indirect retries and nested restoration, then add tests covering the requested sleep duration and restoration of the previous function.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100