Files
tasks/common/backoff/jitter_test.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

87 lines
2.0 KiB
Go

package backoff
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type (
jitterSuite struct {
suite.Suite
}
)
func TestJitterSuite(t *testing.T) {
s := new(jitterSuite)
suite.Run(t, s)
}
func (s *jitterSuite) SetupSuite() {
}
func (s *jitterSuite) TestJitter_Int64() {
input := int64(1048576)
coefficient := float64(0.25)
lowerBound := int64(float64(input) * (1 - coefficient))
upperBound := int64(float64(input) * (1 + coefficient))
for i := 0; i < 1048576; i++ {
result := Jitter(input, coefficient)
s.True(result >= lowerBound)
s.True(result < upperBound)
result = FullJitter(input)
s.True(result >= 0)
s.True(result < input)
}
}
func (s *jitterSuite) TestJitter_Float64() {
input := float64(1048576.1048576)
coefficient := float64(0.16)
lowerBound := float64(input) * (1 - coefficient)
upperBound := float64(input) * (1 + coefficient)
for i := 0; i < 1048576; i++ {
result := Jitter(input, coefficient)
s.True(result >= lowerBound)
s.True(result < upperBound)
result = FullJitter(input)
s.True(result >= 0)
s.True(result < input)
}
}
func (s *jitterSuite) TestJitter_Duration() {
input := time.Duration(1099511627776)
coefficient := float64(0.1)
lowerBound := time.Duration(int64(float64(input.Nanoseconds()) * (1 - coefficient)))
upperBound := time.Duration(int64(float64(input.Nanoseconds()) * (1 + coefficient)))
for i := 0; i < 1048576; i++ {
result := Jitter(input, coefficient)
s.True(result >= lowerBound)
s.True(result < upperBound)
result = FullJitter(input)
s.True(result >= 0)
s.True(result < input)
}
}
func (s *jitterSuite) TestJitter_InputZeroValue() {
s.Zero(Jitter(time.Duration(0), rand.Float64()))
s.Zero(Jitter(int64(0), rand.Float64()))
s.Zero(Jitter(float64(0), rand.Float64()))
}
func (s *jitterSuite) TestJitter_CoeffientZeroValue() {
s.Equal(time.Duration(1), Jitter(time.Duration(1), 0))
s.Equal(int64(1), Jitter(int64(1), 0))
s.Equal(float64(1), Jitter(float64(1), 0))
}