@@ -17,9 +17,12 @@ import (
1717
1818 "github.com/rekby/fixenv"
1919 "github.com/stretchr/testify/require"
20+ "google.golang.org/grpc"
2021
2122 "github.com/ydb-platform/ydb-go-sdk/v3"
23+ "github.com/ydb-platform/ydb-go-sdk/v3/config"
2224 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
25+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
2326 "github.com/ydb-platform/ydb-go-sdk/v3/log"
2427 "github.com/ydb-platform/ydb-go-sdk/v3/sugar"
2528 "github.com/ydb-platform/ydb-go-sdk/v3/table"
@@ -35,21 +38,22 @@ type scopeT struct {
3538 Ctx context.Context
3639 fixenv.Env
3740 Require * require.Assertions
38- t testing. TB
41+ t * xtest. SyncedTest
3942}
4043
4144func newScope (t * testing.T ) * scopeT {
42- at := require .New (t )
43- fEnv := fixenv .NewEnv (t )
45+ st := xtest .MakeSyncedTest (t )
46+ at := require .New (st )
47+ fEnv := fixenv .New (st )
4448 ctx , ctxCancel := context .WithCancel (context .Background ())
45- t .Cleanup (func () {
49+ st .Cleanup (func () {
4650 ctxCancel ()
4751 })
4852 res := & scopeT {
4953 Ctx : ctx ,
5054 Env : fEnv ,
5155 Require : at ,
52- t : t ,
56+ t : st ,
5357 }
5458 return res
5559}
@@ -79,9 +83,21 @@ func (scope *scopeT) AuthToken() string {
7983}
8084
8185func (scope * scopeT ) Driver (opts ... ydb.Option ) * ydb.Driver {
86+ return scope .driverNamed ("default" , opts ... )
87+ }
88+
89+ func (scope * scopeT ) DriverWithGRPCLogging () * ydb.Driver {
90+ return scope .driverNamed ("grpc-logged" , ydb .With (config .WithGrpcOptions (
91+ grpc .WithChainUnaryInterceptor (xtest .NewGrpcLogger (scope .t ).UnaryClientInterceptor ),
92+ grpc .WithChainStreamInterceptor (xtest .NewGrpcLogger (scope .t ).StreamClientInterceptor ),
93+ )),
94+ )
95+ }
96+
97+ func (scope * scopeT ) driverNamed (name string , opts ... ydb.Option ) * ydb.Driver {
8298 f := func () (* fixenv.GenericResult [* ydb.Driver ], error ) {
8399 connectionString := scope .ConnectionString ()
84- scope .Logf ("Connect with connection string: %v" , connectionString )
100+ scope .Logf ("Connect with connection string, driver name %q : %v" , name , connectionString )
85101
86102 token := scope .AuthToken ()
87103 if token == "" {
@@ -111,7 +127,7 @@ func (scope *scopeT) Driver(opts ...ydb.Option) *ydb.Driver {
111127 return fixenv .NewGenericResultWithCleanup (driver , clean ), err
112128 }
113129
114- return fixenv .CacheResult (scope .Env , f )
130+ return fixenv .CacheResult (scope .Env , f , fixenv. CacheOptions { CacheKey : name } )
115131}
116132
117133func (scope * scopeT ) SQLDriver (opts ... ydb.ConnectorOption ) * sql.DB {
@@ -319,7 +335,7 @@ func (scope *scopeT) TablePath(opts ...func(t *tableNameParams)) string {
319335
320336// logger for tests
321337type testLogger struct {
322- test testing. TB
338+ test * xtest. SyncedTest
323339 testName string
324340 minLevel log.Level
325341
@@ -328,11 +344,11 @@ type testLogger struct {
328344 messages []string
329345}
330346
331- func newLogger (t testing. TB ) * testLogger {
347+ func newLogger (t * xtest. SyncedTest ) * testLogger {
332348 return newLoggerWithMinLevel (t , 0 )
333349}
334350
335- func newLoggerWithMinLevel (t testing. TB , level log.Level ) * testLogger {
351+ func newLoggerWithMinLevel (t * xtest. SyncedTest , level log.Level ) * testLogger {
336352 logger := & testLogger {
337353 test : t ,
338354 testName : t .Name (),
0 commit comments