mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/daemon: experiment with the test/synctest package
This commit is contained in:
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user