From 7d465f63562a33b169e15a62facb9a3206299ed0 Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Fri, 12 Nov 2021 10:01:33 +0800 Subject: [PATCH] add TestWaitDBUp --- common/types.go | 3 +++ common/types_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/common/types.go b/common/types.go index 4f7f74a..4be83a3 100644 --- a/common/types.go +++ b/common/types.go @@ -197,6 +197,9 @@ func checkConfig() string { func WaitDBUp() { sdb, err := dtmimp.StandaloneDB(DtmConfig.DB) dtmimp.FatalIfError(err) + defer func() { + sdb.Close() + }() for _, err := dtmimp.DBExec(sdb, "select 1"); err != nil; { // wait for mysql to start time.Sleep(3 * time.Second) _, err = dtmimp.DBExec(sdb, "select 1") diff --git a/common/types_test.go b/common/types_test.go index 84d4c32..ed3c30f 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -19,6 +19,10 @@ func TestDb(t *testing.T) { assert.NotEqual(t, nil, err) } +func TestWaitDBUp(t *testing.T) { + WaitDBUp() +} + func TestDbAlone(t *testing.T) { db, err := dtmimp.StandaloneDB(DtmConfig.DB) assert.Nil(t, err)