File tree Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -242,7 +242,6 @@ func (s *Service) deleteTaskExecutionsRoutine(ctx context.Context) error {
242242func (s * Service ) dequeueTaskExecutions (ctx context.Context ) error {
243243 for {
244244 if ctx .Err () != nil {
245- log .Error (ctx , "dequeueTaskExecutions> exiting go routine: %v" , ctx .Err ())
246245 return ctx .Err ()
247246 }
248247 size , err := s .Dao .QueueLen ()
@@ -261,14 +260,15 @@ func (s *Service) dequeueTaskExecutions(ctx context.Context) error {
261260 // Dequeuing context
262261 var taskKey string
263262 if ctx .Err () != nil {
264- log .Error (ctx , "dequeueTaskExecutions> exiting go routine: %v" , err )
265263 return ctx .Err ()
266264 }
267265 if err := s .Cache .DequeueWithContext (ctx , schedulerQueueKey , & taskKey ); err != nil {
268- log .Error (ctx , "dequeueTaskExecutions> store.DequeueWithContext err: %v" , err )
269266 continue
270267 }
271268 s .Dao .dequeuedIncr ()
269+ if taskKey == "" {
270+ continue
271+ }
272272 log .Info (ctx , "dequeueTaskExecutions> work on taskKey: %s" , taskKey )
273273
274274 // Load the task execution
Original file line number Diff line number Diff line change @@ -92,9 +92,7 @@ func Test_dequeueTaskExecutions_ScheduledTask(t *testing.T) {
9292
9393 // Start the goroutine
9494 go func () {
95- if err := s .dequeueTaskExecutions (ctx ); err != nil {
96- t .Logf ("dequeueTaskExecutions error: %v" , err )
97- }
95+ s .dequeueTaskExecutions (ctx ) // nolint
9896 }()
9997
10098 h := & sdk.NodeHook {
Original file line number Diff line number Diff line change 77 "io/ioutil"
88 "os"
99 "strings"
10+ "testing"
1011
1112 log "github.com/sirupsen/logrus"
1213
@@ -48,8 +49,39 @@ type Logger interface {
4849 Fatalf (fmt string , values ... interface {})
4950}
5051
52+ type TestingLogger struct {
53+ t * testing.T
54+ }
55+
56+ var _ Logger = new (TestingLogger )
57+
58+ func (t * TestingLogger ) isDone () bool {
59+ return t .t .Failed () || t .t .Skipped ()
60+ }
61+
62+ func (t * TestingLogger ) Logf (fmt string , values ... interface {}) {
63+ if ! t .isDone () {
64+ t .t .Logf (fmt , values ... )
65+ }
66+ }
67+ func (t * TestingLogger ) Errorf (fmt string , values ... interface {}) {
68+ if ! t .isDone () {
69+ t .t .Errorf (fmt , values ... )
70+ }
71+ }
72+ func (t * TestingLogger ) Fatalf (fmt string , values ... interface {}) {
73+ if ! t .isDone () {
74+ t .t .Fatalf (fmt , values ... )
75+ }
76+ }
77+
5178// SetLogger replace logrus logger with custom one.
5279func SetLogger (l Logger ) {
80+ t , isTesting := l .(* testing.T )
81+ if isTesting {
82+ logger = & TestingLogger {t : t }
83+ return
84+ }
5385 logger = l
5486}
5587
You can’t perform that action at this time.
0 commit comments