-
Notifications
You must be signed in to change notification settings - Fork 253
provider: use synctest for testing time #1136
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
Conversation
|
A quick fly-by comment because I'm still being notified of all the PRs :D What about using https://go.dev/blog/synctest instead of introducing another 3rd party lib? synctest is only out since Go 1.25 so I guess it cannot be introduced right away because of the go-libp2p-kad-dht backwards compatibility promise of the latest two Go versions? Or does such promise not exist (anymore)? |
|
Thanks for the suggestion @dennis-tra, I found a way to run the Adapting tests from The goal is to use |
|
+1 synctest. Technically not fully deterministic, but that's fine. remember we have the ability to create simulated networks: https://github.com/libp2p/go-libp2p/tree/master/x/simlibp2p that work with synctest in case its helpful |
it's not? do you have a link where I can read up on the details? I had read the linked recent blog post and a few other resources but must have missed that detail. |
|
```go
package main
import (
"fmt"
"testing"
"testing/synctest"
)
func TestSyncTest(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
c := make(chan int, 10)
for i := 0; i < 10; i++ {
go func(v int) { c <- v }(i) // capture i
}
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
})
}
```
There's nothing making the goroutine scheduler deterministic. (shown in
example)
There's likely also nothing making rand methods deterministic.
There's also likely no control in how the OS resumes threads.
|
Summary
Refactor tests to usegithub.amrom.workers.dev/coder/quartzinstead ofgithub.amrom.workers.dev/benbjohnson/clockor its forkgithub.amrom.workers.dev/filecoin-project/go-clockRefactor tests to use
testing/synctestinstead ofgithub.amrom.workers.dev/benbjohnson/clock, its forkgithub.amrom.workers.dev/filecoin-project/go-clockorgithub.amrom.workers.dev/coder/quartz.See this blogpost
Benefits