Fix scheduler cleanup edge cases
This commit is contained in:
@@ -2,6 +2,7 @@ package scheduler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -107,6 +108,38 @@ func TestCronEmitsOnDueSlot(t *testing.T) {
|
||||
m.Wait()
|
||||
}
|
||||
|
||||
func TestCronArmErrorCallsStoppedHook(t *testing.T) {
|
||||
old := parseCronSchedule
|
||||
var calls int32
|
||||
parseCronSchedule = func(string) (cron.Schedule, error) {
|
||||
if atomic.AddInt32(&calls, 1) == 1 {
|
||||
return fakeCronSchedule{delay: 10 * time.Millisecond}, nil
|
||||
}
|
||||
return nil, errors.New("boom")
|
||||
}
|
||||
t.Cleanup(func() { parseCronSchedule = old })
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
out := make(chan Event, 10)
|
||||
stopped := make(chan string, 1)
|
||||
m := NewManager(ctx, "a1", out, Hooks{
|
||||
OnStopped: func(id string) { stopped <- id },
|
||||
})
|
||||
m.Update([]config.CheckConfig{mkCronCheck("cron", "true", 100*time.Millisecond)})
|
||||
|
||||
select {
|
||||
case id := <-stopped:
|
||||
if id != "cron" {
|
||||
t.Fatalf("unexpected stopped id: %q", id)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("stopped hook was not called")
|
||||
}
|
||||
m.Stop()
|
||||
m.Wait()
|
||||
}
|
||||
|
||||
func TestNoOverlapSkips(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 600*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user