diff --git a/spanner/retry_test.go b/spanner/retry_test.go index 225062e05ea2..e07bcf5f839d 100644 --- a/spanner/retry_test.go +++ b/spanner/retry_test.go @@ -34,6 +34,9 @@ import ( // Test if runRetryable loop deals with various errors correctly. func TestRetry(t *testing.T) { + if testing.Short() { + t.SkipNow() + } responses := []error{ grpc.Errorf(codes.Internal, "transport is closing"), grpc.Errorf(codes.Unknown, "unexpected EOF"), diff --git a/spanner/session_test.go b/spanner/session_test.go index 7ad9bb56390c..7c3d4f88e10e 100644 --- a/spanner/session_test.go +++ b/spanner/session_test.go @@ -172,6 +172,9 @@ func TestTakeWriteSessionFromIdleList(t *testing.T) { // TestTakeFromIdleListChecked tests taking sessions from session pool's idle list, but with a extra ping check. func TestTakeFromIdleListChecked(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{}) defer cancel() // Stop healthcheck workers to simulate slow pings. @@ -222,6 +225,9 @@ func TestTakeFromIdleListChecked(t *testing.T) { // TestTakeFromIdleWriteListChecked tests taking sessions from session pool's idle list, but with a extra ping check. func TestTakeFromIdleWriteListChecked(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{}) defer cancel() sc.MakeNice() @@ -273,6 +279,9 @@ func TestTakeFromIdleWriteListChecked(t *testing.T) { // TestMaxOpenedSessions tests max open sessions constraint. func TestMaxOpenedSessions(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, _, cancel := setup(t, SessionPoolConfig{MaxOpened: 1}) defer cancel() sh1, err := sp.take(context.Background()) @@ -334,6 +343,9 @@ func TestMinOpenedSessions(t *testing.T) { // TestMaxBurst tests max burst constraint. func TestMaxBurst(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{MaxBurst: 1}) defer cancel() // Will cause session creation RPC to be retried forever. @@ -373,6 +385,9 @@ func TestMaxBurst(t *testing.T) { // TestSessionrecycle tests recycling sessions. func TestSessionRecycle(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, _, cancel := setup(t, SessionPoolConfig{MaxSessionAge: 100 * time.Millisecond, MinOpened: 1}) // Healthcheck is explicitly turned off in this test because it might aggressively expire sessions in idle list. sp.hc.close() @@ -456,6 +471,9 @@ func TestHcHeap(t *testing.T) { // TestHealthCheckScheduler tests if healthcheck workers can schedule and perform healthchecks properly. func TestHealthCheckScheduler(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{}) defer cancel() // Create 50 sessions. @@ -485,6 +503,9 @@ func TestHealthCheckScheduler(t *testing.T) { // Tests that a fractions of sessions are prepared for write by health checker. func TestWriteSessionsPrepared(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{WriteSessions: 0.5}) sc.MakeNice() defer cancel() @@ -536,6 +557,9 @@ func TestWriteSessionsPrepared(t *testing.T) { // TestTakeFromWriteQueue tests that sessionPool.take() returns write prepared sessions as well. func TestTakeFromWriteQueue(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{MaxOpened: 1, WriteSessions: 1.0}) sc.MakeNice() defer cancel() @@ -561,6 +585,9 @@ func TestTakeFromWriteQueue(t *testing.T) { // TestSessionHealthCheck tests healthchecking cases. func TestSessionHealthCheck(t *testing.T) { + if testing.Short() { + t.SkipNow() + } sp, sc, cancel := setup(t, SessionPoolConfig{MaxSessionAge: 2 * time.Second}) defer cancel() // Test pinging sessions. @@ -641,6 +668,9 @@ func TestSessionHealthCheck(t *testing.T) { // when all test workers and healthcheck workers exit, mockclient, session pool and healthchecker should be in consistent state. func TestStressSessionPool(t *testing.T) { // Use concurrent workers to test different session pool built from different configurations. + if testing.Short() { + t.SkipNow() + } for ti, cfg := range []SessionPoolConfig{ SessionPoolConfig{}, SessionPoolConfig{MaxSessionAge: 20 * time.Millisecond}, diff --git a/spanner/spanner_test.go b/spanner/spanner_test.go index e09a256f7547..96d42ddc33e6 100644 --- a/spanner/spanner_test.go +++ b/spanner/spanner_test.go @@ -52,23 +52,19 @@ var ( dbName string ) -// skipTest returns true if testProjectID is empty. -func skipTest(t *testing.T) bool { - if testProjectID == "" { - t.Logf("skipping because not all environment variables are provided: GCLOUD_TESTS_GOLANG_PROJECT_ID=%q", testProjectID) - return true - } - return false -} - // prepare initializes Cloud Spanner testing DB and clients. func prepare(ctx context.Context, t *testing.T) error { - var err error + if testing.Short() { + t.Skip("Integration tests skipped in short mode") + } + if testProjectID == "" { + t.Skip("Integration tests skipped: GCLOUD_TESTS_GOLANG_PROJECT_ID is missing") + } ts := testutil.TokenSource(ctx, AdminScope, Scope) if ts == nil { - t.Logf("cannot get service account credential from environment variable %v, skiping test", "GCLOUD_TESTS_GOLANG_KEY") - t.SkipNow() + t.Skip("Integration test skipped: cannot get service account credential from environment variable %v", "GCLOUD_TESTS_GOLANG_KEY") } + var err error // Create Admin client and Data client. // TODO: Remove the EndPoint option once this is the default. admin, err = database.NewDatabaseAdminClient(ctx, option.WithTokenSource(ts), option.WithEndpoint("spanner.googleapis.com:443")) @@ -158,10 +154,6 @@ func tearDown(ctx context.Context, t *testing.T) { func TestSingleUse(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - if skipTest(t) { - // Skip inegration test if not all flags are provided. - t.SkipNow() - } // Set up testing environment. if err := prepare(ctx, t); err != nil { // If prepare() fails, tear down whatever that's already up. @@ -365,10 +357,6 @@ func TestSingleUse(t *testing.T) { func TestReadOnlyTransaction(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - if skipTest(t) { - // Skip inegration test if not all flags are provided. - t.SkipNow() - } // Set up testing environment. if err := prepare(ctx, t); err != nil { // If prepare() fails, tear down whatever that's already up. @@ -559,9 +547,6 @@ func TestReadWriteTransaction(t *testing.T) { // Give a longer deadline because of transaction backoffs. ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() - if skipTest(t) { - t.SkipNow() - } if err := prepare(ctx, t); err != nil { tearDown(ctx, t) t.Fatalf("cannot set up testing environment: %v", err) @@ -658,9 +643,6 @@ func TestReadWriteTransaction(t *testing.T) { func TestDbRemovalRecovery(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - if skipTest(t) { - t.SkipNow() - } if err := prepare(ctx, t); err != nil { tearDown(ctx, t) t.Fatalf("cannot set up testing environment: %v", err) @@ -713,9 +695,6 @@ func TestDbRemovalRecovery(t *testing.T) { func TestBasicTypes(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - if skipTest(t) { - t.SkipNow() - } if err := prepare(ctx, t); err != nil { tearDown(ctx, t) t.Fatalf("cannot set up testing environment: %v", err) @@ -866,9 +845,6 @@ func TestBasicTypes(t *testing.T) { func TestStructTypes(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - if skipTest(t) { - t.SkipNow() - } if err := prepare(ctx, t); err != nil { tearDown(ctx, t) t.Fatalf("cannot set up testing environment: %v", err)