Skip to content

Commit

Permalink
chore: refine chaos test (#3491)
Browse files Browse the repository at this point in the history
* chore: refine chaos test

Signed-off-by: yiyiyimu <[email protected]>
  • Loading branch information
Yiyiyimu authored Feb 3, 2021
1 parent 436beab commit 68c4fd5
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions t/chaos/kill-etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func getIngressBandwidthPerSecond(e *httpexpect.Expect, g *WithT) float64 {
// so need to calculate the duration
timeStart := time.Now()

time.Sleep(10 * time.Second)
time.Sleep(1 * time.Second)
bandWidthString = getPrometheusMetric(e, g, key)
bandWidthEnd, err := strconv.ParseFloat(bandWidthString, 64)
g.Expect(err).To(BeNil())
Expand All @@ -184,10 +184,34 @@ func roughCompare(a float64, b float64) bool {
return false
}

type silentPrinter struct {
logger httpexpect.Logger
}

func newSilentPrinter(logger httpexpect.Logger) silentPrinter {
return silentPrinter{logger}
}

// Request implements Printer.Request.
func (p silentPrinter) Request(req *http.Request) {
}

// Response implements Printer.Response.
func (silentPrinter) Response(*http.Response, time.Duration) {
}

func TestGetSuccessWhenEtcdKilled(t *testing.T) {
g := NewWithT(t)
e := httpexpect.New(t, host)

eSilent := httpexpect.WithConfig(httpexpect.Config{
BaseURL: host,
Reporter: httpexpect.NewAssertReporter(t),
Printers: []httpexpect.Printer{
newSilentPrinter(t),
},
})

// check if everything works
setRoute(e, http.StatusCreated)

Expand All @@ -199,8 +223,8 @@ func TestGetSuccessWhenEtcdKilled(t *testing.T) {
// run in background
go func() {
for {
go getRoute(e, http.StatusOK)
time.Sleep(1000 * time.Millisecond)
go getRoute(eSilent, http.StatusOK)
time.Sleep(100 * time.Millisecond)
}
}()

Expand Down

0 comments on commit 68c4fd5

Please sign in to comment.