Skip to content

Commit 11737a0

Browse files
committed
spanner: skip some tests in short mode
Skip integration tests and long-running unit tests if -short is supplied. Change-Id: I785a72f73bf2c60563d4f6e3e56c8aa6db8a767b Reviewed-on: https://code-review.googlesource.com/11251 Reviewed-by: kokoro <[email protected]> Reviewed-by: Vikas Kedia <[email protected]>
1 parent 7bcba8a commit 11737a0

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

spanner/retry_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import (
3434

3535
// Test if runRetryable loop deals with various errors correctly.
3636
func TestRetry(t *testing.T) {
37+
if testing.Short() {
38+
t.SkipNow()
39+
}
3740
responses := []error{
3841
grpc.Errorf(codes.Internal, "transport is closing"),
3942
grpc.Errorf(codes.Unknown, "unexpected EOF"),

spanner/session_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func TestTakeWriteSessionFromIdleList(t *testing.T) {
172172

173173
// TestTakeFromIdleListChecked tests taking sessions from session pool's idle list, but with a extra ping check.
174174
func TestTakeFromIdleListChecked(t *testing.T) {
175+
if testing.Short() {
176+
t.SkipNow()
177+
}
175178
sp, sc, cancel := setup(t, SessionPoolConfig{})
176179
defer cancel()
177180
// Stop healthcheck workers to simulate slow pings.
@@ -222,6 +225,9 @@ func TestTakeFromIdleListChecked(t *testing.T) {
222225

223226
// TestTakeFromIdleWriteListChecked tests taking sessions from session pool's idle list, but with a extra ping check.
224227
func TestTakeFromIdleWriteListChecked(t *testing.T) {
228+
if testing.Short() {
229+
t.SkipNow()
230+
}
225231
sp, sc, cancel := setup(t, SessionPoolConfig{})
226232
defer cancel()
227233
sc.MakeNice()
@@ -273,6 +279,9 @@ func TestTakeFromIdleWriteListChecked(t *testing.T) {
273279

274280
// TestMaxOpenedSessions tests max open sessions constraint.
275281
func TestMaxOpenedSessions(t *testing.T) {
282+
if testing.Short() {
283+
t.SkipNow()
284+
}
276285
sp, _, cancel := setup(t, SessionPoolConfig{MaxOpened: 1})
277286
defer cancel()
278287
sh1, err := sp.take(context.Background())
@@ -334,6 +343,9 @@ func TestMinOpenedSessions(t *testing.T) {
334343

335344
// TestMaxBurst tests max burst constraint.
336345
func TestMaxBurst(t *testing.T) {
346+
if testing.Short() {
347+
t.SkipNow()
348+
}
337349
sp, sc, cancel := setup(t, SessionPoolConfig{MaxBurst: 1})
338350
defer cancel()
339351
// Will cause session creation RPC to be retried forever.
@@ -373,6 +385,9 @@ func TestMaxBurst(t *testing.T) {
373385

374386
// TestSessionrecycle tests recycling sessions.
375387
func TestSessionRecycle(t *testing.T) {
388+
if testing.Short() {
389+
t.SkipNow()
390+
}
376391
sp, _, cancel := setup(t, SessionPoolConfig{MaxSessionAge: 100 * time.Millisecond, MinOpened: 1})
377392
// Healthcheck is explicitly turned off in this test because it might aggressively expire sessions in idle list.
378393
sp.hc.close()
@@ -456,6 +471,9 @@ func TestHcHeap(t *testing.T) {
456471

457472
// TestHealthCheckScheduler tests if healthcheck workers can schedule and perform healthchecks properly.
458473
func TestHealthCheckScheduler(t *testing.T) {
474+
if testing.Short() {
475+
t.SkipNow()
476+
}
459477
sp, sc, cancel := setup(t, SessionPoolConfig{})
460478
defer cancel()
461479
// Create 50 sessions.
@@ -485,6 +503,9 @@ func TestHealthCheckScheduler(t *testing.T) {
485503

486504
// Tests that a fractions of sessions are prepared for write by health checker.
487505
func TestWriteSessionsPrepared(t *testing.T) {
506+
if testing.Short() {
507+
t.SkipNow()
508+
}
488509
sp, sc, cancel := setup(t, SessionPoolConfig{WriteSessions: 0.5})
489510
sc.MakeNice()
490511
defer cancel()
@@ -536,6 +557,9 @@ func TestWriteSessionsPrepared(t *testing.T) {
536557

537558
// TestTakeFromWriteQueue tests that sessionPool.take() returns write prepared sessions as well.
538559
func TestTakeFromWriteQueue(t *testing.T) {
560+
if testing.Short() {
561+
t.SkipNow()
562+
}
539563
sp, sc, cancel := setup(t, SessionPoolConfig{MaxOpened: 1, WriteSessions: 1.0})
540564
sc.MakeNice()
541565
defer cancel()
@@ -561,6 +585,9 @@ func TestTakeFromWriteQueue(t *testing.T) {
561585

562586
// TestSessionHealthCheck tests healthchecking cases.
563587
func TestSessionHealthCheck(t *testing.T) {
588+
if testing.Short() {
589+
t.SkipNow()
590+
}
564591
sp, sc, cancel := setup(t, SessionPoolConfig{MaxSessionAge: 2 * time.Second})
565592
defer cancel()
566593
// Test pinging sessions.
@@ -641,6 +668,9 @@ func TestSessionHealthCheck(t *testing.T) {
641668
// when all test workers and healthcheck workers exit, mockclient, session pool and healthchecker should be in consistent state.
642669
func TestStressSessionPool(t *testing.T) {
643670
// Use concurrent workers to test different session pool built from different configurations.
671+
if testing.Short() {
672+
t.SkipNow()
673+
}
644674
for ti, cfg := range []SessionPoolConfig{
645675
SessionPoolConfig{},
646676
SessionPoolConfig{MaxSessionAge: 20 * time.Millisecond},

spanner/spanner_test.go

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,19 @@ var (
5252
dbName string
5353
)
5454

55-
// skipTest returns true if testProjectID is empty.
56-
func skipTest(t *testing.T) bool {
57-
if testProjectID == "" {
58-
t.Logf("skipping because not all environment variables are provided: GCLOUD_TESTS_GOLANG_PROJECT_ID=%q", testProjectID)
59-
return true
60-
}
61-
return false
62-
}
63-
6455
// prepare initializes Cloud Spanner testing DB and clients.
6556
func prepare(ctx context.Context, t *testing.T) error {
66-
var err error
57+
if testing.Short() {
58+
t.Skip("Integration tests skipped in short mode")
59+
}
60+
if testProjectID == "" {
61+
t.Skip("Integration tests skipped: GCLOUD_TESTS_GOLANG_PROJECT_ID is missing")
62+
}
6763
ts := testutil.TokenSource(ctx, AdminScope, Scope)
6864
if ts == nil {
69-
t.Logf("cannot get service account credential from environment variable %v, skiping test", "GCLOUD_TESTS_GOLANG_KEY")
70-
t.SkipNow()
65+
t.Skip("Integration test skipped: cannot get service account credential from environment variable %v", "GCLOUD_TESTS_GOLANG_KEY")
7166
}
67+
var err error
7268
// Create Admin client and Data client.
7369
// TODO: Remove the EndPoint option once this is the default.
7470
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) {
158154
func TestSingleUse(t *testing.T) {
159155
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
160156
defer cancel()
161-
if skipTest(t) {
162-
// Skip inegration test if not all flags are provided.
163-
t.SkipNow()
164-
}
165157
// Set up testing environment.
166158
if err := prepare(ctx, t); err != nil {
167159
// If prepare() fails, tear down whatever that's already up.
@@ -365,10 +357,6 @@ func TestSingleUse(t *testing.T) {
365357
func TestReadOnlyTransaction(t *testing.T) {
366358
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
367359
defer cancel()
368-
if skipTest(t) {
369-
// Skip inegration test if not all flags are provided.
370-
t.SkipNow()
371-
}
372360
// Set up testing environment.
373361
if err := prepare(ctx, t); err != nil {
374362
// If prepare() fails, tear down whatever that's already up.
@@ -559,9 +547,6 @@ func TestReadWriteTransaction(t *testing.T) {
559547
// Give a longer deadline because of transaction backoffs.
560548
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
561549
defer cancel()
562-
if skipTest(t) {
563-
t.SkipNow()
564-
}
565550
if err := prepare(ctx, t); err != nil {
566551
tearDown(ctx, t)
567552
t.Fatalf("cannot set up testing environment: %v", err)
@@ -658,9 +643,6 @@ func TestReadWriteTransaction(t *testing.T) {
658643
func TestDbRemovalRecovery(t *testing.T) {
659644
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
660645
defer cancel()
661-
if skipTest(t) {
662-
t.SkipNow()
663-
}
664646
if err := prepare(ctx, t); err != nil {
665647
tearDown(ctx, t)
666648
t.Fatalf("cannot set up testing environment: %v", err)
@@ -713,9 +695,6 @@ func TestDbRemovalRecovery(t *testing.T) {
713695
func TestBasicTypes(t *testing.T) {
714696
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
715697
defer cancel()
716-
if skipTest(t) {
717-
t.SkipNow()
718-
}
719698
if err := prepare(ctx, t); err != nil {
720699
tearDown(ctx, t)
721700
t.Fatalf("cannot set up testing environment: %v", err)
@@ -866,9 +845,6 @@ func TestBasicTypes(t *testing.T) {
866845
func TestStructTypes(t *testing.T) {
867846
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
868847
defer cancel()
869-
if skipTest(t) {
870-
t.SkipNow()
871-
}
872848
if err := prepare(ctx, t); err != nil {
873849
tearDown(ctx, t)
874850
t.Fatalf("cannot set up testing environment: %v", err)

0 commit comments

Comments
 (0)