(t *testing.T)
| 749 | } |
| 750 | |
| 751 | func TestDoForAtLeast(t *testing.T) { |
| 752 | // test that it runs for at least the duration |
| 753 | start := time.Now() |
| 754 | doForAtLeast(context.Background(), time.Second, func() { time.Sleep(time.Millisecond) }) |
| 755 | require.WithinDuration(t, time.Now(), start.Add(time.Second), 100*time.Millisecond) |
| 756 | |
| 757 | // test that it allows func to overrun |
| 758 | start = time.Now() |
| 759 | doForAtLeast(context.Background(), time.Second, func() { time.Sleep(2 * time.Second) }) |
| 760 | require.WithinDuration(t, time.Now(), start.Add(2*time.Second), 100*time.Millisecond) |
| 761 | |
| 762 | // make sure cancelling the context stops the function if the function is complete and we're |
| 763 | // just waiting. it is presumed, but not enforced that the function responds to a cancelled contxt |
| 764 | ctx, cancel := context.WithCancel(context.Background()) |
| 765 | start = time.Now() |
| 766 | go func() { |
| 767 | time.Sleep(time.Second) |
| 768 | cancel() |
| 769 | }() |
| 770 | doForAtLeast(ctx, 2*time.Second, func() {}) |
| 771 | require.WithinDuration(t, time.Now(), start.Add(time.Second), 100*time.Millisecond) |
| 772 | } |
| 773 | |
| 774 | func TestCompactWithConfig(t *testing.T) { |
| 775 | for _, enc := range encoding.AllEncodingsForWrites() { |
nothing calls this directly
no test coverage detected