From c0d37981546b2e58b0d2367d96ca7dc478aeea11 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 12 Dec 2014 21:54:29 -0800 Subject: [PATCH] consul: Test Session.Apply updates session timers --- consul/session_endpoint_test.go | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/consul/session_endpoint_test.go b/consul/session_endpoint_test.go index a9446f22c..fa721ada9 100644 --- a/consul/session_endpoint_test.go +++ b/consul/session_endpoint_test.go @@ -225,6 +225,47 @@ func TestSessionEndpoint_List(t *testing.T) { } } +func TestSessionEndpoint_ApplyTimers(t *testing.T) { + dir1, s1 := testServer(t) + defer os.RemoveAll(dir1) + defer s1.Shutdown() + client := rpcClient(t, s1) + defer client.Close() + + testutil.WaitForLeader(t, client.Call, "dc1") + + s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"}) + arg := structs.SessionRequest{ + Datacenter: "dc1", + Op: structs.SessionCreate, + Session: structs.Session{ + Node: "foo", + TTL: "10s", + }, + } + var out string + if err := client.Call("Session.Apply", &arg, &out); err != nil { + t.Fatalf("err: %v", err) + } + + // Check the session map + if _, ok := s1.sessionTimers[out]; !ok { + t.Fatalf("missing session timer") + } + + // Destroy the session + arg.Op = structs.SessionDestroy + arg.Session.ID = out + if err := client.Call("Session.Apply", &arg, &out); err != nil { + t.Fatalf("err: %v", err) + } + + // Check the session map + if _, ok := s1.sessionTimers[out]; ok { + t.Fatalf("session timer exists") + } +} + func TestSessionEndpoint_Renew(t *testing.T) { dir1, s1 := testServer(t) defer os.RemoveAll(dir1) @@ -254,6 +295,11 @@ func TestSessionEndpoint_Renew(t *testing.T) { ids = append(ids, out) } + // Verify the timer map is setup + if len(s1.sessionTimers) != 5 { + t.Fatalf("missing session timers") + } + getR := structs.DCSpecificRequest{ Datacenter: "dc1", }