Skip to content

Commit d2be80f

Browse files
committed
use a timeout based read timeout constraint instead 42 attempt
1 parent e557510 commit d2be80f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

random/Make_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package random_test
22

33
import (
4-
"github.com/adamluzsi/testcase/pp"
54
"math/rand"
65
"testing"
76
"time"
@@ -290,7 +289,6 @@ func TestSlice_smoke(t *testing.T) {
290289
rnd := random.New(random.CryptoSeed{})
291290
length := rnd.IntB(1, 5)
292291
slice1 := random.Slice[int](length, rnd.Int)
293-
pp.PP(slice1)
294292
it.Must.Equal(length, len(slice1))
295293
it.Must.NotEmpty(slice1)
296294
it.Must.AnyOf(func(a *assert.AnyOf) {

random/Random.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,19 @@ func (r *Random) Read(p []byte) (n int, err error) {
159159
}
160160

161161
func (r *Random) mustRead(b []byte) {
162-
var err error
163-
for i := 0; i < 42; i++ {
164-
_, err = r.Read(b)
165-
if err == nil {
162+
deadline := time.Now().Add(5 * time.Minute)
163+
for {
164+
n, err := r.Read(b)
165+
if err != nil {
166+
if time.Now().After(deadline) {
167+
panic(err)
168+
}
169+
continue
170+
}
171+
if n == len(b) {
166172
return
167173
}
168174
}
169-
panic(err)
170175
}
171176

172177
func (r *Random) UUID() string {

0 commit comments

Comments
 (0)