Skip to content

Commit

Permalink
Merge pull request #4 from spirt-t/master
Browse files Browse the repository at this point in the history
fix for loop in prepare: add prepare attempts limit
  • Loading branch information
Tonsofattraction authored Jul 30, 2021
2 parents 5025876 + e84f990 commit 3f3a73c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tankapi/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
)

const (
createBreakpoint = "init"
prepareBreakpoint = "start"
prepareTryTimeout = time.Minute * 2
createBreakpoint = "init"
prepareBreakpoint = "start"
prepareTryTimeout = time.Minute
prepareAttemptsLimit = 4
)

var dialTimeout, tlsHandshakeTimeout, netClientTimeout time.Duration
Expand Down Expand Up @@ -185,6 +186,7 @@ func (s *Session) create() (err error) {
// prepare - goroutine that prepares single tank, checks if failed.
// if session has no name yet, starts a new one with "start" breakpoint
func (s *Session) prepare() (err error) {
start := time.Now()
err = s.checkTank()
if err != nil {
return
Expand All @@ -194,19 +196,21 @@ func (s *Session) prepare() (err error) {
if err != nil {
return
}
fmt.Println(s.Name)
}

var resp *http.Response
try := time.Duration(0)
var longing time.Duration
j := 0
for {
resp, err = netClient.Get(fmt.Sprintf("%v/run?session=%v&break=%v", s.Tank.Url, s.Name, prepareBreakpoint))
if err == nil {
break
}

log.Printf("http.POST failed: %v", err)
try += netClientTimeout
if try >= prepareTryTimeout {
longing = time.Now().Sub(start)
j++
if longing >= prepareTryTimeout || j >= prepareAttemptsLimit {
s.setFailed([]string{fmt.Sprintf("http.POST failed: %v", err)})
return
}
Expand Down

0 comments on commit 3f3a73c

Please sign in to comment.