agent: use helper/retry instead of timing related tests

This commit is contained in:
Mitchell Hashimoto 2018-04-22 14:00:32 -07:00
parent bd3b8e042a
commit 051f004683
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 19 additions and 12 deletions

View File

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

View File

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