| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func TestPeriodicallyDo(t *testing.T) { |
| ctx, cancel := context.WithCancel(context.Background()) |
| didWork := make(chan time.Time, 2) |
| done := make(chan interface{}) |
| PeriodicallyDo(ctx, time.Millisecond, func(ctx context.Context, t time.Time) { |
| case <-time.After(5 * time.Second): |
| t.Error("PeriodicallyDo() never called f, wanted at least one call") |
| // PeriodicallyDo called f successfully. |
| t.Errorf("PeriodicallyDo() finished early, wanted it to still be looping") |