MCPcopy
hub / github.com/robfig/cron / TestChainRecover

Function TestChainRecover

chain_test.go:44–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func 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
72type countJob struct {
73 m sync.Mutex

Callers

nothing calls this directly

Calls 6

FuncJobFuncType · 0.85
NewChainFunction · 0.85
RecoverFunction · 0.85
PrintfLoggerFunction · 0.85
ThenMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected