common/daemon: experiment with the test/synctest package

This commit is contained in:
Vincent Bernat
2025-08-30 19:48:52 +02:00
parent 1a0ed7d98a
commit bd787e654f

View File

@@ -6,7 +6,7 @@ package daemon
import (
"errors"
"testing"
"time"
"testing/synctest"
"gopkg.in/tomb.v2"
@@ -71,6 +71,7 @@ func TestStop(t *testing.T) {
}
func TestTombTracking(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
var tomb tomb.Tomb
r := reporter.NewMock(t)
c, err := New(r)
@@ -91,7 +92,7 @@ func TestTombTracking(t *testing.T) {
}
return nil
})
time.Sleep(10 * time.Millisecond) // should be runtime.Gosched()
synctest.Wait()
select {
case <-tomb.Dying():
@@ -104,7 +105,7 @@ func TestTombTracking(t *testing.T) {
close(ch)
tomb.Wait()
time.Sleep(10 * time.Millisecond) // should be runtime.Gosched(), but this is not enough
synctest.Wait()
select {
case <-c.Terminated():
// OK
@@ -113,4 +114,5 @@ func TestTombTracking(t *testing.T) {
}
c.Stop()
})
}