From 3df8d84aae04d34036c3dc0923c95bea4d9817b7 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 18:47:19 -0500 Subject: [PATCH 01/21] skip TestCheckTCPPassing on CircleCI --- agent/checks/check_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/agent/checks/check_test.go b/agent/checks/check_test.go index 226735e29..edffe3b55 100644 --- a/agent/checks/check_test.go +++ b/agent/checks/check_test.go @@ -517,6 +517,9 @@ func TestCheckTCPPassing(t *testing.T) { if os.Getenv("TRAVIS") == "true" { t.Skip("IPV6 not supported on travis-ci") } + if os.Getenv("CIRCLECI") == "true" { + t.Skip("IPV6 not supported on CircleCI") + } tcpServer = mockTCPServer(`tcp6`) expectTCPStatus(t, tcpServer.Addr().String(), api.HealthPassing) tcpServer.Close() From 9543ab6a7c0528e7835fd24a5dbd32f19d600133 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 15 Feb 2019 13:10:02 -0500 Subject: [PATCH 02/21] fix TestAgent_CheckCriticalTime and better error output --- agent/local/state_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/local/state_test.go b/agent/local/state_test.go index 751963946..ab8ba5a92 100644 --- a/agent/local/state_test.go +++ b/agent/local/state_test.go @@ -1733,18 +1733,18 @@ func TestAgent_CheckCriticalTime(t *testing.T) { if c, ok := l.CriticalCheckStates()[checkID]; !ok { t.Fatalf("should have a critical check") } else if c.CriticalFor() > time.Millisecond { - t.Fatalf("bad: %#v", c) + t.Fatalf("bad: %#v, check was critical for %v", c, c.CriticalFor()) } // Wait a while, then fail it again and make sure the time keeps track - // of the initial failure, and doesn't reset here. + // of the initial failure, and doesn't reset here. Since we are sleeping for + // 50ms the check should not be any less than that. time.Sleep(50 * time.Millisecond) l.UpdateCheck(chk.CheckID, api.HealthCritical, "") if c, ok := l.CriticalCheckStates()[checkID]; !ok { t.Fatalf("should have a critical check") - } else if c.CriticalFor() < 25*time.Millisecond || - c.CriticalFor() > 75*time.Millisecond { - t.Fatalf("bad: %#v", c) + } else if c.CriticalFor() < 50*time.Millisecond { + t.Fatalf("bad: %#v, check was critical for %v", c, c.CriticalFor()) } // Set it passing again. @@ -1759,7 +1759,7 @@ func TestAgent_CheckCriticalTime(t *testing.T) { if c, ok := l.CriticalCheckStates()[checkID]; !ok { t.Fatalf("should have a critical check") } else if c.CriticalFor() > time.Millisecond { - t.Fatalf("bad: %#v", c) + t.Fatalf("bad: %#v, check was critical for %v", c, c.CriticalFor()) } } From 8ab8bdda53d3cda554b78fb42d78347bcc89665b Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 20:03:05 -0500 Subject: [PATCH 03/21] add serf check to TestAPI_SemaphoreConflict --- api/semaphore_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/semaphore_test.go b/api/semaphore_test.go index b2ec954ed..0b88e8b25 100644 --- a/api/semaphore_test.go +++ b/api/semaphore_test.go @@ -295,6 +295,7 @@ func TestAPI_SemaphoreConflict(t *testing.T) { t.Parallel() c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) lock, session := createTestLock(t, c, "test/sema/.lock") defer session.Destroy(lock.opts.Session, nil) From d3b56af72ffc713b94bbc212aa16dac93563ba72 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 20:14:26 -0500 Subject: [PATCH 04/21] remove serf check --- api/semaphore_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/semaphore_test.go b/api/semaphore_test.go index 0b88e8b25..b2ec954ed 100644 --- a/api/semaphore_test.go +++ b/api/semaphore_test.go @@ -295,7 +295,6 @@ func TestAPI_SemaphoreConflict(t *testing.T) { t.Parallel() c, s := makeClient(t) defer s.Stop() - s.WaitForSerfCheck(t) lock, session := createTestLock(t, c, "test/sema/.lock") defer session.Destroy(lock.opts.Session, nil) From c8847c421372d68032b130c28713b6012bb61105 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 21:47:19 -0500 Subject: [PATCH 05/21] add wait to TestAgent_RPCPing --- agent/agent_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/agent_test.go b/agent/agent_test.go index a9a100a54..095f56765 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -132,6 +132,7 @@ func TestAgent_RPCPing(t *testing.T) { t.Parallel() a := NewTestAgent(t, t.Name(), "") defer a.Shutdown() + testrpc.WaitForTestAgent(t, a.RPC, "dc1") var out struct{} if err := a.RPC("Status.Ping", struct{}{}, &out); err != nil { From 0bff68928128c9863c82c90a8a2b428e5c9401d2 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 22:11:31 -0500 Subject: [PATCH 06/21] add serf check to TestAPI_AgentServices_ManagedConnectProxyDeprecatedUpstreams --- api/agent_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/agent_test.go b/api/agent_test.go index 221c7d413..ce5a65dfd 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -293,6 +293,7 @@ func TestAPI_AgentServices_ManagedConnectProxyDeprecatedUpstreams(t *testing.T) defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) reg := &AgentServiceRegistration{ Name: "foo", From 255e6c60879246ab994ae632275205e9c32cd9b8 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 17:39:54 -0500 Subject: [PATCH 07/21] add serf check to TestLockCommand --- command/lock/lock_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/lock/lock_test.go b/command/lock/lock_test.go index a1141dfdd..affff5f71 100644 --- a/command/lock/lock_test.go +++ b/command/lock/lock_test.go @@ -45,7 +45,7 @@ func TestLockCommand(t *testing.T) { a := agent.NewTestAgent(t, t.Name(), ``) defer a.Shutdown() - testrpc.WaitForLeader(t, a.RPC, "dc1") + testrpc.WaitForTestAgent(t, a.RPC, "dc1") ui := cli.NewMockUi() c := New(ui) From 9ccaa7f0cadb80f2c61b2351448de851e2b01f0f Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 10:19:19 -0500 Subject: [PATCH 08/21] add serf check to TestAPI_Snapshot --- api/snapshot_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/snapshot_test.go b/api/snapshot_test.go index ba371d4e4..938360d49 100644 --- a/api/snapshot_test.go +++ b/api/snapshot_test.go @@ -11,6 +11,7 @@ func TestAPI_Snapshot(t *testing.T) { c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) // Place an initial key into the store. kv := c.KV() key := &KVPair{Key: testKey(), Value: []byte("hello")} From 6617785b33efd33ca08853eb73358fe83f87c30b Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 10:20:08 -0500 Subject: [PATCH 09/21] add serf check to TestAPI_SemaphoreConflict --- api/semaphore_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/semaphore_test.go b/api/semaphore_test.go index b2ec954ed..81b959b5e 100644 --- a/api/semaphore_test.go +++ b/api/semaphore_test.go @@ -296,6 +296,7 @@ func TestAPI_SemaphoreConflict(t *testing.T) { c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) lock, session := createTestLock(t, c, "test/sema/.lock") defer session.Destroy(lock.opts.Session, nil) From 313408a35fba0d51e27d985a33119217b9623684 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 10:37:09 -0500 Subject: [PATCH 10/21] add serf check to TestAPI_ClientPutGetDelete, TestAPI_ClientWatchGet --- api/kv_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/kv_test.go b/api/kv_test.go index f19cfc1a7..abd21b2d5 100644 --- a/api/kv_test.go +++ b/api/kv_test.go @@ -15,6 +15,7 @@ func TestAPI_ClientPutGetDelete(t *testing.T) { kv := c.KV() + s.WaitForSerfCheck(t) // Get a get without a key key := testKey() pair, _, err := kv.Get(key, nil) @@ -229,6 +230,7 @@ func TestAPI_ClientWatchGet(t *testing.T) { kv := c.KV() + s.WaitForSerfCheck(t) // Get a get without a key key := testKey() pair, meta, err := kv.Get(key, nil) From 6f27454ea02920322fac6f250814d433afdf14c4 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 10:38:39 -0500 Subject: [PATCH 11/21] add serf check to TestAPI_HealthChecks_NodeMetaFilter, TestAPI_HealthConnect --- api/health_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/health_test.go b/api/health_test.go index 9b25b0f3c..e083e5e46 100644 --- a/api/health_test.go +++ b/api/health_test.go @@ -230,6 +230,8 @@ func TestAPI_HealthChecks_NodeMetaFilter(t *testing.T) { agent := c.Agent() health := c.Health() + s.WaitForSerfCheck(t) + // Make a service with a check reg := &AgentServiceRegistration{ Name: "foo", @@ -393,6 +395,8 @@ func TestAPI_HealthConnect(t *testing.T) { agent := c.Agent() health := c.Health() + s.WaitForSerfCheck(t) + // Make a service with a proxy reg := &AgentServiceRegistration{ Name: "foo", From c45a193e3d21e3c360abcba0fe0f8cefe4c8666d Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 13:32:30 -0500 Subject: [PATCH 12/21] add serf check to TestAPI_CoordinateUpdate --- api/coordinate_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/coordinate_test.go b/api/coordinate_test.go index 352620148..9e6f2e27d 100644 --- a/api/coordinate_test.go +++ b/api/coordinate_test.go @@ -71,6 +71,7 @@ func TestAPI_CoordinateUpdate(t *testing.T) { c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) node := "foo" _, err := c.Catalog().Register(&CatalogRegistration{ Node: node, From 9953306901384baa464eb7d6d02d8502970f39c3 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 13:38:21 -0500 Subject: [PATCH 13/21] add serf check to TestAPI_ConnectCARoots_empty, TestAPI_ConnectCAConfig_get_set --- api/connect_ca_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/connect_ca_test.go b/api/connect_ca_test.go index 912920976..97c96c3ed 100644 --- a/api/connect_ca_test.go +++ b/api/connect_ca_test.go @@ -21,6 +21,8 @@ func TestAPI_ConnectCARoots_empty(t *testing.T) { }) defer s.Stop() + s.WaitForSerfCheck(t) + connect := c.Connect() _, _, err := connect.CARoots(nil) @@ -60,6 +62,7 @@ func TestAPI_ConnectCAConfig_get_set(t *testing.T) { c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) expected := &ConsulCAProviderConfig{ RotationPeriod: 90 * 24 * time.Hour, } From 897c5ff74654e93bfcab5e7417c21869d830984b Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 13:39:08 -0500 Subject: [PATCH 14/21] add serf check to TestAPI_CatalogNodes --- api/catalog_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/catalog_test.go b/api/catalog_test.go index 5c73d73b1..7b2ce0a71 100644 --- a/api/catalog_test.go +++ b/api/catalog_test.go @@ -33,6 +33,7 @@ func TestAPI_CatalogNodes(t *testing.T) { c, s := makeClient(t) defer s.Stop() + s.WaitForSerfCheck(t) catalog := c.Catalog() retry.RunWith(retry.ThreeTimes(), t, func(r *retry.R) { nodes, meta, err := catalog.Nodes(nil) From 23417780dc595f915cb96e9a1c23b9d6aa1ae9dd Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 13:41:28 -0500 Subject: [PATCH 15/21] add serf check to various api/agent tests --- api/agent_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/agent_test.go b/api/agent_test.go index ce5a65dfd..17580eaa7 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -39,6 +39,8 @@ func TestAPI_AgentMetrics(t *testing.T) { defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) + timer := &retry.Timer{Timeout: 10 * time.Second, Wait: 500 * time.Millisecond} retry.RunWith(timer, t, func(r *retry.R) { metrics, err := agent.Metrics() @@ -168,6 +170,7 @@ func TestAPI_AgentServices(t *testing.T) { defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) reg := &AgentServiceRegistration{ Name: "foo", @@ -743,6 +746,7 @@ func TestAPI_AgentSetTTLStatus(t *testing.T) { defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) reg := &AgentServiceRegistration{ Name: "foo", @@ -957,6 +961,7 @@ func TestAPI_AgentChecks_serviceBound(t *testing.T) { defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) // First register a service serviceReg := &AgentServiceRegistration{ @@ -1198,6 +1203,7 @@ func TestAPI_NodeMaintenance(t *testing.T) { defer s.Stop() agent := c.Agent() + s.WaitForSerfCheck(t) // Enable maintenance mode if err := agent.EnableNodeMaintenance("broken"); err != nil { From e9919a5d005906182ddb6676ac356ffd6b9fb0f3 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 13:42:09 -0500 Subject: [PATCH 16/21] add serf check to TestAPI_ACLToken_List --- api/acl_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/acl_test.go b/api/acl_test.go index 2a5146f06..ecf4ea044 100644 --- a/api/acl_test.go +++ b/api/acl_test.go @@ -498,6 +498,7 @@ func TestAPI_ACLToken_List(t *testing.T) { defer s.Stop() acl := c.ACL() + s.WaitForSerfCheck(t) policies := prepTokenPolicies(t, acl) From 0cbd8406cccb86262199e2033b6b244f74722db2 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Wed, 20 Feb 2019 12:36:14 -0500 Subject: [PATCH 17/21] add wait to TestSnapshot --- agent/snapshot_endpoint_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/snapshot_endpoint_test.go b/agent/snapshot_endpoint_test.go index 33d58ca12..1d7d66558 100644 --- a/agent/snapshot_endpoint_test.go +++ b/agent/snapshot_endpoint_test.go @@ -9,14 +9,16 @@ import ( "testing" "github.com/hashicorp/consul/acl" + "github.com/hashicorp/consul/testrpc" ) func TestSnapshot(t *testing.T) { t.Parallel() var snap io.Reader - t.Run("", func(t *testing.T) { + t.Run("create snapshot", func(t *testing.T) { a := NewTestAgent(t, t.Name(), "") defer a.Shutdown() + testrpc.WaitForTestAgent(t, a.RPC, "dc1") body := bytes.NewBuffer(nil) req, _ := http.NewRequest("GET", "/v1/snapshot?token=root", body) @@ -40,9 +42,10 @@ func TestSnapshot(t *testing.T) { } }) - t.Run("", func(t *testing.T) { + t.Run("restore snapshot", func(t *testing.T) { a := NewTestAgent(t, t.Name(), "") defer a.Shutdown() + testrpc.WaitForTestAgent(t, a.RPC, "dc1") req, _ := http.NewRequest("PUT", "/v1/snapshot?token=root", snap) resp := httptest.NewRecorder() From f9e7cb987144edf68cddc3fd6ae9afda77d0f656 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 15 Feb 2019 12:24:38 -0500 Subject: [PATCH 18/21] add wait to TestOperator_AutopilotCASConfiguration --- agent/operator_endpoint_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/operator_endpoint_test.go b/agent/operator_endpoint_test.go index f48e4fa29..46add896a 100644 --- a/agent/operator_endpoint_test.go +++ b/agent/operator_endpoint_test.go @@ -346,6 +346,7 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) { t.Parallel() a := NewTestAgent(t, t.Name(), "") defer a.Shutdown() + testrpc.WaitForTestAgent(t, a.RPC, "dc1") body := bytes.NewBuffer([]byte(`{"CleanupDeadServers": false}`)) req, _ := http.NewRequest("PUT", "/v1/operator/autopilot/configuration", body) From 47e1c37fe656010dcfdb616f4ed64373b5086fff Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 15:24:19 -0500 Subject: [PATCH 19/21] add serf check to testDNSServiceLookupResponseLimits, checkDNSService --- agent/dns_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/dns_test.go b/agent/dns_test.go index 34940bfa3..01d1bda4c 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -4151,7 +4151,7 @@ func testDNSServiceLookupResponseLimits(t *testing.T, answerLimit int, qType uin } `) defer a.Shutdown() - testrpc.WaitForLeader(t, a.RPC, "dc1") + testrpc.WaitForTestAgent(t, a.RPC, "dc1") for i := 0; i < generateNumNodes; i++ { nodeAddress := fmt.Sprintf("127.0.0.%d", i+1) @@ -4241,7 +4241,7 @@ func checkDNSService(t *testing.T, generateNumNodes int, aRecordLimit int, qType } `) defer a.Shutdown() - testrpc.WaitForLeader(t, a.RPC, "dc1") + testrpc.WaitForTestAgent(t, a.RPC, "dc1") for i := 0; i < generateNumNodes; i++ { nodeAddress := fmt.Sprintf("127.0.0.%d", i+1) From 2e961d653930dbb6485d7ed9bfdc219091a8df55 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Thu, 21 Feb 2019 16:27:17 -0500 Subject: [PATCH 20/21] add retry to TestResetSessionTimerLocked --- agent/consul/session_ttl_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/agent/consul/session_ttl_test.go b/agent/consul/session_ttl_test.go index de33ee5d0..9f7c0e241 100644 --- a/agent/consul/session_ttl_test.go +++ b/agent/consul/session_ttl_test.go @@ -162,10 +162,11 @@ func TestResetSessionTimerLocked(t *testing.T) { t.Fatalf("missing timer") } - time.Sleep(10 * time.Millisecond * structs.SessionTTLMultiplier) - if s1.sessionTimers.Get("foo") != nil { - t.Fatalf("timer should be gone") - } + retry.Run(t, func(r *retry.R) { + if s1.sessionTimers.Get("foo") != nil { + r.Fatal("timer should be gone") + } + }) } func TestResetSessionTimerLocked_Renew(t *testing.T) { From c4168e6dfcde90009e3b9172805da5ef453e4c08 Mon Sep 17 00:00:00 2001 From: Alvin Huang Date: Fri, 22 Feb 2019 15:40:59 -0500 Subject: [PATCH 21/21] add wait to TestClient_JoinLAN --- agent/consul/client_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agent/consul/client_test.go b/agent/consul/client_test.go index d28e3994e..0fca26333 100644 --- a/agent/consul/client_test.go +++ b/agent/consul/client_test.go @@ -84,8 +84,10 @@ func TestClient_JoinLAN(t *testing.T) { defer os.RemoveAll(dir2) defer c1.Shutdown() + testrpc.WaitForLeader(t, s1.RPC, "dc1") // Try to join joinLAN(t, c1, s1) + testrpc.WaitForTestAgent(t, c1.RPC, "dc1") retry.Run(t, func(r *retry.R) { if got, want := c1.routers.NumServers(), 1; got != want { r.Fatalf("got %d servers want %d", got, want)