@@ -38,6 +38,7 @@ import (
3838 "github.com/google/go-cmp/cmp"
3939 "github.com/google/go-cmp/cmp/cmpopts"
4040 "github.com/google/uuid"
41+ "github.com/googleapis/go-sql-spanner/connectionstate"
4142 "github.com/googleapis/go-sql-spanner/parser"
4243 "github.com/googleapis/go-sql-spanner/testutil"
4344 "google.golang.org/api/option"
@@ -3698,6 +3699,47 @@ func TestMaxSessions(t *testing.T) {
36983699 }
36993700}
37003701
3702+ func TestConnectionStateType (t * testing.T ) {
3703+ t .Parallel ()
3704+
3705+ ctx := context .Background ()
3706+ db , _ , teardown := setupTestDBConnectionWithParams (t , "connection_state_type=TRANSACTIONAL" )
3707+ defer teardown ()
3708+
3709+ c , err := db .Conn (ctx )
3710+ if err != nil {
3711+ t .Fatalf ("failed to get a connection: %v" , err )
3712+ }
3713+
3714+ verifyConnectionPropertyValue (t , c , "connection_state_type" , connectionstate .TypeTransactional )
3715+ // Check that the behavior is actually transactional.
3716+ verifyConnectionPropertyValue (t , c , "data_boost_enabled" , false )
3717+ tx , err := c .BeginTx (ctx , nil )
3718+ if err != nil {
3719+ t .Fatalf ("failed to begin transaction: %v" , err )
3720+ }
3721+ if _ , err := tx .ExecContext (ctx , "set data_boost_enabled = true" ); err != nil {
3722+ t .Fatalf ("failed to set data_boost_enabled: %v" , err )
3723+ }
3724+ if err := tx .Commit (); err != nil {
3725+ t .Fatalf ("failed to commit transaction: %v" , err )
3726+ }
3727+ verifyConnectionPropertyValue (t , c , "data_boost_enabled" , true )
3728+
3729+ tx , err = c .BeginTx (ctx , nil )
3730+ if err != nil {
3731+ t .Fatalf ("failed to begin transaction: %v" , err )
3732+ }
3733+ if _ , err := tx .ExecContext (ctx , "set data_boost_enabled = false" ); err != nil {
3734+ t .Fatalf ("failed to set data_boost_enabled: %v" , err )
3735+ }
3736+ // Rolling back the transaction should also roll back the change to data_boost_enabled.
3737+ if err := tx .Rollback (); err != nil {
3738+ t .Fatalf ("failed to rollback transaction: %v" , err )
3739+ }
3740+ verifyConnectionPropertyValue (t , c , "data_boost_enabled" , true )
3741+ }
3742+
37013743func TestClientReuse (t * testing.T ) {
37023744 // This test is intentionally not parallel, as the internal caching of clients could
37033745 // be impacted by other parallel tests.
@@ -5821,13 +5863,6 @@ func date(v string) civil.Date {
58215863 return res
58225864}
58235865
5824- func nullDate (valid bool , v string ) spanner.NullDate {
5825- if ! valid {
5826- return spanner.NullDate {}
5827- }
5828- return spanner.NullDate {Valid : true , Date : date (v )}
5829- }
5830-
58315866func nullJson (valid bool , v string ) spanner.NullJSON {
58325867 if ! valid {
58335868 return spanner.NullJSON {}
@@ -5969,28 +6004,3 @@ func filterBeginReadOnlyRequests(requests []interface{}) []*sppb.BeginTransactio
59696004 }
59706005 return res
59716006}
5972-
5973- func waitFor (t * testing.T , assert func () error ) {
5974- t .Helper ()
5975- timeout := 5 * time .Second
5976- ta := time .After (timeout )
5977-
5978- for {
5979- select {
5980- case <- ta :
5981- if err := assert (); err != nil {
5982- t .Fatalf ("after %v waiting, got %v" , timeout , err )
5983- }
5984- return
5985- default :
5986- }
5987-
5988- if err := assert (); err != nil {
5989- // Fail. Let's pause and retry.
5990- time .Sleep (time .Millisecond )
5991- continue
5992- }
5993-
5994- return
5995- }
5996- }
0 commit comments