Add tests for panic recovery of dryadJob 73/161473/3
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 17 Nov 2017 14:01:51 +0000 (15:01 +0100)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 30 Nov 2017 13:25:57 +0000 (14:25 +0100)
Change-Id: I7ac9ccb609a77ff5d0e4635c5d91e23cc88fd4ae
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
manager/dryad_job.go
manager/dryad_job_test.go

index 4c4a32f..21cc5d1 100644 (file)
@@ -99,10 +99,11 @@ func (d *dryadJob) run(ctx context.Context) {
                if r := recover(); r != nil {
                        if err, ok := r.(error); ok {
                                d.failReason = err.Error()
-                               d.changeStatus(DJ_FAIL)
-                               return
+                       } else {
+                               d.failReason = fmt.Sprintf("run panicked: %v", r)
                        }
-                       panic(r)
+                       d.changeStatus(DJ_FAIL)
+                       return
                }
                d.changeStatus(DJ_OK)
        }()
index 22b0ec5..42c0456 100644 (file)
@@ -126,6 +126,27 @@ var _ = Describe("dryadJob", func() {
                }),
        )
 
+       DescribeTable("should recover a panic and go to failed state",
+               func(f func()) {
+                       f()
+                       djSync <- struct{}{}
+                       fail := DryadJobStatusChange{jobID, DJ_FAIL}
+                       Eventually(changes).Should(Receive(Equal(fail)))
+               },
+               Entry("deploy", func() {
+                       deploy.Do(func() { panic("deploy") })
+                       boot.Times(0)
+                       test.Times(0)
+               }),
+               Entry("boot", func() {
+                       boot.Do(func() { panic("boot") })
+                       test.Times(0)
+               }),
+               Entry("test", func() {
+                       test.Do(func() { panic("test") })
+               }),
+       )
+
        It("should return DryadJobInfo", func() {
                djSync <- struct{}{}
                info := dj.GetJobInfo()