test: Speedup session renew tests

This commit is contained in:
Frank Schroeder 2017-04-27 02:46:38 -07:00 committed by Frank Schröder
parent 8feb9e5423
commit 9a2063bf6f
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()
// 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) {

View File

@ -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{}