mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
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:
@@ -56,7 +56,7 @@ func TestInitialize(t *testing.T) {
|
|||||||
for name, test := range tests {
|
for name, test := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
db := new()
|
db := new()
|
||||||
dbtesting.AssertInitialize(t, db, test.req)
|
dbtesting.AssertInitializeCircleCiTest(t, db, test.req)
|
||||||
defer dbtesting.AssertClose(t, db)
|
defer dbtesting.AssertClose(t, db)
|
||||||
|
|
||||||
if !db.Initialized {
|
if !db.Initialized {
|
||||||
@@ -144,7 +144,7 @@ func TestNewUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db := new()
|
db := new()
|
||||||
dbtesting.AssertInitialize(t, db, initReq)
|
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
|
||||||
defer dbtesting.AssertClose(t, db)
|
defer dbtesting.AssertClose(t, db)
|
||||||
|
|
||||||
createResp, err := db.NewUser(context.Background(), test.req)
|
createResp, err := db.NewUser(context.Background(), test.req)
|
||||||
@@ -250,7 +250,7 @@ func TestUpdateUser_password(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db := new()
|
db := new()
|
||||||
dbtesting.AssertInitialize(t, db, initReq)
|
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
|
||||||
defer dbtesting.AssertClose(t, db)
|
defer dbtesting.AssertClose(t, db)
|
||||||
|
|
||||||
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)
|
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)
|
||||||
@@ -313,7 +313,8 @@ func TestDeleteUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db := new()
|
db := new()
|
||||||
dbtesting.AssertInitialize(t, db, initReq)
|
|
||||||
|
dbtesting.AssertInitializeCircleCiTest(t, db, initReq)
|
||||||
defer dbtesting.AssertClose(t, db)
|
defer dbtesting.AssertClose(t, db)
|
||||||
|
|
||||||
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)
|
createTestMSSQLUser(t, connURL, dbUser, initPassword, testMSSQLLogin)
|
||||||
|
|||||||
@@ -22,19 +22,47 @@ func getRequestTimeout(t *testing.T) time.Duration {
|
|||||||
return dur
|
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 {
|
func AssertInitialize(t *testing.T, db dbplugin.Database, req dbplugin.InitializeRequest) dbplugin.InitializeResponse {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
resp, err := verifyInitialize(t, db, req)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), getRequestTimeout(t))
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
resp, err := db.Initialize(ctx, req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to initialize: %s", err)
|
t.Fatalf("Failed to initialize: %s", err)
|
||||||
}
|
}
|
||||||
return resp
|
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 {
|
func AssertNewUser(t *testing.T, db dbplugin.Database, req dbplugin.NewUserRequest) dbplugin.NewUserResponse {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user