chore: test timeout behaviour (#26554)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2026-01-09 11:39:36 +01:00 • committed by GitHub
parent c335df19fc
commit cbf3bd82af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View file

@ -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

View file

@ -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)
}