mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user