test: Speedup session renew tests

pull/2968/head
Frank Schroeder 2017-04-27 02:46:38 -07:00 committed by Frank Schröder
parent f763c24c69
commit 7281b4291a
2 changed files with 18 additions and 17 deletions

View File

@ -221,18 +221,17 @@ func TestSessionDestroy(t *testing.T) {
}) })
} }
func TestSessionTTL(t *testing.T) { func TestSessionCustomTTL(t *testing.T) {
t.Parallel() t.Parallel()
// use the minimum legal ttl ttl := 250 * time.Millisecond
testSessionTTL(t, 10*time.Second, nil) testSessionTTL(t, ttl, customTTL(ttl))
} }
func TestSessionTTLConfig(t *testing.T) { func customTTL(d time.Duration) func(c *Config) {
t.Parallel() return func(c *Config) {
testSessionTTL(t, 1*time.Second, func(c *Config) { c.SessionTTLMinRaw = d.String()
c.SessionTTLMinRaw = "1s" c.SessionTTLMin = d
c.SessionTTLMin = 1 * time.Second }
})
} }
func testSessionTTL(t *testing.T, ttl time.Duration, cb func(c *Config)) { 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) { func TestSessionTTLRenew(t *testing.T) {
t.Parallel() t.Parallel()
httpTest(t, func(srv *HTTPServer) { ttl := 250 * time.Millisecond
TTL := "10s" // use the minimum legal ttl TTL := ttl.String()
ttl := 10 * time.Second httpTestWithConfig(t, func(srv *HTTPServer) {
id := makeTestSessionTTL(t, srv, TTL) id := makeTestSessionTTL(t, srv, TTL)
req, err := http.NewRequest("GET", req, err := http.NewRequest("GET",
@ -354,7 +352,7 @@ func TestSessionTTLRenew(t *testing.T) {
if len(respObj) != 0 { if len(respObj) != 0 {
t.Fatalf("session '%s' should have destroyed", id) t.Fatalf("session '%s' should have destroyed", id)
} }
}) }, customTTL(ttl))
} }
func TestSessionGet(t *testing.T) { func TestSessionGet(t *testing.T) {

View File

@ -532,15 +532,18 @@ func TestSession_ApplyTimers(t *testing.T) {
} }
func TestSession_Renew(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 os.RemoveAll(dir1)
defer s1.Shutdown() defer s1.Shutdown()
codec := rpcClient(t, s1) codec := rpcClient(t, s1)
defer codec.Close() defer codec.Close()
testrpc.WaitForLeader(t, s1.RPC, "dc1") 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"}) s1.fsm.State().EnsureNode(1, &structs.Node{Node: "foo", Address: "127.0.0.1"})
ids := []string{} ids := []string{}