@@ -3972,6 +3972,95 @@ func TestConnect_context_cancel(t *testing.T) {
3972
3972
}
3973
3973
}
3974
3974
3975
+ func TestConnectIsBlocked (t * testing.T ) {
3976
+ const server = "127.0.0.1:3015"
3977
+
3978
+ testDialer := dialer
3979
+ testDialer .Address = server
3980
+
3981
+ ctx , cancel := context .WithTimeout (context .TODO (), 10 * time .Second )
3982
+ defer cancel ()
3983
+ delay := 2 * time .Second
3984
+ errors := make (chan error )
3985
+ go func () {
3986
+ now := time .Now ()
3987
+ reconnectOpts := opts
3988
+ reconnectOpts .Reconnect = 100 * time .Millisecond
3989
+ reconnectOpts .MaxReconnects = 100
3990
+ conn , err := Connect (ctx , testDialer , reconnectOpts )
3991
+ if err != nil {
3992
+ errors <- fmt .Errorf ("Connection was not established: %v" , err )
3993
+ return
3994
+ }
3995
+ defer conn .Close ()
3996
+ if time .Now ().Before (now .Add (delay )) {
3997
+ errors <- fmt .Errorf ("Connection was established too early" )
3998
+ return
3999
+ }
4000
+ close (errors )
4001
+ }()
4002
+
4003
+ time .Sleep (delay )
4004
+ inst , err := test_helpers .StartTarantool (test_helpers.StartOpts {
4005
+ Dialer : testDialer ,
4006
+ InitScript : "config.lua" ,
4007
+ Listen : server ,
4008
+ WaitStart : 100 * time .Millisecond ,
4009
+ ConnectRetry : 10 ,
4010
+ RetryTimeout : 500 * time .Millisecond ,
4011
+ })
4012
+ defer test_helpers .StopTarantoolWithCleanup (inst )
4013
+ if err != nil {
4014
+ t .Fatalf ("Unable to start Tarantool: %s" , err )
4015
+ }
4016
+ if err := <- errors ; err != nil {
4017
+ t .Fatal (err )
4018
+ }
4019
+ }
4020
+
4021
+ func TestConnectIsBlockedUntilContextExpires (t * testing.T ) {
4022
+ const server = "127.0.0.1:3015"
4023
+
4024
+ testDialer := dialer
4025
+ testDialer .Address = server
4026
+
4027
+ now := time .Now ()
4028
+ delay := 2 * time .Second
4029
+ ctx , cancel := context .WithTimeout (context .TODO (), delay )
4030
+ defer cancel ()
4031
+ reconnectOpts := opts
4032
+ reconnectOpts .Reconnect = 100 * time .Millisecond
4033
+ reconnectOpts .MaxReconnects = 100
4034
+ _ , err := Connect (ctx , testDialer , reconnectOpts )
4035
+ if err == nil {
4036
+ t .Fatal ("Connection was unexpectedly established." )
4037
+ }
4038
+ if time .Now ().Before (now .Add (delay )) {
4039
+ t .Fatal ("Connect() was unblocked too early" )
4040
+ }
4041
+ }
4042
+
4043
+ func TestConnectIsUnblockedAfterMaxAttempts (t * testing.T ) {
4044
+ const server = "127.0.0.1:3015"
4045
+
4046
+ testDialer := dialer
4047
+ testDialer .Address = server
4048
+
4049
+ now := time .Now ()
4050
+ ctx , cancel := context .WithTimeout (context .TODO (), 5 * time .Second )
4051
+ defer cancel ()
4052
+ reconnectOpts := opts
4053
+ reconnectOpts .Reconnect = 100 * time .Millisecond
4054
+ reconnectOpts .MaxReconnects = 10
4055
+ _ , err := Connect (ctx , testDialer , reconnectOpts )
4056
+ if err == nil {
4057
+ t .Fatal ("Connection was unexpectedly established." )
4058
+ }
4059
+ if time .Now ().Before (now .Add (time .Second )) {
4060
+ t .Fatal ("Connect() was unblocked too early" )
4061
+ }
4062
+ }
4063
+
3975
4064
func buildSidecar (dir string ) error {
3976
4065
goPath , err := exec .LookPath ("go" )
3977
4066
if err != nil {
0 commit comments