@@ -45,7 +45,7 @@ func TestDoBackoffRetryCancelation(t *testing.T) {
4545 go func () {
4646 err := do (ctx , p ,
4747 config .New (),
48- func (ctx context.Context , _ table. Session ) error {
48+ func (ctx context.Context , _ * Session ) error {
4949 return testErr
5050 },
5151 nil ,
@@ -86,6 +86,13 @@ func TestDoBadSession(t *testing.T) {
8686 xtest .TestManyTimes (t , func (t testing.TB ) {
8787 closed := make (map [table.Session ]bool )
8888 p := pool .New [* Session , Session ](ctx ,
89+ pool.WithMustDeleteItemFunc [* Session , Session ](func (session * Session , err error ) bool {
90+ if ! session .IsAlive () {
91+ return true
92+ }
93+
94+ return xerrors .MustDeleteTableOrQuerySession (err )
95+ }),
8996 pool.WithCreateItemFunc [* Session , Session ](func (ctx context.Context ) (* Session , error ) {
9097 s := simpleSession (t )
9198 s .closeOnce = func (_ context.Context ) error {
@@ -104,7 +111,7 @@ func TestDoBadSession(t *testing.T) {
104111 )
105112 ctx , cancel := xcontext .WithCancel (context .Background ())
106113 err := do (ctx , p , config .New (),
107- func (ctx context.Context , s table. Session ) error {
114+ func (ctx context.Context , s * Session ) error {
108115 sessions = append (sessions , s )
109116 i ++
110117 if i > maxRetryes {
@@ -143,7 +150,7 @@ func TestDoCreateSessionError(t *testing.T) {
143150 }),
144151 )
145152 err := do (ctx , p , config .New (),
146- func (ctx context.Context , s table. Session ) error {
153+ func (ctx context.Context , s * Session ) error {
147154 return nil
148155 },
149156 nil ,
@@ -186,7 +193,7 @@ func TestDoImmediateReturn(t *testing.T) {
186193 context .Background (),
187194 p ,
188195 config .New (),
189- func (ctx context.Context , _ table. Session ) error {
196+ func (ctx context.Context , _ * Session ) error {
190197 return testErr
191198 },
192199 nil ,
@@ -322,7 +329,7 @@ func TestDoContextDeadline(t *testing.T) {
322329 ctx ,
323330 p ,
324331 config .New (),
325- func (ctx context.Context , _ table. Session ) error {
332+ func (ctx context.Context , _ * Session ) error {
326333 select {
327334 case <- ctx .Done ():
328335 return ctx .Err ()
@@ -357,6 +364,13 @@ func TestDoWithCustomErrors(t *testing.T) {
357364 pool.WithCreateItemFunc [* Session , Session ](func (ctx context.Context ) (* Session , error ) {
358365 return simpleSession (t ), nil
359366 }),
367+ pool.WithMustDeleteItemFunc [* Session , Session ](func (session * Session , err error ) bool {
368+ if ! session .IsAlive () {
369+ return true
370+ }
371+
372+ return xerrors .MustDeleteTableOrQuerySession (err )
373+ }),
360374 pool.WithLimit [* Session , Session ](limit ),
361375 )
362376 )
@@ -369,11 +383,10 @@ func TestDoWithCustomErrors(t *testing.T) {
369383 error : & CustomError {
370384 Err : retry .RetryableError (
371385 fmt .Errorf ("custom error" ),
372- retry .WithDeleteSession (),
373386 ),
374387 },
375388 retriable : true ,
376- deleteSession : true ,
389+ deleteSession : false ,
377390 },
378391 {
379392 error : & CustomError {
@@ -388,8 +401,7 @@ func TestDoWithCustomErrors(t *testing.T) {
388401 },
389402 {
390403 error : & CustomError {
391- Err : fmt .Errorf (
392- "wrapped error: %w" ,
404+ Err : fmt .Errorf ("wrapped error: %w" ,
393405 xerrors .Operation (
394406 xerrors .WithStatusCode (
395407 Ydb .StatusIds_BAD_SESSION ,
@@ -402,8 +414,7 @@ func TestDoWithCustomErrors(t *testing.T) {
402414 },
403415 {
404416 error : & CustomError {
405- Err : fmt .Errorf (
406- "wrapped error: %w" ,
417+ Err : fmt .Errorf ("wrapped error: %w" ,
407418 xerrors .Operation (
408419 xerrors .WithStatusCode (
409420 Ydb .StatusIds_UNAUTHORIZED ,
@@ -420,11 +431,8 @@ func TestDoWithCustomErrors(t *testing.T) {
420431 i = 0
421432 sessions = make (map [table.Session ]int )
422433 )
423- err := do (
424- ctx ,
425- p ,
426- config .New (),
427- func (ctx context.Context , s table.Session ) (err error ) {
434+ err := do (ctx , p , config .New (),
435+ func (ctx context.Context , s * Session ) (err error ) {
428436 sessions [s ]++
429437 i ++
430438 if i < limit {
@@ -442,7 +450,7 @@ func TestDoWithCustomErrors(t *testing.T) {
442450 }
443451 if test .deleteSession {
444452 if len (sessions ) != limit {
445- t .Fatalf ("unexpected len(sessions): %d, err: %v" , len (sessions ), err )
453+ t .Fatalf ("unexpected len(sessions): %d, exp: %d, err: %v" , len (sessions ), limit , err )
446454 }
447455 for s , n := range sessions {
448456 if n != 1 {
@@ -489,9 +497,3 @@ func (s *singleSession) With(ctx context.Context,
489497 return f (ctx , s .s )
490498 }, opts ... )
491499}
492-
493- var (
494- errNoSession = xerrors .Wrap (fmt .Errorf ("no session" ))
495- errUnexpectedSession = xerrors .Wrap (fmt .Errorf ("unexpected session" ))
496- errSessionOverflow = xerrors .Wrap (fmt .Errorf ("session overflow" ))
497- )
0 commit comments