miniredis/redis_test.go
Wojciech Szarański 0dd44a9c73 Change Run() to RunT(t) in tests
Goleak[1] found unclosed goroutines in tests, for example
`miniredis_test.go:TestDump`[2] never calls `s.Close()`
```go
func TestDump(t *testing.T) {
	s, err := Run()
	ok(t, err)
	s.Set("aap", "noot")
	s.Set("vuur", "mies")
// ...
}
```

I've changed `Run()` calls to `RunT(t)` calls to:
 - ensure all goroutines all closed after test is finished
 - we have shorter tests (no need to check for error and close server

There is no risk in using RunT even if test manually closes server
because calling Close multiple times is not an issue.

[1] http://go.uber.org/goleak
[2] 9ac631e686/miniredis_test.go (L88-L129)

Signed-off-by: Wojciech Szarański <wojciech.szaranski@gmail.com>
2024-03-27 19:55:20 +01:00

37 lines
592 B
Go

package miniredis
import (
"sync"
"testing"
"time"
"github.com/alicebob/miniredis/v2/server"
)
func TestRedis(t *testing.T) {
s := RunT(t)
peer := &server.Peer{}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
blocking(s, peer, time.Second, func(p *server.Peer, cc *connCtx) bool {
err := s.Ctx.Err()
if err != nil {
t.Error("blocking call should not retry command when context has error")
return true
}
return false
}, func(p *server.Peer) {
// expect to time out
})
}()
time.Sleep(time.Millisecond * 250)
s.Close()
wg.Wait()
}