MCPcopy
hub / github.com/grafana/tempo / TestDoForAtLeast

Function TestDoForAtLeast

tempodb/compactor_test.go:751–772  ·  tempodb/compactor_test.go::TestDoForAtLeast
(t *testing.T)

Source from the content-addressed store, hash-verified

749}
750
751func 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
774func TestCompactWithConfig(t *testing.T) {
775 for _, enc := range encoding.AllEncodingsForWrites() {

Callers

nothing calls this directly

Calls 4

doForAtLeastFunction · 0.85
NowMethod · 0.65
SleepMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected