/* * Copyright 2024 The Dragonfly Authors * * Licensed 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 e2e import ( "fmt" . "github.com/onsi/ginkgo/v2" //nolint . "github.com/onsi/gomega" //nolint "d7y.io/dragonfly/v2/test/e2e/util" ) var _ = Describe("Download Concurrency", func() { Context("ab", func() { var ( testFile *util.File err error ) BeforeEach(func() { testFile, err = util.GetFileServer().GenerateFile(util.FileSize1MiB) Expect(err).NotTo(HaveOccurred()) Expect(testFile).NotTo(BeNil()) }) AfterEach(func() { err = util.GetFileServer().DeleteFile(testFile.GetInfo()) Expect(err).NotTo(HaveOccurred()) }) It("concurrent 100 should be ok", Label("concurrent", "100"), func() { clientPod, err := util.ClientExec() fmt.Println(err) Expect(err).NotTo(HaveOccurred()) out, err := clientPod.Command("sh", "-c", fmt.Sprintf("ab -c 100 -n 200 -X 127.0.0.1:4001 %s", testFile.GetDownloadURL())).CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) seedClientPods := make([]*util.PodExec, 3) for i := range 3 { seedClientPods[i], err = util.SeedClientExec(i) fmt.Println(err) Expect(err).NotTo(HaveOccurred()) } sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) }) It("concurrent 200 should be ok", Label("concurrent", "200"), func() { clientPod, err := util.ClientExec() fmt.Println(err) Expect(err).NotTo(HaveOccurred()) out, err := clientPod.Command("sh", "-c", fmt.Sprintf("ab -c 200 -n 400 -X 127.0.0.1:4001 %s", testFile.GetDownloadURL())).CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) seedClientPods := make([]*util.PodExec, 3) for i := range 3 { seedClientPods[i], err = util.SeedClientExec(i) fmt.Println(err) Expect(err).NotTo(HaveOccurred()) } sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) }) It("concurrent 500 should be ok", Label("concurrent", "500"), func() { clientPod, err := util.ClientExec() fmt.Println(err) Expect(err).NotTo(HaveOccurred()) out, err := clientPod.Command("sh", "-c", fmt.Sprintf("ab -c 500 -n 1000 -X 127.0.0.1:4001 %s", testFile.GetDownloadURL())).CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) seedClientPods := make([]*util.PodExec, 3) for i := range 3 { seedClientPods[i], err = util.SeedClientExec(i) fmt.Println(err) Expect(err).NotTo(HaveOccurred()) } sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) }) It("concurrent 1000 should be ok", Label("concurrent", "1000"), func() { clientPod, err := util.ClientExec() fmt.Println(err) Expect(err).NotTo(HaveOccurred()) out, err := clientPod.Command("sh", "-c", fmt.Sprintf("ab -c 1000 -n 2000 -X 127.0.0.1:4001 %s", testFile.GetDownloadURL())).CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) seedClientPods := make([]*util.PodExec, 3) for i := range 3 { seedClientPods[i], err = util.SeedClientExec(i) fmt.Println(err) Expect(err).NotTo(HaveOccurred()) } sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID()) Expect(err).NotTo(HaveOccurred()) Expect(testFile.GetSha256()).To(Equal(sha256sum)) }) }) })