github.com/midokura/kubeedge@v1.2.0-mido.0/tests/performance/hubtest/hubtest_test.go (about) 1 /* 2 Copyright 2019 The KubeEdge Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package hubtest 17 18 import ( 19 . "github.com/onsi/ginkgo" 20 . "github.com/onsi/gomega" 21 metav1 "k8s.io/api/core/v1" 22 23 "github.com/kubeedge/kubeedge/tests/e2e/utils" 24 . "github.com/kubeedge/kubeedge/tests/performance/common" 25 "github.com/kubeedge/kubeedge/tests/stubs/common/constants" 26 "github.com/kubeedge/kubeedge/tests/stubs/common/types" 27 ) 28 29 var _ = Describe("KubeEdge hub performance test", func() { 30 Context("Test different numbers of Pods on different numbers of Edge Nodes", func() { 31 // Init params 32 var podlist metav1.PodList 33 var numOfEdgeNodes int 34 var numOfPodsPerEdgeNode int 35 var podsInfo map[string]types.FakePod 36 var pods []types.FakePod 37 var latency types.Latency 38 39 BeforeEach(func() { 40 // Create Edge Nodes 41 numOfEdgeNodes = 10 42 podlist = HandleEdgeDeployment(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, 43 ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, ctx.Cfg.EdgeImageUrl, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, numOfEdgeNodes) 44 }) 45 46 AfterEach(func() { 47 // Get latency 48 if len(pods) > 0 { 49 latency = GetLatency(pods) 50 utils.Infof("HubTest 50 percent latency: %s", latency.Percent50.String()) 51 utils.Infof("HubTest 90 percent latency: %s", latency.Percent90.String()) 52 utils.Infof("HubTest 99 percent latency: %s", latency.Percent99.String()) 53 utils.Infof("HubTest 100 percent latency: %s", latency.Percent100.String()) 54 } 55 56 // Delete Pods 57 for _, p := range podsInfo { 58 DeleteFakePod(controllerHubURL, p) 59 } 60 // Check All Pods are deleted 61 Eventually(func() int { 62 ps := ListFakePods(controllerHubURL) 63 return len(ps) 64 }, "240s", "4s").Should(Equal(0), "Wait for Pods deleted timeout") 65 66 // Delete Edge Nodes 67 DeleteEdgeDeployments(ctx.Cfg.K8SMasterForKubeEdge, ctx.Cfg.K8SMasterForProvisionEdgeNodes, numOfEdgeNodes) 68 utils.CheckDeploymentPodDeleteState(ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, podlist) 69 }) 70 71 Measure("PERF_HUBTEST_NODES_10_PODS_10: Create 10 Edge Nodes, Deploy 10 Pods per Edge Node, Measure startup time of Pods", func(b Benchmarker) { 72 // Measure startup time 73 hubTestRuntime := b.Time("runtime", func() { 74 // Create Pods on Edge Nodes 75 numOfPodsPerEdgeNode = 10 76 podsInfo = make(map[string]types.FakePod) 77 pods = make([]types.FakePod, 0) 78 // Loop for Pod Numbers 79 for i := 0; i < numOfPodsPerEdgeNode; i++ { 80 // Loop for Edge Node Numbers 81 for nodeName := range NodeInfo { 82 // Contruct fake pods 83 var pod types.FakePod 84 pod.Name = nodeName + "-fakepod-" + utils.GetRandomString(10) 85 pod.Namespace = constants.NamespaceDefault 86 pod.NodeName = nodeName 87 pod.Status = constants.PodPending 88 // Add fake pod 89 go AddFakePod(controllerHubURL, pod) 90 // Store fake pod 91 podsInfo[pod.Name] = pod 92 } 93 } 94 95 // Check all pods are running 96 Eventually(func() int { 97 count := 0 98 // List all pods status 99 pods = ListFakePods(controllerHubURL) 100 // Get current pod numbers which are running 101 for _, p := range pods { 102 if p.Status == constants.PodRunning { 103 count++ 104 } 105 } 106 utils.Infof("Current running pods count: %d", count) 107 return count 108 }, "240s", "100ms").Should(Equal(numOfEdgeNodes*numOfPodsPerEdgeNode), "Wait for Pods in running status timeout") 109 }) 110 utils.Infof("HubTest runtime stats: %+v", hubTestRuntime) 111 }, 5) 112 }) 113 })