Add extra debugging to help identify failures within mssql test (#13142)

* Add extra debugging to help identify failures within mssql test
* Switch up the AssertInitialized method for mssql tests by marking the test as failed instead of
   immediately failing, this will also allow us to see what happens even if this assertion fails to the rest
   of the test.
This commit is contained in:
Steven Clark
2021-11-15 12:51:16 -05:00
committed by GitHub
parent 26970c4b1a
commit c749b1ddbe
2 changed files with 38 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ func TestInitialize(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
db := new()
dbtesting.AssertInitialize(t, db, test.req)
dbtesting.AssertInitializeCircleCiTest(t, db, test.req)
defer dbtesting.AssertClose(t, db)
if !db.Initialized {
@@ -144,7 +144,7 @@ func TestNewUser(t *testing.T) {
}
db := new()
dbtesting.AssertInitialize(t, db, initReq)
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
defer dbtesting.AssertClose(t, db)
createResp, err := db.NewUser(context.Background(), test.req)
@@ -250,7 +250,7 @@ func TestUpdateUser_password(t *testing.T) {
}
db := new()
dbtesting.AssertInitialize(t, db, initReq)
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
defer dbtesting.AssertClose(t, db)
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)
@@ -313,7 +313,8 @@ func TestDeleteUser(t *testing.T) {
}
db := new()
dbtesting.AssertInitialize(t, db, initReq)
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
defer dbtesting.AssertClose(t, db)
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)

View File

@@ -22,19 +22,47 @@ func getRequestTimeout(t *testing.T) time.Duration {
return dur
}
// AssertInitializeCircleCiTest help to diagnose CircleCI failures within AssertInitialize for mssql tests failing
// with "Failed to initialize: error verifying connection ...". This will now mark a test as failed instead of being fatal
func AssertInitializeCircleCiTest(t *testing.T, db dbplugin.Database, req dbplugin.InitializeRequest) dbplugin.InitializeResponse {
t.Helper()
maxAttempts := 5
var resp dbplugin.InitializeResponse
var err error
for i := 1; i <= maxAttempts; i++ {
resp, err = verifyInitialize(t, db, req)
if err != nil {
t.Errorf("Failed AssertInitialize attempt: %d with error:\n%+v\n", i, err)
time.Sleep(1 * time.Second)
continue
}
if i > 1 {
t.Logf("AssertInitialize worked the %d time around with a 1 second sleep", i)
}
break
}
return resp
}
func AssertInitialize(t *testing.T, db dbplugin.Database, req dbplugin.InitializeRequest) dbplugin.InitializeResponse {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), getRequestTimeout(t))
defer cancel()
resp, err := db.Initialize(ctx, req)
resp, err := verifyInitialize(t, db, req)
if err != nil {
t.Fatalf("Failed to initialize: %s", err)
}
return resp
}
func verifyInitialize(t *testing.T, db dbplugin.Database, req dbplugin.InitializeRequest) (dbplugin.InitializeResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), getRequestTimeout(t))
defer cancel()
return db.Initialize(ctx, req)
}
func AssertNewUser(t *testing.T, db dbplugin.Database, req dbplugin.NewUserRequest) dbplugin.NewUserResponse {
t.Helper()