github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/dlock/retry_test.go (about)

     1  package dlock
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestBackoffRetry(t *testing.T) {
     9  	for i := range 5 {
    10  		t.Log("default ex backoff", i, DefaultExponentialBackoffRetry().Next())
    11  	}
    12  	for i := range 5 {
    13  		t.Log("endless linear backoff", i, EndlessRetry(20*time.Millisecond).Next())
    14  	}
    15  	exBackoff := ExponentialBackoffRetry(5, 10*time.Millisecond, 100*time.Millisecond, 0.0, 0.5)
    16  	for i := range 6 {
    17  		t.Log("ex backoff", i, exBackoff.Next())
    18  	}
    19  	exBackoff = ExponentialBackoffRetry(5, 10*time.Millisecond, 100*time.Millisecond, 2.0, 0.5)
    20  	for i := range 6 {
    21  		t.Log("ex backoff2", i, exBackoff.Next())
    22  	}
    23  	limitedRetry := LimitedRetry(20*time.Millisecond, 5)
    24  	for i := range 6 {
    25  		t.Log("limited backoff", i, limitedRetry.Next())
    26  	}
    27  	limitedRetry = LimitedRetry(0, 5)
    28  	for i := range 6 {
    29  		t.Log("limited backoff 2", i, limitedRetry.Next())
    30  	}
    31  }