Skip to content

Commit

Permalink
ci: Resolve flaky test issues (ory#1234)
Browse files Browse the repository at this point in the history
Signed-off-by: aeneasr <[email protected]>
  • Loading branch information
aeneasr authored Dec 13, 2018
1 parent 30a7c8e commit bff47d2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
6 changes: 4 additions & 2 deletions client/x_manager_sql_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ var createMigrations = map[string]*dbal.PackrMigrationSource{
}

func CleanTestDB(t *testing.T, db *sqlx.DB) {
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client")
_, err := db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_client")
t.Logf("Unable to execute clean up query: %s", err)
}

func TestXXMigrations(t *testing.T) {
Expand Down
30 changes: 20 additions & 10 deletions consent/x_manager_sql_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,34 @@ var createMigrations = map[string]*dbal.PackrMigrationSource{
}

func cleanDB(t *testing.T, db *sqlx.DB) {
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_consent_migration")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
_, err := db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_consent_migration")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
t.Logf("Unable to execute clean up query: %s", err)

// hydra_oauth2_consent_request_handled depends on hydra_oauth2_consent_request
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request_handled")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request_handled")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request")
t.Logf("Unable to execute clean up query: %s", err)

// hydra_oauth2_authentication_request_handled depends on hydra_oauth2_authentication_request
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request_handled")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request_handled")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request")
t.Logf("Unable to execute clean up query: %s", err)

// everything depends on hydra_oauth2_authentication_session
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_session")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_session")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
t.Logf("Unable to execute clean up query: %s", err)

// everything depends on hydra_client
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_client")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
t.Logf("Unable to execute clean up query: %s", err)
}

func TestXXMigrations(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions jwk/x_manager_sql_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func TestXXMigrations(t *testing.T) {
require.True(t, len(client.Migrations[dbal.DriverMySQL].Box.List()) == len(client.Migrations[dbal.DriverPostgreSQL].Box.List()))

var clean = func(t *testing.T, db *sqlx.DB) {
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_jwk")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_jwk_migration")
_, err := db.Exec("DROP TABLE IF EXISTS hydra_jwk")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_jwk_migration")
t.Logf("Unable to execute clean up query: %s", err)
}

migratest.RunPackrMigrationTests(
Expand Down
45 changes: 30 additions & 15 deletions oauth2/x_fosite_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,44 @@ var createMigrations = map[string]*dbal.PackrMigrationSource{
func cleanDB(t *testing.T, db *sqlx.DB) {
t.Logf("Cleaning up tables...")

_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_access")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_refresh")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_code")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_oidc")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_pkce")
_, err := db.Exec("DROP TABLE IF EXISTS hydra_oauth2_access")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_refresh")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_code")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_oidc")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_pkce")
t.Logf("Unable to execute clean up query: %s", err)

// hydra_oauth2_consent_request_handled depends on hydra_oauth2_consent_request
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request_handled")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request_handled")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_consent_request")
t.Logf("Unable to execute clean up query: %s", err)

// hydra_oauth2_authentication_request_handled depends on hydra_oauth2_authentication_request
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request_handled")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request_handled")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_request")
t.Logf("Unable to execute clean up query: %s", err)

// everything depends on hydra_oauth2_authentication_session
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_session")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_session")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_obfuscated_authentication_session")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_client")
t.Logf("Unable to execute clean up query: %s", err)

// clean up migration tables
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_consent_migration")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
_, _ = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_migration")
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_authentication_consent_migration")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_client_migration")
t.Logf("Unable to execute clean up query: %s", err)
_, err = db.Exec("DROP TABLE IF EXISTS hydra_oauth2_migration")
t.Logf("Unable to execute clean up query: %s", err)

t.Logf("Done cleaning up tables!")
}
Expand Down

0 comments on commit bff47d2

Please sign in to comment.