Skip to content

Commit

Permalink
refactor: refactor the e2e file server
Browse files Browse the repository at this point in the history
Signed-off-by: suhan.zcy <[email protected]>
  • Loading branch information
suhan.zcy committed Jan 2, 2025
1 parent 14cf937 commit ff867ba
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compatibility-e2e-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
DRAGONFLY_CHARTS_CONFIG_PATH: test/testdata/charts/config-v2.yaml
DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly
DRAGONFLY_FILE_SERVER_PATH: test/testdata/k8s/file-server.yaml
DRAGONFLY_FILE_SERVER_V2_PATH: test/testdata/k8s/file-server-v2.yaml

jobs:
compatibility_e2e_tests:
Expand Down Expand Up @@ -137,6 +138,7 @@ jobs:
run: |
helm install --wait --timeout 15m --dependency-update --create-namespace --namespace dragonfly-system --set ${{ matrix.chart-name }}.image.tag=${{ matrix.image-tag }} --set ${{ matrix.chart-name }}.image.repository=dragonflyoss/${{ matrix.image }} -f ${{ env.DRAGONFLY_CHARTS_CONFIG_PATH }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_V2_PATH }}
kubectl wait po file-server-0 --namespace dragonfly-e2e --for=condition=ready --timeout=10m
- name: Run E2E test
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/e2e-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
schedule:
- cron: '0 4 * * *'

permissions:
permissions:
contents: read

env:
Expand All @@ -19,6 +19,7 @@ env:
KIND_CONFIG_PATH: test/testdata/kind/config-v2.yaml
DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly
DRAGONFLY_FILE_SERVER_PATH: test/testdata/k8s/file-server.yaml
DRAGONFLY_FILE_SERVER_V2_PATH: test/testdata/k8s/file-server-v2.yaml

jobs:
e2e_tests:
Expand Down Expand Up @@ -124,6 +125,7 @@ jobs:
run: |
helm install --wait --timeout 15m --dependency-update --create-namespace --namespace dragonfly-system -f ${{ matrix.charts-config }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_V2_PATH }}
kubectl wait po file-server-0 --namespace dragonfly-e2e --for=condition=ready --timeout=10m
- name: Run E2E test
Expand Down
76 changes: 36 additions & 40 deletions test/e2e/v2/concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,34 @@ import (

var _ = Describe("Download Concurrency", func() {
Context("ab", func() {
var (
testFile *util.File
err error
)

BeforeEach(func() {
testFile, err = fs.PrepareFile(util.FileSize1MiB)
Expect(err).NotTo(HaveOccurred())
Expect(testFile).NotTo(BeNil())
})

AfterEach(func() {
err = fs.CleanFile(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", util.GetFileURL("/bin/unshare"))).CombinedOutput()
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())

fileMetadata := util.FileMetadata{
ID: "14b31801ea6990788057b965fbc51e44bf73800462915fdfa0fda8182acca4d6",
Sha256: "fc44bbbba20490450c73530db3d1b935f893f38d7d8084ca132952a765ff5ff6",
}

sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID)
sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
Expect(testFile.GetSha256()).To(Equal(sha256sum))

seedClientPods := make([]*util.PodExec, 3)
for i := 0; i < 3; i++ {
Expand All @@ -52,28 +63,23 @@ var _ = Describe("Download Concurrency", func() {
Expect(err).NotTo(HaveOccurred())
}

sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID)
sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
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", util.GetFileURL("/bin/loginctl"))).CombinedOutput()
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())

fileMetadata := util.FileMetadata{
ID: "958e177b56be708c9d7ec193ae8cef399b39faff8234af33efa4cbe097d1fc5f",
Sha256: "dc102987a36be20846821ac74648534863ff0fe8897d4250273a6ffc80481d91",
}

sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID)
sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
Expect(testFile.GetSha256()).To(Equal(sha256sum))

seedClientPods := make([]*util.PodExec, 3)
for i := 0; i < 3; i++ {
Expand All @@ -82,28 +88,23 @@ var _ = Describe("Download Concurrency", func() {
Expect(err).NotTo(HaveOccurred())
}

sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID)
sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
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", util.GetFileURL("/bin/realpath"))).CombinedOutput()
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())

fileMetadata := util.FileMetadata{
ID: "dd573cf9c3e1a79402b8423abcd1ba987c1b1ee9c49069d139d71106a260b055",
Sha256: "54e54b7ff54ef70d4db2adcd24a27e3b9af3cd99fc0213983bac1e8035429be6",
}

sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID)
sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
Expect(testFile.GetSha256()).To(Equal(sha256sum))

seedClientPods := make([]*util.PodExec, 3)
for i := 0; i < 3; i++ {
Expand All @@ -112,28 +113,23 @@ var _ = Describe("Download Concurrency", func() {
Expect(err).NotTo(HaveOccurred())
}

sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID)
sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
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", util.GetFileURL("/bin/lnstat"))).CombinedOutput()
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())

fileMetadata := util.FileMetadata{
ID: "f1957adc26ec326800ced850d72e583a03be0999ba80d9aa2e3ba57ef4ddaf17",
Sha256: "87c09b7c338f258809ca2d436bbe06ac94a3166b3f3e1125a86f35d9a9aa1d2f",
}

sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID)
sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
Expect(testFile.GetSha256()).To(Equal(sha256sum))

seedClientPods := make([]*util.PodExec, 3)
for i := 0; i < 3; i++ {
Expand All @@ -142,9 +138,9 @@ var _ = Describe("Download Concurrency", func() {
Expect(err).NotTo(HaveOccurred())
}

sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID)
sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, testFile.GetTaskID())
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))
Expect(testFile.GetSha256()).To(Equal(sha256sum))
})
})
})
13 changes: 13 additions & 0 deletions test/e2e/v2/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
"d7y.io/dragonfly/v2/test/e2e/v2/util"
)

// fs is the global file server.
var fs *util.FileServer

var _ = AfterSuite(func() {
for _, server := range util.Servers {
for i := 0; i < server.Replicas; i++ {
Expand Down Expand Up @@ -80,9 +83,19 @@ var _ = AfterSuite(func() {
fmt.Printf("------------------------------ Get %s-%d Artifact Finished ------------------------------\n", server.Name, i)
}
}

// Clean up file server if exists.
if fs != nil {
fs.CleanAll()
}
})

var _ = BeforeSuite(func() {
var err error
fs, err = util.NewFileServer()
Expect(err).NotTo(HaveOccurred())
Expect(fs).NotTo(BeNil())

rawGitCommit, err := util.GitCommand("rev-parse", "--short", "HEAD").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
gitCommit := strings.Fields(string(rawGitCommit))[0]
Expand Down
60 changes: 60 additions & 0 deletions test/e2e/v2/util/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 util

import (
"os"

"d7y.io/dragonfly/v2/pkg/idgen"
)

// File represents a file.
type File struct {
// info is the local file info.
info os.FileInfo
// downloadURL is the download URL of the file from remote file server.
downloadURL string
}

// GetInfo returns the file info.
func (f *File) GetInfo() os.FileInfo {
return f.info
}

// GetSha256 returns the sha256 of the file content.
func (f *File) GetSha256() string {
// the file name is the sha256 of the file content
return f.info.Name()
}

// GetDownloadURL returns the download URL of the file from remote file server.
func (f *File) GetDownloadURL() string {
return f.downloadURL
}

// GetTaskID returns the task id of the file.
func (f *File) GetTaskID(opts ...TaskIDOption) string {
taskIDOpts := &TaskIDOptions{
url: f.downloadURL,
}

for _, opt := range opts {
opt(taskIDOpts)
}

return idgen.TaskIDV2(taskIDOpts.url, taskIDOpts.tag, taskIDOpts.application, taskIDOpts.filteredQueryParams)
}
Loading

0 comments on commit ff867ba

Please sign in to comment.