Skip to content

Commit

Permalink
Add a retrier function to reduce the numhber of sleeps in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Mar 19, 2019
1 parent 7ba2a45 commit 06b3e0d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tests/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const (
QEDUrl = "http://127.0.0.1:8800"
QEDTLS = "https://localhost:8800"
QEDGossip = "127.0.0.1:8400"
QEDTamperURL = "http://127.0.0.1:18800/"
StoreURL = "http://127.0.0.1:8888/"
AlertsURL = "http://127.0.0.1:8888/"
QEDTamperURL = "http://127.0.0.1:18800"
StoreURL = "http://127.0.0.1:8888"
AlertsURL = "http://127.0.0.1:8888"
APIKey = "my-key"
)

Expand All @@ -69,6 +69,18 @@ func delay(duration time.Duration) scope.TestF {
}
}

func retry(tries int, delay time.Duration, fn func() error) int {
var i int
for i = 0; i < tries; i++ {
err := fn()
if err == nil {
return i
}
time.Sleep(delay)
}
return i
}

func doReq(method string, url, apiKey string, payload *strings.Reader) (*http.Response, error) {
var err error
if payload == nil {
Expand Down Expand Up @@ -98,10 +110,13 @@ func newAgent(id int, name string, role member.Type, p gossip.Processor, t *test
switch role {
case member.Auditor:
agentConf.BindAddr = fmt.Sprintf("127.0.0.1:810%d", id)
agentConf.MetricsAddr = fmt.Sprintf("127.0.0.1:811%d", id)
case member.Monitor:
agentConf.BindAddr = fmt.Sprintf("127.0.0.1:820%d", id)
agentConf.MetricsAddr = fmt.Sprintf("127.0.0.1:821%d", id)
case member.Publisher:
agentConf.BindAddr = fmt.Sprintf("127.0.0.1:830%d", id)
agentConf.MetricsAddr = fmt.Sprintf("127.0.0.1:831%d", id)
}

agentConf.StartJoin = []string{QEDGossip}
Expand Down

0 comments on commit 06b3e0d

Please sign in to comment.