tokers commented on a change in pull request #4560: URL: https://github.com/apache/apisix/pull/4560#discussion_r667286821
########## File path: t/chaos/killetcd/killetcd.go ########## @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package killetcd + +import ( + "context" + "fmt" + "net/http" + "time" + + "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" + "github.com/gavv/httpexpect" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/api/v1/pod" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/apache/apisix/t/chaos/utils" +) + +var ( + bandwidthBefore float64 + durationBefore float64 + bpsBefore float64 + bandwidthAfter float64 + durationAfter float64 + bpsAfter float64 +) + +func getEtcdKillChaos() *v1alpha1.PodChaos { + return &v1alpha1.PodChaos{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kill-etcd", + Namespace: metav1.NamespaceDefault, + }, + Spec: v1alpha1.PodChaosSpec{ + Selector: v1alpha1.SelectorSpec{ + LabelSelectors: map[string]string{"app.kubernetes.io/instance": "etcd"}, + }, + Action: v1alpha1.PodKillAction, + Mode: v1alpha1.AllPodMode, + Scheduler: &v1alpha1.SchedulerSpec{ + Cron: "@every 10m", + }, + }, + } +} + +var _ = ginkgo.Describe("Test Get Success When Etcd Got Killed", func() { + e := httpexpect.New(ginkgo.GinkgoT(), utils.Host) + eSilent := httpexpect.WithConfig(httpexpect.Config{ Review comment: A recommended best practice is putting all your initialization logics into `ginkgo.BeforeEach`. ########## File path: t/chaos/killetcd/killetcd.go ########## @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package killetcd + +import ( + "context" + "fmt" + "net/http" + "time" + + "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" + "github.com/gavv/httpexpect" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/api/v1/pod" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/apache/apisix/t/chaos/utils" +) + +var ( + bandwidthBefore float64 + durationBefore float64 + bpsBefore float64 + bandwidthAfter float64 + durationAfter float64 + bpsAfter float64 +) + +func getEtcdKillChaos() *v1alpha1.PodChaos { + return &v1alpha1.PodChaos{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kill-etcd", + Namespace: metav1.NamespaceDefault, + }, + Spec: v1alpha1.PodChaosSpec{ + Selector: v1alpha1.SelectorSpec{ + LabelSelectors: map[string]string{"app.kubernetes.io/instance": "etcd"}, + }, + Action: v1alpha1.PodKillAction, + Mode: v1alpha1.AllPodMode, + Scheduler: &v1alpha1.SchedulerSpec{ + Cron: "@every 10m", + }, + }, + } +} + +var _ = ginkgo.Describe("Test Get Success When Etcd Got Killed", func() { + e := httpexpect.New(ginkgo.GinkgoT(), utils.Host) + eSilent := httpexpect.WithConfig(httpexpect.Config{ + BaseURL: utils.Host, + Reporter: httpexpect.NewAssertReporter(ginkgo.GinkgoT()), + Printers: []httpexpect.Printer{ + utils.NewSilentPrinter(ginkgo.GinkgoT()), + }, + }) + + var cliSet *utils.ClientSet + var apisixPod *v1.Pod + var err error + ginkgo.It("init client set", func() { Review comment: If you'd like to use `It` mechanism to separate the test suites, you may try ginkgo table. ########## File path: t/chaos/killetcd/killetcd.go ########## @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package killetcd + +import ( + "context" + "fmt" + "net/http" + "time" + + "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" + "github.com/gavv/httpexpect" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/api/v1/pod" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/apache/apisix/t/chaos/utils" +) + +var ( + bandwidthBefore float64 + durationBefore float64 + bpsBefore float64 + bandwidthAfter float64 + durationAfter float64 + bpsAfter float64 +) + +func getEtcdKillChaos() *v1alpha1.PodChaos { + return &v1alpha1.PodChaos{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kill-etcd", + Namespace: metav1.NamespaceDefault, + }, + Spec: v1alpha1.PodChaosSpec{ + Selector: v1alpha1.SelectorSpec{ + LabelSelectors: map[string]string{"app.kubernetes.io/instance": "etcd"}, + }, + Action: v1alpha1.PodKillAction, + Mode: v1alpha1.AllPodMode, + Scheduler: &v1alpha1.SchedulerSpec{ + Cron: "@every 10m", + }, + }, + } +} + +var _ = ginkgo.Describe("Test Get Success When Etcd Got Killed", func() { + e := httpexpect.New(ginkgo.GinkgoT(), utils.Host) + eSilent := httpexpect.WithConfig(httpexpect.Config{ + BaseURL: utils.Host, + Reporter: httpexpect.NewAssertReporter(ginkgo.GinkgoT()), + Printers: []httpexpect.Printer{ + utils.NewSilentPrinter(ginkgo.GinkgoT()), + }, + }) + + var cliSet *utils.ClientSet + var apisixPod *v1.Pod + var err error + ginkgo.It("init client set", func() { + cliSet, err = utils.InitClientSet() + gomega.Expect(err).To(gomega.BeNil()) + listOption := client.MatchingLabels{"app": "apisix-gw"} + apisixPods, err := utils.GetPods(cliSet.CtrlCli, metav1.NamespaceDefault, listOption) + gomega.Expect(err).To(gomega.BeNil()) + gomega.Ω(len(apisixPods)).Should(gomega.BeNumerically(">", 0)) + apisixPod = &apisixPods[0] + }) + + stopChan := make(chan bool) + defer ginkgo.It("restore test environment", func() { Review comment: Why not use `ginkgo.AfterEach`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
