github.com/hernad/nomad@v1.6.112/helper/cluster_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package helper 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/shoenig/test/must" 11 ) 12 13 func TestCluster_RandomStagger(t *testing.T) { 14 cases := []struct { 15 name string 16 input time.Duration 17 }{ 18 {name: "positive", input: 1 * time.Second}, 19 {name: "negative", input: -1 * time.Second}, 20 {name: "zero", input: 0}, 21 } 22 23 abs := func(d time.Duration) time.Duration { 24 return Max(d, -d) 25 } 26 27 for _, tc := range cases { 28 result := RandomStagger(tc.input) 29 must.GreaterEq(t, 0, result) 30 must.LessEq(t, abs(tc.input), result) 31 } 32 }