Skip to content

Commit

Permalink
spanner: skip some tests in short mode
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jba committed Mar 9, 2017
1 parent 7bcba8a commit 11737a0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
3 changes: 3 additions & 0 deletions spanner/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
30 changes: 30 additions & 0 deletions spanner/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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},
Expand Down
40 changes: 8 additions & 32 deletions spanner/spanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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.
Expand Down Expand 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.
Expand Down Expand 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 11737a0

Please sign in to comment.