@@ -403,18 +403,14 @@ func TestConnectionHandlerOpenError(t *testing.T) {
403
403
}
404
404
405
405
type testUpdateErrorHandler struct {
406
- discovered , deactivated int
407
- mutex sync.Mutex
406
+ discovered , deactivated uint32
408
407
}
409
408
410
409
func (h * testUpdateErrorHandler ) Discovered (conn * tarantool.Connection ,
411
410
role connection_pool.Role ) error {
412
- h .mutex .Lock ()
413
- defer h .mutex .Unlock ()
414
-
415
- h .discovered ++
411
+ atomic .AddUint32 (& h .discovered , 1 )
416
412
417
- if h .deactivated != 0 {
413
+ if atomic . LoadUint32 ( & h .deactivated ) != 0 {
418
414
// Don't add a connection into a pool again after it was deleted.
419
415
return fmt .Errorf ("any error" )
420
416
}
@@ -423,10 +419,7 @@ func (h *testUpdateErrorHandler) Discovered(conn *tarantool.Connection,
423
419
424
420
func (h * testUpdateErrorHandler ) Deactivated (conn * tarantool.Connection ,
425
421
role connection_pool.Role ) error {
426
- h .mutex .Lock ()
427
- defer h .mutex .Unlock ()
428
-
429
- h .deactivated ++
422
+ atomic .AddUint32 (& h .deactivated , 1 )
430
423
return nil
431
424
}
432
425
@@ -477,7 +470,9 @@ func TestConnectionHandlerUpdateError(t *testing.T) {
477
470
478
471
require .Nilf (t , err , "failed to get ConnectedNow()" )
479
472
require .Falsef (t , connected , "should be deactivated" )
480
- require .GreaterOrEqualf (t , h .discovered , h .deactivated , "discovered < deactivated" )
473
+ discovered := atomic .LoadUint32 (& h .discovered )
474
+ deactivated := atomic .LoadUint32 (& h .deactivated )
475
+ require .GreaterOrEqualf (t , discovered , deactivated , "discovered < deactivated" )
481
476
require .Nilf (t , err , "failed to get ConnectedNow()" )
482
477
}
483
478
0 commit comments