From 2d0bba543212229415b630cafd5b442cc44db4c8 Mon Sep 17 00:00:00 2001 From: Michael MacDonald Date: Wed, 30 Mar 2022 18:21:45 +0000 Subject: [PATCH] DAOS-9584 test: Fix slow LeaderQuery test The TestDatabase only needs to be set up once for the whole suite. Signed-off-by: Michael MacDonald --- src/control/server/mgmt_system_test.go | 37 ++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/control/server/mgmt_system_test.go b/src/control/server/mgmt_system_test.go index 251d64f0f76..50024bbb849 100644 --- a/src/control/server/mgmt_system_test.go +++ b/src/control/server/mgmt_system_test.go @@ -220,6 +220,25 @@ func stateString(s system.MemberState) string { func TestServer_MgmtSvc_LeaderQuery(t *testing.T) { localhost := common.LocalhostCtrlAddr() + log, buf := logging.NewTestLogger(t.Name()) + + db, cleanup := system.TestDatabase(t, log) + defer cleanup() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + if err := db.Start(ctx); err != nil { + t.Fatal(err) + } + + // wait for the bootstrap to finish + for { + if leader, _, _ := db.LeaderQuery(); leader != "" { + break + } + time.Sleep(250 * time.Millisecond) + } for name, tc := range map[string]struct { req *mgmtpb.LeaderQueryReq @@ -244,28 +263,12 @@ func TestServer_MgmtSvc_LeaderQuery(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - log, buf := logging.NewTestLogger(t.Name()) + buf.Reset() defer common.ShowBufferOnFailure(t, buf) svc := newTestMgmtSvc(t, log) - db, cleanup := system.TestDatabase(t, log) - defer cleanup() svc.sysdb = db - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - if err := db.Start(ctx); err != nil { - t.Fatal(err) - } - - // wait for the bootstrap to finish - for { - if leader, _, _ := db.LeaderQuery(); leader != "" { - break - } - time.Sleep(250 * time.Millisecond) - } - gotResp, gotErr := svc.LeaderQuery(context.TODO(), tc.req) common.CmpErr(t, tc.expErr, gotErr) if tc.expErr != nil {