ci: use httpbin.org in chaos test to make CI works (#3614)

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
This commit is contained in:
Shuyang Wu 2021-02-20 14:03:10 +08:00 committed by GitHub
parent 017298de86
commit 5656649d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 15 deletions

View File

@ -3,7 +3,7 @@ name: Chaos Test
on: [pull_request]
jobs:
build:
chaos-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

View File

@ -68,9 +68,6 @@ func TestGetSuccessWhenEtcdKilled(t *testing.T) {
// check if everything works
setRoute(e, http.StatusCreated)
// to avoid route haven't been set yet
time.Sleep(1 * time.Second)
getRoute(e, http.StatusOK)
testPrometheusEtcdMetric(e, 1)
@ -78,13 +75,14 @@ func TestGetSuccessWhenEtcdKilled(t *testing.T) {
go func() {
for {
go getRoute(eSilent, http.StatusOK)
time.Sleep(100 * time.Millisecond)
time.Sleep(500 * time.Millisecond)
}
}()
// wait 5 second to let first route access returns
time.Sleep(5 * time.Second)
bpsBefore := getIngressBandwidthPerSecond(e, g)
bandwidthBefore, durationBefore := getIngressBandwidthPerSecond(e, g)
bpsBefore := bandwidthBefore / durationBefore
g.Expect(bpsBefore).NotTo(BeZero())
listOption := client.MatchingLabels{"app": "apisix-gw"}
@ -112,8 +110,11 @@ func TestGetSuccessWhenEtcdKilled(t *testing.T) {
g.Expect(strings.Contains(errorLog, "failed to fetch data from etcd")).To(BeTrue())
})
bpsAfter := getIngressBandwidthPerSecond(e, g)
bandwidthAfter, durationAfter := getIngressBandwidthPerSecond(e, g)
bpsAfter := bandwidthAfter / durationAfter
t.Run("ingress bandwidth per second not change much", func(t *testing.T) {
t.Logf("bandwidth before: %f, after: %f", bandwidthBefore, bandwidthAfter)
t.Logf("duration before: %f, after: %f", durationBefore, durationAfter)
t.Logf("bps before: %f, after: %f", bpsBefore, bpsAfter)
g.Expect(roughCompare(bpsBefore, bpsAfter)).To(BeTrue())
})

View File

@ -84,14 +84,14 @@ func setRoute(e *httpexpect.Expect, expectStatus int) {
Path: "/apisix/admin/routes/1",
Headers: map[string]string{"X-API-KEY": token},
Body: `{
"uri": "/hello",
"host": "foo.com",
"uri": "/get",
"host": "httpbin.org",
"plugins": {
"prometheus": {}
},
"upstream": {
"nodes": {
"bar.org": 1
"httpbin.org:80": 1
},
"type": "roundrobin"
}
@ -104,8 +104,8 @@ func getRoute(e *httpexpect.Expect, expectStatus int) {
caseCheck(httpTestCase{
E: e,
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "foo.com"},
Path: "/get",
Headers: map[string]string{"Host": "httpbin.org"},
ExpectStatus: expectStatus,
})
}
@ -149,7 +149,7 @@ func getPrometheusMetric(e *httpexpect.Expect, g *WithT, key string) string {
return targetSlice[1]
}
func getIngressBandwidthPerSecond(e *httpexpect.Expect, g *WithT) float64 {
func getIngressBandwidthPerSecond(e *httpexpect.Expect, g *WithT) (float64, float64) {
key := "apisix_bandwidth{type=\"ingress\","
bandWidthString := getPrometheusMetric(e, g, key)
bandWidthStart, err := strconv.ParseFloat(bandWidthString, 64)
@ -158,13 +158,13 @@ func getIngressBandwidthPerSecond(e *httpexpect.Expect, g *WithT) float64 {
// so need to calculate the duration
timeStart := time.Now()
time.Sleep(1 * time.Second)
time.Sleep(5 * time.Second)
bandWidthString = getPrometheusMetric(e, g, key)
bandWidthEnd, err := strconv.ParseFloat(bandWidthString, 64)
g.Expect(err).To(BeNil())
duration := time.Now().Sub(timeStart)
return (bandWidthEnd - bandWidthStart) / duration.Seconds()
return bandWidthEnd - bandWidthStart, duration.Seconds()
}
func roughCompare(a float64, b float64) bool {