From 409fd57e4af0626f6731b4ed2ebd087ff459672b Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 14 Oct 2015 02:22:03 -0700 Subject: [PATCH] Adds a delay test. --- consul/state/delay_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 consul/state/delay_test.go diff --git a/consul/state/delay_test.go b/consul/state/delay_test.go new file mode 100644 index 000000000..68f67d3be --- /dev/null +++ b/consul/state/delay_test.go @@ -0,0 +1,29 @@ +package state + +import ( + "testing" + "time" +) + +func TestDelay(t *testing.T) { + d := NewDelay() + + // An unknown key should have a time in the past. + if exp := d.GetExpiration("nope"); !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) + if exp := d.GetExpiration("bye"); !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"); !exp.Before(now) { + t.Fatalf("bad: %v", exp) + } +}