diff --git a/engine/hooks/scheduler.go b/engine/hooks/scheduler.go index f88c81b302..3b86c18448 100644 --- a/engine/hooks/scheduler.go +++ b/engine/hooks/scheduler.go @@ -242,7 +242,6 @@ func (s *Service) deleteTaskExecutionsRoutine(ctx context.Context) error { func (s *Service) dequeueTaskExecutions(ctx context.Context) error { for { if ctx.Err() != nil { - log.Error(ctx, "dequeueTaskExecutions> exiting go routine: %v", ctx.Err()) return ctx.Err() } size, err := s.Dao.QueueLen() @@ -261,14 +260,15 @@ func (s *Service) dequeueTaskExecutions(ctx context.Context) error { // Dequeuing context var taskKey string if ctx.Err() != nil { - log.Error(ctx, "dequeueTaskExecutions> exiting go routine: %v", err) return ctx.Err() } if err := s.Cache.DequeueWithContext(ctx, schedulerQueueKey, &taskKey); err != nil { - log.Error(ctx, "dequeueTaskExecutions> store.DequeueWithContext err: %v", err) continue } s.Dao.dequeuedIncr() + if taskKey == "" { + continue + } log.Info(ctx, "dequeueTaskExecutions> work on taskKey: %s", taskKey) // Load the task execution diff --git a/engine/hooks/tasks_test.go b/engine/hooks/tasks_test.go index bb10b83c33..8b9372cd93 100644 --- a/engine/hooks/tasks_test.go +++ b/engine/hooks/tasks_test.go @@ -92,9 +92,7 @@ func Test_dequeueTaskExecutions_ScheduledTask(t *testing.T) { // Start the goroutine go func() { - if err := s.dequeueTaskExecutions(ctx); err != nil { - t.Logf("dequeueTaskExecutions error: %v", err) - } + s.dequeueTaskExecutions(ctx) // nolint }() h := &sdk.NodeHook{ diff --git a/sdk/log/log.go b/sdk/log/log.go index 62ade2a6ef..b5120ef381 100644 --- a/sdk/log/log.go +++ b/sdk/log/log.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "strings" + "testing" log "github.com/sirupsen/logrus" @@ -48,8 +49,39 @@ type Logger interface { Fatalf(fmt string, values ...interface{}) } +type TestingLogger struct { + t *testing.T +} + +var _ Logger = new(TestingLogger) + +func (t *TestingLogger) isDone() bool { + return t.t.Failed() || t.t.Skipped() +} + +func (t *TestingLogger) Logf(fmt string, values ...interface{}) { + if !t.isDone() { + t.t.Logf(fmt, values...) + } +} +func (t *TestingLogger) Errorf(fmt string, values ...interface{}) { + if !t.isDone() { + t.t.Errorf(fmt, values...) + } +} +func (t *TestingLogger) Fatalf(fmt string, values ...interface{}) { + if !t.isDone() { + t.t.Fatalf(fmt, values...) + } +} + // SetLogger replace logrus logger with custom one. func SetLogger(l Logger) { + t, isTesting := l.(*testing.T) + if isTesting { + logger = &TestingLogger{t: t} + return + } logger = l }