micro/client/backoff_test.go
Evstigneev Denis 38c5fe8b5a
All checks were successful
test / test (push) Successful in 42s
fixed struct alignment && refactor linter (#369)
## Pull Request template
Please, go through these steps before clicking submit on this PR.

1. Give a descriptive title to your PR.
2. Provide a description of your changes.
3. Make sure you have some relevant tests.
4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable).

**PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING**

Reviewed-on: #369
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
2024-12-09 16:23:25 +03:00

57 lines
963 B
Go

package client
import (
"context"
"testing"
"time"
)
func TestBackoffExp(t *testing.T) {
results := []time.Duration{
0 * time.Second,
100 * time.Millisecond,
600 * time.Millisecond,
1900 * time.Millisecond,
4300 * time.Millisecond,
7900 * time.Millisecond,
}
r := &testRequest{
service: "test",
method: "test",
}
for i := 0; i < 5; i++ {
d, err := BackoffExp(context.TODO(), r, i)
if err != nil {
t.Fatal(err)
}
if d != results[i] {
t.Fatalf("Expected equal than %v, got %v", results[i], d)
}
}
}
func TestBackoffInterval(t *testing.T) {
minTime := 100 * time.Millisecond
maxTime := 300 * time.Millisecond
r := &testRequest{
service: "test",
method: "test",
}
fn := BackoffInterval(minTime, maxTime)
for i := 0; i < 5; i++ {
d, err := fn(context.TODO(), r, i)
if err != nil {
t.Fatal(err)
}
if d < minTime || d > maxTime {
t.Fatalf("Expected %v < %v < %v", minTime, d, maxTime)
}
}
}