mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-05 21:49:03 +01:00
fix test timing
This commit is contained in:
parent
d9dfae625b
commit
cfac8c4762
@ -6,11 +6,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewHealthPeriod(t *testing.T) {
|
func TestMain(m *testing.M) {
|
||||||
// override the health check interval to speed up the test
|
// override the health check interval to speed up the test
|
||||||
healthCheckInterval = 1 * time.Second
|
healthCheckInterval = 1 * time.Second
|
||||||
healthCheckTimeout = 100 * time.Millisecond
|
healthCheckTimeout = 100 * time.Millisecond
|
||||||
|
m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewHealthPeriod(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
hc := NewSender(ctx)
|
hc := NewSender(ctx)
|
||||||
@ -30,10 +33,6 @@ func TestNewHealthPeriod(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewHealthFailed(t *testing.T) {
|
func TestNewHealthFailed(t *testing.T) {
|
||||||
// override the health check interval to speed up the test
|
|
||||||
healthCheckInterval = 1 * time.Second
|
|
||||||
healthCheckTimeout = 500 * time.Millisecond
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
hc := NewSender(ctx)
|
hc := NewSender(ctx)
|
||||||
@ -46,18 +45,17 @@ func TestNewHealthFailed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewHealthcheckStop(t *testing.T) {
|
func TestNewHealthcheckStop(t *testing.T) {
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
hc := NewSender(ctx)
|
hc := NewSender(ctx)
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(300 * time.Millisecond)
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-hc.HealthCheck:
|
case <-hc.HealthCheck:
|
||||||
t.Fatalf("is not closed")
|
t.Fatalf("health check on received")
|
||||||
case <-hc.Timeout:
|
case <-hc.Timeout:
|
||||||
t.Fatalf("is not closed")
|
t.Fatalf("health check timedout")
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// expected
|
// expected
|
||||||
case <-time.After(1 * time.Second):
|
case <-time.After(1 * time.Second):
|
||||||
|
Loading…
Reference in New Issue
Block a user