chore: test timeout behaviour (#26554)
Some checks failed
Some checks failed
This commit is contained in:
parent
c335df19fc
commit
cbf3bd82af
3 changed files with 23 additions and 6 deletions
|
|
@ -31,8 +31,9 @@ func NewMonitor[T any](timeout time.Duration) *Monitor[T] {
|
|||
}
|
||||
|
||||
// WithClock sets the a clock for debugging
|
||||
func (m *Monitor[T]) WithClock(clock clock.Clock) {
|
||||
func (m *Monitor[T]) WithClock(clock clock.Clock) *Monitor[T] {
|
||||
m.clock = clock
|
||||
return m
|
||||
}
|
||||
|
||||
// Set updates the current value and timestamp
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/benbjohnson/clock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMonitorRacyMaps(t *testing.T) {
|
||||
|
|
@ -42,13 +43,29 @@ func TestMonitorRacyMaps(t *testing.T) {
|
|||
default:
|
||||
err := m.GetFunc(func(mm map[int]int) {
|
||||
for k, v := range mm {
|
||||
require.Equal(t, k, v)
|
||||
assert.Equal(t, k, v)
|
||||
}
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestMonitorWithoutTimeout(t *testing.T) {
|
||||
clock := clock.NewMock()
|
||||
m := NewMonitor[int](0).WithClock(clock)
|
||||
|
||||
_, err := m.Get()
|
||||
assert.Error(t, err)
|
||||
|
||||
m.Set(0)
|
||||
_, err = m.Get()
|
||||
assert.NoError(t, err)
|
||||
|
||||
clock.Add(time.Hour)
|
||||
_, err = m.Get()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue