From 9a2063bf6fa597ac300232813b4902f6c8f6ff74 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Thu, 27 Apr 2017 02:46:38 -0700 Subject: [PATCH] test: Speedup session renew tests --- command/agent/session_endpoint_test.go | 26 ++++++++++++-------------- consul/session_endpoint_test.go | 9 ++++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/command/agent/session_endpoint_test.go b/command/agent/session_endpoint_test.go index b403a9b1c..e54a1d907 100644 --- a/command/agent/session_endpoint_test.go +++ b/command/agent/session_endpoint_test.go @@ -221,18 +221,17 @@ func TestSessionDestroy(t *testing.T) { }) } -func TestSessionTTL(t *testing.T) { +func TestSessionCustomTTL(t *testing.T) { t.Parallel() - // use the minimum legal ttl - testSessionTTL(t, 10*time.Second, nil) + ttl := 250 * time.Millisecond + testSessionTTL(t, ttl, customTTL(ttl)) } -func TestSessionTTLConfig(t *testing.T) { - t.Parallel() - testSessionTTL(t, 1*time.Second, func(c *Config) { - c.SessionTTLMinRaw = "1s" - c.SessionTTLMin = 1 * time.Second - }) +func customTTL(d time.Duration) func(c *Config) { + return func(c *Config) { + c.SessionTTLMinRaw = d.String() + c.SessionTTLMin = d + } } func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) { @@ -277,10 +276,9 @@ func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) { func TestSessionTTLRenew(t *testing.T) { t.Parallel() - httpTest(t, func(srv *HTTPServer) { - TTL := "10s" // use the minimum legal ttl - ttl := 10 * time.Second - + ttl := 250 * time.Millisecond + TTL := ttl.String() + httpTestWithConfig(t, func(srv *HTTPServer) { id := makeTestSessionTTL(t, srv, TTL) req, err := http.NewRequest("GET", @@ -354,7 +352,7 @@ func TestSessionTTLRenew(t *testing.T) { if len(respObj) != 0 { t.Fatalf("session '%s' should have destroyed", id) } - }) + }, customTTL(ttl)) } func TestSessionGet(t *testing.T) { diff --git a/consul/session_endpoint_test.go b/consul/session_endpoint_test.go index b4ed3d23a..f5ca6bb7b 100644 --- a/consul/session_endpoint_test.go +++ b/consul/session_endpoint_test.go @@ -532,15 +532,18 @@ func TestSession_ApplyTimers(t *testing.T) { } func TestSession_Renew(t *testing.T) { - dir1, s1 := testServer(t) + ttl := 250 * time.Millisecond + TTL := ttl.String() + + dir1, s1 := testServerWithConfig(t, func(c *Config) { + c.SessionTTLMin = ttl + }) defer os.RemoveAll(dir1) defer s1.Shutdown() codec := rpcClient(t, s1) defer codec.Close() testrpc.WaitForLeader(t, s1.RPC, "dc1") - TTL := "10s" // the minimum allowed ttl - ttl := 10 * time.Second s1.fsm.State().EnsureNode(1, &structs.Node{Node: "foo", Address: "127.0.0.1"}) ids := []string{}