-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathfallbackgroup_test.go
103 lines (85 loc) · 2.75 KB
/
fallbackgroup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package proxy_test
// TODO: move this to the proxy package
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/proxy/proxytest"
)
func TestFallbackGroupLB(t *testing.T) {
// two groups and a non-grouped route, altogether 1 + 2 + 2 = 5 backends
// initially, all work
// the non-grouped backend fails
// -> the non-grouped route fails, the others work and don't fall back
// recovers
// a grouped backend fails
// -> the non-grouped route works, the failing one falls back, the other grouped works
// recovers
// both backends from a group fail -> both routes fail
// -> the group fails
// start one ungrouped, and two grouped backends:
nonGrouped := testBackend("non-grouped", http.StatusOK)
groupA_BE1 := testBackend("group-A/BE-1", http.StatusOK)
groupA_BE2 := testBackend("group-A/BE-2", http.StatusOK)
groupB_BE1 := testBackend("group-B/BE-1", http.StatusOK)
groupB_BE2 := testBackend("group-B/BE-2", http.StatusOK)
type closer interface {
Close()
}
for _, c := range []closer{nonGrouped, groupA_BE1, groupA_BE2, groupB_BE1, groupB_BE2} {
defer c.Close()
}
// start a proxy:
const routesFmt = `
nonGrouped: Path("/") -> "%s";
groupA: Path("/a") -> <roundRobin, "%s", "%s">;
groupB: Path("/b") -> <roundRobin, "%s", "%s">;
`
routesDoc := fmt.Sprintf(
routesFmt,
nonGrouped.URL,
groupA_BE1.URL,
groupA_BE2.URL,
groupB_BE1.URL,
groupB_BE2.URL,
)
routes := eskip.MustParse(routesDoc)
p := proxytest.New(builtin.MakeRegistry(), routes...)
defer p.Close()
requestMSG := bindClient(p)
request := func(path string, expectedResponses ...string) bool {
_, ok := requestMSG(path, expectedResponses...)
return ok
}
t.Run("succeed and load balance initially", func(t *testing.T) {
if !request("/", "non-grouped") ||
!request("/a", "group-A/BE-1", "group-A/BE-2") ||
!request("/b", "group-B/BE-1", "group-B/BE-2") {
t.Error("failed to receive the right response")
}
})
t.Run("one member in the group fails", func(t *testing.T) {
groupA_BE1.Close()
time.Sleep(300 * time.Millisecond)
// group A responds two times from backend 2:
if !request("/", "non-grouped") ||
!request("/a", "group-A/BE-2", "group-A/BE-2") ||
!request("/b", "group-B/BE-1", "group-B/BE-2") {
t.Error("failed to receive the right response")
}
})
t.Run("both members in the group fail", func(t *testing.T) {
groupA_BE1.Close()
groupA_BE2.Close()
time.Sleep(300 * time.Millisecond)
// group A responds two times with failure:
if !request("/", "non-grouped") ||
!request("/a", "Bad Gateway", "Bad Gateway") ||
!request("/b", "group-B/BE-1", "group-B/BE-2") {
t.Error("failed to receive the right response")
}
})
}