From 18d6c338f4914ebf5a12f8fe097f74c35697d9ac Mon Sep 17 00:00:00 2001 From: Derek Menteer <105233703+hashi-derek@users.noreply.github.com> Date: Fri, 4 Nov 2022 10:19:24 -0500 Subject: [PATCH] Backport tests from ent. (#15260) * Backport agent tests. Original commit: 0710b2d12fb51a29cedd1119b5fb086e5c71f632 Original commit: aaedb3c28bfe247266f21013d500147d8decb7cd (partial) * Backport test fix and reduce flaky failures. --- agent/agent_test.go | 12 ++++++++---- .../grpc-external/services/peerstream/stream_test.go | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/agent/agent_test.go b/agent/agent_test.go index ff36a42234..56ec68ed85 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -326,7 +326,9 @@ func TestAgent_HTTPMaxHeaderBytes(t *testing.T) { }, Cache: cache.New(cache.Options{}), } - bd, err = initEnterpriseBaseDeps(bd, nil) + + cfg := config.RuntimeConfig{BuildDate: time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC)} + bd, err = initEnterpriseBaseDeps(bd, &cfg) require.NoError(t, err) a, err := New(bd) @@ -5418,7 +5420,8 @@ func TestAgent_ListenHTTP_MultipleAddresses(t *testing.T) { Cache: cache.New(cache.Options{}), } - bd, err = initEnterpriseBaseDeps(bd, nil) + cfg := config.RuntimeConfig{BuildDate: time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC)} + bd, err = initEnterpriseBaseDeps(bd, &cfg) require.NoError(t, err) agent, err := New(bd) @@ -6003,7 +6006,7 @@ func TestAgent_startListeners(t *testing.T) { Cache: cache.New(cache.Options{}), } - bd, err := initEnterpriseBaseDeps(bd, nil) + bd, err := initEnterpriseBaseDeps(bd, &config.RuntimeConfig{}) require.NoError(t, err) agent, err := New(bd) @@ -6134,7 +6137,8 @@ func TestAgent_startListeners_scada(t *testing.T) { Cache: cache.New(cache.Options{}), } - bd, err := initEnterpriseBaseDeps(bd, nil) + cfg := config.RuntimeConfig{BuildDate: time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC)} + bd, err := initEnterpriseBaseDeps(bd, &cfg) require.NoError(t, err) agent, err := New(bd) diff --git a/agent/grpc-external/services/peerstream/stream_test.go b/agent/grpc-external/services/peerstream/stream_test.go index 9f5f10b406..f3feeae6d1 100644 --- a/agent/grpc-external/services/peerstream/stream_test.go +++ b/agent/grpc-external/services/peerstream/stream_test.go @@ -1159,7 +1159,7 @@ func TestStreamResources_Server_CARootUpdates(t *testing.T) { func TestStreamResources_Server_AckNackNonce(t *testing.T) { srv, store := newTestServer(t, func(c *Config) { - c.incomingHeartbeatTimeout = 50 * time.Millisecond + c.incomingHeartbeatTimeout = 10 * time.Millisecond }) p := writePeeringToBeDialed(t, store, 1, "my-peer") @@ -1204,6 +1204,9 @@ func TestStreamResources_Server_AckNackNonce(t *testing.T) { require.NoError(t, err) require.Equal(t, "5678", msg.GetRequest().ResponseNonce) }) + // Add in a sleep to prevent the test from flaking. + // The mock client expects certain calls to be made. + time.Sleep(50 * time.Millisecond) } // Test that when the client doesn't send a heartbeat in time, the stream is disconnected.