| 42 | } |
| 43 | |
| 44 | func TestChainRecover(t *testing.T) { |
| 45 | panickingJob := FuncJob(func() { |
| 46 | panic("panickingJob panics") |
| 47 | }) |
| 48 | |
| 49 | t.Run("panic exits job by default", func(t *testing.T) { |
| 50 | defer func() { |
| 51 | if err := recover(); err == nil { |
| 52 | t.Errorf("panic expected, but none received") |
| 53 | } |
| 54 | }() |
| 55 | NewChain().Then(panickingJob). |
| 56 | Run() |
| 57 | }) |
| 58 | |
| 59 | t.Run("Recovering JobWrapper recovers", func(t *testing.T) { |
| 60 | NewChain(Recover(PrintfLogger(log.New(ioutil.Discard, "", 0)))). |
| 61 | Then(panickingJob). |
| 62 | Run() |
| 63 | }) |
| 64 | |
| 65 | t.Run("composed with the *IfStillRunning wrappers", func(t *testing.T) { |
| 66 | NewChain(Recover(PrintfLogger(log.New(ioutil.Discard, "", 0)))). |
| 67 | Then(panickingJob). |
| 68 | Run() |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | type countJob struct { |
| 73 | m sync.Mutex |