Skip to content

Commit

Permalink
Added wait_before_ms and wait_after_ms as additional parameters in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrode committed Jun 6, 2019
1 parent a8efab0 commit 9318b37
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions api_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/programmfabrik/fylr-apitest/lib/datastore"
"time"

"github.com/programmfabrik/fylr-apitest/lib/datastore"

"github.com/programmfabrik/fylr-apitest/lib/cjson"

"github.com/programmfabrik/fylr-apitest/lib/api"
Expand All @@ -17,10 +18,6 @@ import (
log "github.com/sirupsen/logrus"
)

const (
defaultTimeout int = 10
)

// Case defines the structure of our single testcase
// It gets read in by our config reader at the moment the mainfest.json gets parsed
type Case struct {
Expand All @@ -32,6 +29,8 @@ type Case struct {
StoreResponse map[string]string `json:"store_response_qjson"` // store qjson parsed response in datastore

Timeout int `json:"timeout_ms"`
WaitBefore *int `json:"wait_before_ms"`
WaitAfter *int `json:"wait_after_ms"`
Delay *int `json:"delay_ms"`
BreakResponse []util.GenericJson `json:"break_response"`
CollectResponse util.GenericJson `json:"collect_response"`
Expand Down Expand Up @@ -305,13 +304,16 @@ func (testCase Case) run() (success bool, err error) {

collectPresent := testCase.CollectResponse != nil

if testCase.WaitBefore != nil {
log.Infof("wait_before_ms: %d", *testCase.WaitBefore)
time.Sleep(time.Duration(*testCase.WaitBefore) * time.Millisecond)
}

//Poll repeats the request until the right response is found, or a timeout triggers
for {
// delay between repeating a request
if testCase.Delay != nil {
time.Sleep(time.Duration(*testCase.Delay) * time.Millisecond)
} else {
time.Sleep(time.Duration(defaultTimeout) * time.Millisecond)
}

responsesMatch, request, apiResponse, err = testCase.executeRequest(requestCounter)
Expand Down Expand Up @@ -392,6 +394,11 @@ func (testCase Case) run() (success bool, err error) {
return false, nil
}

if testCase.WaitAfter != nil {
log.Infof("wait_after_ms: %d", *testCase.WaitAfter)
time.Sleep(time.Duration(*testCase.WaitAfter) * time.Millisecond)
}

return true, nil
}

Expand Down

0 comments on commit 9318b37

Please sign in to comment.