Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update get and delete task unit test and e2e test. #3525

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/compatibility-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 @@ -31,11 +31,11 @@ jobs:
include:
- module: manager
image: manager
image-tag: v2.1.56
image-tag: v2.1.58
chart-name: manager
- module: scheduler
image: scheduler
image-tag: v2.1.56
image-tag: v2.1.58
chart-name: scheduler
- module: client
image: client
Expand Down
226 changes: 223 additions & 3 deletions test/e2e/v2/manager/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
"d7y.io/dragonfly/v2/test/e2e/v2/util"
)

var _ = Describe("Get and delete task with Manager", func() {
Context("get and delete /bin/cat task", func() {
It("get and delete task should be ok", func() {
var _ = Describe("GetTask and DeleteTask with Manager", func() {
Context("/bin/cat file", Label("getTask", "deleteTask", "file"), func() {
It("getTask and deleteTask should be ok", func() {
// Create preheat job.
managerPod, err := util.ManagerExec(0)
fmt.Println(err)
Expand Down Expand Up @@ -103,6 +103,35 @@ var _ = Describe("Get and delete task with Manager", func() {

// Check get task response is not null.
Expect(job.Result).NotTo(BeNil())
groupJobStateData, err := json.Marshal(job.Result)
Expect(err).NotTo(HaveOccurred())
groupJobState := internaljob.GroupJobState{}
err = json.Unmarshal(groupJobStateData, &groupJobState)
Expect(err).NotTo(HaveOccurred())
Expect(len(groupJobState.JobStates)).Should(BeNumerically("==", 3))

// Check get task response is valid.
foundValidResult := false
for _, state := range groupJobState.JobStates {
for _, result := range state.Results {
resultData, err := json.Marshal(result)
Expect(err).NotTo(HaveOccurred())

getTaskResponse := internaljob.GetTaskResponse{}
err = json.Unmarshal(resultData, &getTaskResponse)
Expect(err).NotTo(HaveOccurred())

if len(getTaskResponse.Peers) > 0 {
foundValidResult = true
break
}
}

if foundValidResult {
break
}
}
Expect(foundValidResult).To(BeTrue())

// Delete task.
req, err = structure.StructToMap(types.CreateDeleteTaskJobRequest{
Expand All @@ -128,6 +157,197 @@ var _ = Describe("Get and delete task with Manager", func() {

// Check delete task response is not null.
Expect(job.Result).NotTo(BeNil())
groupJobStateData, err = json.Marshal(job.Result)
Expect(err).NotTo(HaveOccurred())
groupJobState = internaljob.GroupJobState{}
err = json.Unmarshal(groupJobStateData, &groupJobState)
Expect(err).NotTo(HaveOccurred())
Expect(len(groupJobState.JobStates)).Should(BeNumerically("==", 3))

// Check delete task response is valid.
foundValidResult = false
for _, state := range groupJobState.JobStates {
for _, result := range state.Results {
resultData, err := json.Marshal(result)
Expect(err).NotTo(HaveOccurred())

deleteTaskResponse := internaljob.DeleteTaskResponse{}
err = json.Unmarshal(resultData, &deleteTaskResponse)
Expect(err).NotTo(HaveOccurred())

if len(deleteTaskResponse.SuccessTasks) > 0 || len(deleteTaskResponse.FailureTasks) > 0 {
foundValidResult = true
break
}
}

if foundValidResult {
break
}
}
Expect(foundValidResult).To(BeTrue())

// Check file is deleted successfully.
exist := util.CheckFilesExist(seedClientPods, fileMetadata.ID)
Expect(exist).Should(BeFalse())
})
})

Context("/bin/pwd file", Label("getTask", "deleteTask", "file"), func() {
It("getTask and deleteTask should be ok", func() {
// Create preheat job.
managerPod, err := util.ManagerExec(0)
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())

req, err := structure.StructToMap(types.CreatePreheatJobRequest{
Type: internaljob.PreheatJob,
Args: types.PreheatArgs{
Type: "file",
URL: util.GetFileURL("/bin/pwd"),
},
SchedulerClusterIDs: []uint{1},
})
Expect(err).NotTo(HaveOccurred())

out, err := managerPod.CurlCommand("POST", map[string]string{"Content-Type": "application/json"}, req,
"http://127.0.0.1:8080/api/v1/jobs").CombinedOutput()
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())
fmt.Println(string(out))

job := &models.Job{}
err = json.Unmarshal(out, job)
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())

done := waitForDone(job, managerPod)
Expect(done).Should(BeTrue())

fileMetadata := util.FileMetadata{
ID: "ddc397119488e07671cdeec0bf54c31b544ce2fbff14441c7444f1dddda2bd91",
Sha256: "5286873505a9671e077f346cdfb89d5a6c99985fe3f11a972f30fedf9029bae0",
}

seedClientPods := make([]*util.PodExec, 3)
for i := 0; i < 3; i++ {
seedClientPods[i], err = util.SeedClientExec(i)
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())
}

// Check the file is downloaded successfully.
sha256sum, err := util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID)
Expect(err).NotTo(HaveOccurred())
Expect(fileMetadata.Sha256).To(Equal(sha256sum))

// Get task.
req, err = structure.StructToMap(types.CreateGetTaskJobRequest{
Type: internaljob.GetTaskJob,
Args: types.GetTaskArgs{
TaskID: fileMetadata.ID,
},
})
Expect(err).NotTo(HaveOccurred())
out, err = managerPod.CurlCommand("POST", map[string]string{"Content-Type": "application/json"}, req,
"http://127.0.0.1:8080/api/v1/jobs").CombinedOutput()
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())
fmt.Println(string(out))

job = &models.Job{}
err = json.Unmarshal(out, job)
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())

done = waitForDone(job, managerPod)
Expect(done).Should(BeTrue())

// Check get task response is not null.
Expect(job.Result).NotTo(BeNil())
groupJobStateData, err := json.Marshal(job.Result)
Expect(err).NotTo(HaveOccurred())
groupJobState := internaljob.GroupJobState{}
err = json.Unmarshal(groupJobStateData, &groupJobState)
Expect(err).NotTo(HaveOccurred())
Expect(len(groupJobState.JobStates)).Should(BeNumerically("==", 3))

// Check get task response is valid.
foundValidResult := false
for _, state := range groupJobState.JobStates {
for _, result := range state.Results {
resultData, err := json.Marshal(result)
Expect(err).NotTo(HaveOccurred())

getTaskResponse := internaljob.GetTaskResponse{}
err = json.Unmarshal(resultData, &getTaskResponse)
Expect(err).NotTo(HaveOccurred())

if len(getTaskResponse.Peers) > 0 {
foundValidResult = true
break
}
}

if foundValidResult {
break
}
}
Expect(foundValidResult).To(BeTrue())

// Delete task.
req, err = structure.StructToMap(types.CreateDeleteTaskJobRequest{
Type: internaljob.DeleteTaskJob,
Args: types.DeleteTaskArgs{
TaskID: fileMetadata.ID,
},
})
Expect(err).NotTo(HaveOccurred())
out, err = managerPod.CurlCommand("POST", map[string]string{"Content-Type": "application/json"}, req,
"http://127.0.0.1:8080/api/v1/jobs").CombinedOutput()
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())
fmt.Println(string(out))

job = &models.Job{}
err = json.Unmarshal(out, job)
fmt.Println(err)
Expect(err).NotTo(HaveOccurred())

done = waitForDone(job, managerPod)
Expect(done).Should(BeTrue())

// Check delete task response is not null.
Expect(job.Result).NotTo(BeNil())
groupJobStateData, err = json.Marshal(job.Result)
Expect(err).NotTo(HaveOccurred())
groupJobState = internaljob.GroupJobState{}
err = json.Unmarshal(groupJobStateData, &groupJobState)
Expect(err).NotTo(HaveOccurred())
Expect(len(groupJobState.JobStates)).Should(BeNumerically("==", 3))

// Check delete task response is valid.
foundValidResult = false
for _, state := range groupJobState.JobStates {
for _, result := range state.Results {
resultData, err := json.Marshal(result)
Expect(err).NotTo(HaveOccurred())

deleteTaskResponse := internaljob.DeleteTaskResponse{}
err = json.Unmarshal(resultData, &deleteTaskResponse)
Expect(err).NotTo(HaveOccurred())

if len(deleteTaskResponse.SuccessTasks) > 0 || len(deleteTaskResponse.FailureTasks) > 0 {
foundValidResult = true
break
}
}

if foundValidResult {
break
}
}
Expect(foundValidResult).To(BeTrue())

// Check file is deleted successfully.
exist := util.CheckFilesExist(seedClientPods, fileMetadata.ID)
Expand Down
Loading