@@ -243,85 +243,54 @@ func TestSessionPoolCloseWhenWaiting(t *testing.T) {
243243}
244244
245245func TestSessionPoolClose (t * testing.T ) {
246- wg := sync.WaitGroup {}
247- p := newClientWithStubBuilder (
248- t ,
249- testutil .NewBalancer (testutil .WithInvokeHandlers (testutil.InvokeHandlers {
250- testutil .TableCreateSession : func (interface {}) (proto.Message , error ) {
251- return & Ydb_Table.CreateSessionResult {
252- SessionId : testutil .SessionID (),
253- }, nil
254- },
255- testutil .TableDeleteSession : func (interface {}) (proto.Message , error ) {
256- return & Ydb_Table.DeleteSessionResponse {}, nil
257- },
258- })),
259- 3 ,
260- config .WithSizeLimit (3 ),
261- config .WithIdleThreshold (time .Hour ),
262- config .WithTrace (
263- trace.Table {
264- OnPoolPut : func (info trace.TablePoolPutStartInfo ) func (trace.TablePoolPutDoneInfo ) {
265- wg .Add (1 )
266- return func (info trace.TablePoolPutDoneInfo ) {
267- wg .Done ()
268- }
246+ xtest .TestManyTimes (t , func (t testing.TB ) {
247+ p := newClientWithStubBuilder (
248+ t ,
249+ testutil .NewBalancer (testutil .WithInvokeHandlers (testutil.InvokeHandlers {
250+ testutil .TableCreateSession : func (interface {}) (proto.Message , error ) {
251+ return & Ydb_Table.CreateSessionResult {
252+ SessionId : testutil .SessionID (),
253+ }, nil
269254 },
270- OnPoolSessionClose : func (
271- info trace.TablePoolSessionCloseStartInfo ,
272- ) func (
273- doneInfo trace.TablePoolSessionCloseDoneInfo ,
274- ) {
275- wg .Add (1 )
276- return func (info trace.TablePoolSessionCloseDoneInfo ) {
277- wg .Done ()
278- }
255+ testutil .TableDeleteSession : func (interface {}) (proto.Message , error ) {
256+ return & Ydb_Table.DeleteSessionResponse {}, nil
279257 },
280- },
281- ),
282- )
283- defer func () {
284- _ = p .Close (context .Background ())
285- }()
286-
287- var (
288- s1 = mustGetSession (t , p )
289- s2 = mustGetSession (t , p )
290- s3 = mustGetSession (t , p )
291- closed1 = false
292- closed2 = false
293- closed3 = false
294- )
295-
296- s1 .onClose = append (s1 .onClose , func (s * session ) { closed1 = true })
297- s2 .onClose = append (s2 .onClose , func (s * session ) { closed2 = true })
298- s3 .onClose = append (s3 .onClose , func (s * session ) { closed3 = true })
258+ })),
259+ 3 ,
260+ config .WithSizeLimit (3 ),
261+ config .WithIdleThreshold (time .Hour ),
262+ )
263+ defer func () {
264+ _ = p .Close (context .Background ())
265+ }()
299266
300- mustPutSession (t , p , s1 )
301- mustPutSession (t , p , s2 )
302- mustClose (t , p )
267+ var (
268+ s1 = mustGetSession (t , p )
269+ s2 = mustGetSession (t , p )
270+ s3 = mustGetSession (t , p )
271+ closed1 = false
272+ closed2 = false
273+ closed3 = false
274+ )
303275
304- if ! closed1 {
305- t .Fatalf ("session1 was not closed" )
306- }
307- if ! closed2 {
308- t .Fatalf ("session2 was not closed" )
309- }
310- if closed3 {
311- t .Fatalf ("unexpected session close" )
312- }
276+ s1 .onClose = append (s1 .onClose , func (s * session ) { closed1 = true })
277+ s2 .onClose = append (s2 .onClose , func (s * session ) { closed2 = true })
278+ s3 .onClose = append (s3 .onClose , func (s * session ) { closed3 = true })
313279
314- if err := p .Put (context .Background (), s3 ); ! xerrors .Is (err , errClosedClient ) {
315- t .Errorf (
316- "unexpected Put() error: %v; want %v" ,
317- err , errClosedClient ,
318- )
319- }
320- wg .Wait ()
280+ mustPutSession (t , p , s1 )
281+ mustPutSession (t , p , s2 )
282+ mustClose (t , p )
321283
322- if ! closed3 {
323- t .Fatalf ("session was not closed" )
324- }
284+ if ! closed1 {
285+ t .Errorf ("session1 was not closed" )
286+ }
287+ if ! closed2 {
288+ t .Errorf ("session2 was not closed" )
289+ }
290+ if ! closed3 {
291+ t .Errorf ("session3 was not closed" )
292+ }
293+ }, xtest .StopAfter (42 * time .Second ))
325294}
326295
327296func TestRaceWgClosed (t * testing.T ) {
@@ -380,7 +349,7 @@ func TestRaceWgClosed(t *testing.T) {
380349 }
381350 _ = p .Close (context .Background ())
382351 wg .Wait ()
383- }, xtest .StopAfter (17 * time .Second ))
352+ }, xtest .StopAfter (37 * time .Second ))
384353}
385354
386355func TestSessionPoolDeleteReleaseWait (t * testing.T ) {
@@ -1216,7 +1185,7 @@ func mustResetTimer(t *testing.T, ch <-chan time.Duration, exp time.Duration) {
12161185 }
12171186}
12181187
1219- func mustCreateSession (t * testing.T , p * Client ) * session {
1188+ func mustCreateSession (t testing.TB , p * Client ) * session {
12201189 wg := sync.WaitGroup {}
12211190 defer wg .Wait ()
12221191 s , err := p .internalPoolCreateSession (context .Background ())
@@ -1227,7 +1196,7 @@ func mustCreateSession(t *testing.T, p *Client) *session {
12271196 return s
12281197}
12291198
1230- func mustGetSession (t * testing.T , p * Client ) * session {
1199+ func mustGetSession (t testing.TB , p * Client ) * session {
12311200 wg := sync.WaitGroup {}
12321201 defer wg .Wait ()
12331202 s , err := p .Get (context .Background ())
@@ -1238,7 +1207,7 @@ func mustGetSession(t *testing.T, p *Client) *session {
12381207 return s
12391208}
12401209
1241- func mustPutSession (t * testing.T , p * Client , s * session ) {
1210+ func mustPutSession (t testing.TB , p * Client , s * session ) {
12421211 wg := sync.WaitGroup {}
12431212 defer wg .Wait ()
12441213 if err := p .Put (
@@ -1250,7 +1219,7 @@ func mustPutSession(t *testing.T, p *Client, s *session) {
12501219 }
12511220}
12521221
1253- func mustClose (t * testing.T , p * Client ) {
1222+ func mustClose (t testing.TB , p * Client ) {
12541223 wg := sync.WaitGroup {}
12551224 defer wg .Wait ()
12561225 if err := p .Close (context .Background ()); err != nil {
0 commit comments