From 051f00468381e2f76476d1678cee8bbdaf0246c5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 22 Apr 2018 14:00:32 -0700 Subject: [PATCH] agent: use helper/retry instead of timing related tests --- agent/agent.go | 7 +++++-- agent/agent_endpoint_test.go | 24 ++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 4d0246b997..3c866bc481 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -295,9 +295,8 @@ func (a *Agent) Start() error { // regular and on-demand state synchronizations (anti-entropy). a.sync = ae.NewStateSyncer(a.State, c.AEInterval, a.shutdownCh, a.logger) - // create the cache and register types + // create the cache a.cache = cache.New(nil) - a.registerCache() // create the config for the rpc server/client consulCfg, err := a.consulConfig() @@ -335,6 +334,10 @@ func (a *Agent) Start() error { a.State.Delegate = a.delegate a.State.TriggerSyncChanges = a.sync.SyncChanges.Trigger + // Register the cache. We do this much later so the delegate is + // populated from above. + a.registerCache() + // Load checks/services/metadata. if err := a.loadServices(c); err != nil { return err diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index 93cffa6173..44dd029233 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -2175,17 +2175,21 @@ func TestAgentConnectCARoots_list(t *testing.T) { require.Nil(a.RPC("Test.ConnectCASetRoots", []*structs.CARoot{ca}, &reply)) - // Sleep a bit to wait for the cache to update - time.Sleep(100 * time.Millisecond) + retry.Run(t, func(r *retry.R) { + // List it again + obj, err := a.srv.AgentConnectCARoots(httptest.NewRecorder(), req) + if err != nil { + r.Fatal(err) + } - // List it again - obj, err := a.srv.AgentConnectCARoots(httptest.NewRecorder(), req) - require.Nil(err) - require.Equal(obj, obj) - - value := obj.(structs.IndexedCARoots) - require.Equal(value.ActiveRootID, ca.ID) - require.Len(value.Roots, 1) + value := obj.(structs.IndexedCARoots) + if ca.ID != value.ActiveRootID { + r.Fatalf("%s != %s", ca.ID, value.ActiveRootID) + } + if len(value.Roots) != 1 { + r.Fatalf("bad len: %d", len(value.Roots)) + } + }) // Should be a cache hit! The data should've updated in the cache // in the background so this should've been fetched directly from