ef0999547a
Add a skip condition to all tests slower than 100ms. This change was made using `gotestsum tool slowest` with data from the last 3 CI runs of master. See https://github.com/gotestyourself/gotestsum#finding-and-skipping-slow-tests With this change: ``` $ time go test -count=1 -short ./agent ok github.com/hashicorp/consul/agent 0.743s real 0m4.791s $ time go test -count=1 -short ./agent/consul ok github.com/hashicorp/consul/agent/consul 4.229s real 0m8.769s ```
34 lines
695 B
Go
34 lines
695 B
Go
package state
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDelay(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("too slow for testing.Short")
|
|
}
|
|
|
|
d := NewDelay()
|
|
|
|
// An unknown key should have a time in the past.
|
|
if exp := d.GetExpiration("nope", nil); !exp.Before(time.Now()) {
|
|
t.Fatalf("bad: %v", exp)
|
|
}
|
|
|
|
// Add a key and set a short expiration.
|
|
now := time.Now()
|
|
delay := 250 * time.Millisecond
|
|
d.SetExpiration("bye", now, delay, nil)
|
|
if exp := d.GetExpiration("bye", nil); !exp.After(now) {
|
|
t.Fatalf("bad: %v", exp)
|
|
}
|
|
|
|
// Wait for the key to expire and check again.
|
|
time.Sleep(2 * delay)
|
|
if exp := d.GetExpiration("bye", nil); !exp.Before(now) {
|
|
t.Fatalf("bad: %v", exp)
|
|
}
|
|
}
|