File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package ethlike
2+
3+ import (
4+ "context"
5+ "fmt"
6+ "math/big"
7+ "sync"
8+ "time"
9+
10+ "testing"
11+
12+ "github.com/ipfs/go-log"
13+ )
14+
15+ func TestBalanceMonitor_Retries (t * testing.T ) {
16+ log .SetDebugLogging ()
17+
18+ attemptsCount := 0
19+ expectedAttempts := 3
20+
21+ wg := & sync.WaitGroup {}
22+ wg .Add (expectedAttempts )
23+
24+ balanceSource := func (address Address ) (* Token , error ) {
25+ attemptsCount ++
26+ wg .Done ()
27+
28+ if attemptsCount < expectedAttempts {
29+ return nil , fmt .Errorf ("not this time" )
30+ }
31+
32+ return & Token {big .NewInt (10 )}, nil
33+ }
34+
35+ balanceMonitor := NewBalanceMonitor (balanceSource )
36+
37+ address := Address {1 , 2 }
38+ alertThreshold := & Token {big .NewInt (15 )}
39+ tick := 1 * time .Minute
40+ retryTimeout := 5 * time .Second
41+
42+ balanceMonitor .Observe (
43+ context .Background (),
44+ address ,
45+ alertThreshold ,
46+ tick ,
47+ retryTimeout ,
48+ )
49+
50+ wg .Wait ()
51+
52+ if expectedAttempts != attemptsCount {
53+ t .Errorf (
54+ "unexpected retries count\n expected: %d\n actual: %d" ,
55+ expectedAttempts ,
56+ attemptsCount ,
57+ )
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments