Skip to content

Commit

Permalink
fix flaky test (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazegusuri authored Mar 5, 2023
1 parent 87d2af0 commit 0171ab7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
services:
emulator:
image: gcr.io/cloud-spanner-emulator/emulator:1.4.9
image: gcr.io/cloud-spanner-emulator/emulator:1.5.0
ports:
- 9010:9010
- 9020:9020
Expand Down
18 changes: 17 additions & 1 deletion pkg/spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
)

func TestLoadDDL(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand All @@ -84,6 +85,7 @@ func TestLoadDDL(t *testing.T) {
}

func TestApplyDDLFile(t *testing.T) {
t.Parallel()
ctx := context.Background()

ddl, err := ioutil.ReadFile("testdata/ddl.sql")
Expand Down Expand Up @@ -127,6 +129,7 @@ func TestApplyDDLFile(t *testing.T) {
}

func TestApplyDMLFile(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand Down Expand Up @@ -200,6 +203,7 @@ func TestApplyDMLFile(t *testing.T) {
}

func TestExecuteMigrations(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand Down Expand Up @@ -297,6 +301,7 @@ func ensureMigrationVersionRecord(t *testing.T, ctx context.Context, client *Cli
}

func TestGetSchemaMigrationVersion(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand Down Expand Up @@ -330,6 +335,7 @@ func TestGetSchemaMigrationVersion(t *testing.T) {
}

func TestSetSchemaMigrationVersion(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand Down Expand Up @@ -359,6 +365,7 @@ func TestSetSchemaMigrationVersion(t *testing.T) {
}

func TestEnsureMigrationTable(t *testing.T) {
t.Parallel()
ctx := context.Background()

client, done := testClientWithDatabase(t, ctx)
Expand Down Expand Up @@ -403,6 +410,7 @@ func TestEnsureMigrationTable(t *testing.T) {
}

func TestPriorityPBOf(t *testing.T) {
t.Parallel()
tests := map[string]struct {
priority PriorityType
want sppb.RequestOptions_Priority
Expand Down Expand Up @@ -453,7 +461,7 @@ func testClientWithDatabase(t *testing.T, ctx context.Context) (*Client, func())

id := uuid.New()
database := fmt.Sprintf("test-%s", id.String()[:18])
fmt.Printf("database %v\n", database)
t.Logf("database %v\n", database)

config := &Config{
Project: project,
Expand All @@ -475,6 +483,14 @@ func testClientWithDatabase(t *testing.T, ctx context.Context) (*Client, func())
t.Fatalf("failed to create database: %v", err)
}

// Spanner emulator is unstable when using a connection before creating a database.
// So recreate a wrench client for reconnecting the emulator.
client.Close()
client, err = NewClient(ctx, config)
if err != nil {
t.Fatalf("failed to create spanner client: %v", err)
}

return client, func() {
defer client.Close()

Expand Down

0 comments on commit 0171ab7

Please sign in to comment.