1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package httpchaos
17
18 import (
19 "context"
20 "time"
21
22 . "github.com/onsi/ginkgo/v2"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/util/wait"
25 "k8s.io/kubernetes/test/e2e/framework"
26 "sigs.k8s.io/controller-runtime/pkg/client"
27
28 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
29 test "github.com/chaos-mesh/chaos-mesh/e2e-test"
30 e2econfig "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/config"
31 "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/util"
32 )
33
34 func TestcaseHttpGracefulAbortShutdown(
35 ns string,
36 cli client.Client,
37 c HTTPE2EClient,
38 port uint16,
39 ) {
40 ctx, cancel := context.WithCancel(context.Background())
41 defer cancel()
42
43 By("waiting on e2e helper ready")
44 err := util.WaitHTTPE2EHelperReady(*c.C, c.IP, port)
45 framework.ExpectNoError(err, "wait e2e helper ready error")
46 By("create http abort chaos CRD objects")
47
48 abort := true
49
50 httpChaos := &v1alpha1.HTTPChaos{
51 ObjectMeta: metav1.ObjectMeta{
52 Name: "http-chaos",
53 Namespace: ns,
54 },
55 Spec: v1alpha1.HTTPChaosSpec{
56 PodSelector: v1alpha1.PodSelector{
57 Selector: v1alpha1.PodSelectorSpec{
58 GenericSelectorSpec: v1alpha1.GenericSelectorSpec{
59 Namespaces: []string{ns},
60 LabelSelectors: map[string]string{"app": "http"},
61 },
62 },
63 Mode: v1alpha1.OneMode,
64 },
65 Port: 8080,
66 Target: "Request",
67 PodHttpChaosActions: v1alpha1.PodHttpChaosActions{
68 Abort: &abort,
69 },
70 },
71 }
72 err = cli.Create(ctx, httpChaos)
73 framework.ExpectNoError(err, "create http chaos error")
74
75 defer func() {
76 err = cli.Delete(ctx, httpChaos)
77 framework.ExpectNoError(err, "delete http chaos")
78 }()
79
80 By("waiting for assertion HTTP abort")
81 err = wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
82 _, err := getPodHttpNoBody(c, port)
83
84
85 if err != nil {
86 return true, nil
87 }
88 return false, nil
89 })
90 framework.ExpectNoError(err, "http chaos doesn't work as expected")
91 By("apply http chaos successfully")
92
93 By("upgrade chaos mesh")
94
95 oa, ocfg, err := test.BuildOperatorActionAndCfg(e2econfig.TestConfig)
96 framework.ExpectNoError(err, "failed to create operator action")
97 err = oa.RestartDaemon(ocfg)
98 framework.ExpectNoError(err, "failed to restart chaos daemon")
99
100 By("waiting for assertion chaos recovered")
101 err = wait.PollImmediate(5*time.Second, 2*time.Minute, func() (bool, error) {
102 _, err := getPodHttpNoBody(c, port)
103
104
105 if err == nil {
106 return true, nil
107 }
108 return false, nil
109 })
110 framework.ExpectNoError(err, "http chaos doesn't gracefully shutdown as expected")
111 By("http chaos shutdown successfully")
112 }
113