Skip to content

Commit

Permalink
DAOS-9584 test: Fix slow LeaderQuery test
Browse files Browse the repository at this point in the history
The TestDatabase only needs to be set up once for the
whole suite.

Signed-off-by: Michael MacDonald <[email protected]>
  • Loading branch information
mjmac committed Mar 30, 2022
1 parent fdf70aa commit 2d0bba5
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/control/server/mgmt_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 2d0bba5

Please sign in to comment.