feat: make default autobuild poll intervals configurable (#1618)

* feat: make default poll intervals for autobuild and ssh ttl polling configurable
This commit is contained in:
Cian Johnston
2022-05-20 10:57:02 +00:00
committed by GitHub
parent 992b58389b
commit 52230fab56
6 changed files with 104 additions and 20 deletions
+11
View File
@@ -3,6 +3,7 @@ package cryptorand
import (
"crypto/rand"
"encoding/binary"
"time"
"golang.org/x/xerrors"
)
@@ -193,3 +194,13 @@ func Bool() (bool, error) {
// True if the least significant bit is 1
return i&1 == 1, nil
}
// Duration returns a random time.Duration value
func Duration() (time.Duration, error) {
i, err := Int63()
if err != nil {
return time.Duration(0), err
}
return time.Duration(i), nil
}
+11
View File
@@ -175,3 +175,14 @@ func TestBool(t *testing.T) {
require.True(t, percentage > 48, "expected more than 48 percent of values to be true")
require.True(t, percentage < 52, "expected less than 52 percent of values to be true")
}
func TestDuration(t *testing.T) {
t.Parallel()
for i := 0; i < 20; i++ {
v, err := cryptorand.Duration()
require.NoError(t, err, "unexpected error from Duration")
t.Logf("value: %v <- random?", v)
require.True(t, v >= 0.0, "values must be positive")
}
}