From 36bf99ebc73f68473fa079b4c512a0a6437d7834 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Tue, 19 Feb 2019 23:37:37 -0500 Subject: [PATCH] Fixing invalid use of time.Timer. Timer fires only once. Needs to be recreated. --- event/event_test.go | 5 ++--- termdash_test.go | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/event/event_test.go b/event/event_test.go index 5b7b3b9..a477504 100644 --- a/event/event_test.go +++ b/event/event_test.go @@ -89,9 +89,8 @@ func (r *receiver) waitFor(want int, timeout time.Duration) (map[terminalapi.Eve ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - tick := time.NewTimer(5 * time.Millisecond) - defer tick.Stop() for { + tick := time.NewTimer(5 * time.Millisecond) select { case <-tick.C: ev := r.getEvents() @@ -106,7 +105,7 @@ func (r *receiver) waitFor(want int, timeout time.Duration) (map[terminalapi.Eve case <-ctx.Done(): ev := r.getEvents() - return nil, fmt.Errorf("while waiting for events, got %d so far: %v, err: %v", len(ev), ev, ctx.Err()) + return nil, fmt.Errorf("while waiting for events, got %d so far: %v, want %d, err: %v", len(ev), ev, want, ctx.Err()) } } } diff --git a/termdash_test.go b/termdash_test.go index 51be414..13f9dcb 100644 --- a/termdash_test.go +++ b/termdash_test.go @@ -564,9 +564,8 @@ func untilEmpty(timeout time.Duration, q *eventqueue.Unbound) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - tick := time.NewTimer(5 * time.Millisecond) - defer tick.Stop() for { + tick := time.NewTimer(5 * time.Millisecond) select { case <-tick.C: if q.Empty() {