github.com/micro/go-micro/v2@v2.9.1/client/backoff_test.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestBackoff(t *testing.T) {
    10  	results := []time.Duration{
    11  		0 * time.Second,
    12  		100 * time.Millisecond,
    13  		600 * time.Millisecond,
    14  		1900 * time.Millisecond,
    15  		4300 * time.Millisecond,
    16  		7900 * time.Millisecond,
    17  	}
    18  
    19  	c := NewClient()
    20  
    21  	for i := 0; i < 5; i++ {
    22  		d, err := exponentialBackoff(context.TODO(), c.NewRequest("test", "test", nil), i)
    23  		if err != nil {
    24  			t.Fatal(err)
    25  		}
    26  
    27  		if d != results[i] {
    28  			t.Fatalf("Expected equal than %v, got %v", results[i], d)
    29  		}
    30  	}
    31  }