24 lines
684 B
Go
24 lines
684 B
Go
package reconcile_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/wangjia/pay/internal/reconcile"
|
|
)
|
|
|
|
func TestRunnerRunOnceExecutesAllAndRecoversPanic(t *testing.T) {
|
|
r := reconcile.NewRunner()
|
|
var a, b int
|
|
r.Add("inc-a", time.Minute, func(context.Context) error { a++; return nil })
|
|
r.Add("boom", time.Minute, func(context.Context) error { panic("kaboom") }) // 不得拖垮后续
|
|
r.Add("inc-b", time.Minute, func(context.Context) error { b++; return errors.New("soft") })
|
|
|
|
r.RunOnce(context.Background()) // panic 被 recover,error 被记录,均不中断
|
|
if a != 1 || b != 1 {
|
|
t.Fatalf("a=%d b=%d, want 1/1(panic 任务不应阻断其它)", a, b)
|
|
}
|
|
}
|