Skip to content

Commit

Permalink
Add e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxuzhonghu committed Jul 23, 2020
1 parent 9a28717 commit 8f12784
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion test/e2e/job/job_scale_up_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var _ = Describe("Dynamic Job scale up and down", func() {
err := waitJobReady(ctx, job)
Expect(err).NotTo(HaveOccurred())

// scale up
// scale down
job.Spec.MinAvailable = 1
job.Spec.Tasks[0].Replicas = 1
err = updateJob(ctx, job)
Expand Down Expand Up @@ -143,4 +143,77 @@ var _ = Describe("Dynamic Job scale up and down", func() {

})

It("Scale down to zero and scale up", func() {
By("init test ctx")
ctx := initTestContext(options{})
defer cleanupTestContext(ctx)

jobName := "scale-down-job"
By("create job")
job := createJob(ctx, &jobSpec{
name: jobName,
plugins: map[string][]string{
"svc": {},
},
tasks: []taskSpec{
{
name: "default",
img: defaultNginxImage,
min: 2,
rep: 2,
req: halfCPU,
},
},
})

// job phase: pending -> running
err := waitJobReady(ctx, job)
Expect(err).NotTo(HaveOccurred())

// scale down
job.Spec.MinAvailable = 0
job.Spec.Tasks[0].Replicas = 0
err = updateJob(ctx, job)
Expect(err).NotTo(HaveOccurred())

// wait for tasks scaled up
err = waitJobReady(ctx, job)
Expect(err).NotTo(HaveOccurred())

// check configmap updated
pluginName := fmt.Sprintf("%s-svc", jobName)
cm, err := ctx.kubeclient.CoreV1().ConfigMaps(ctx.namespace).Get(context.TODO(),
pluginName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

hosts := svc.GenerateHosts(job)
Expect(hosts).To(Equal(cm.Data))

// scale up
job.Spec.MinAvailable = 2
job.Spec.Tasks[0].Replicas = 2
err = updateJob(ctx, job)
Expect(err).NotTo(HaveOccurred())

// wait for tasks scaled up
err = waitJobReady(ctx, job)
Expect(err).NotTo(HaveOccurred())

// check configmap updated
cm, err = ctx.kubeclient.CoreV1().ConfigMaps(ctx.namespace).Get(context.TODO(),
pluginName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

hosts = svc.GenerateHosts(job)
Expect(hosts).To(Equal(cm.Data))

// TODO: check others

By("delete job")
err = ctx.vcclient.BatchV1alpha1().Jobs(job.Namespace).Delete(context.TODO(), job.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

err = waitJobCleanedUp(ctx, job)
Expect(err).NotTo(HaveOccurred())
})
})

0 comments on commit 8f12784

Please sign in to comment.