Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
* New `MockDoer` interface for custom `Doer` testing with builder pattern
methods: `AddResponse`, `AddResponseRaw`, `AddResponseError`, `Requests`.
* New `MockRequestNamed` type for verifying specific requests in tests.
* New `test_helpers.ExecuteOnAll` function to execute operations on all
instances in parallel with context support.

### Changed

Expand Down Expand Up @@ -62,11 +64,16 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
become private, `SetError` and `SetResponse` become private (#470).
* `ConnectionPool.Close()` returns a single error value, combining multiple
errors using errors.Join() (#540).
* `test_helpers.CheckPoolStatuses` and `test_helpers.ProcessListenOnInstance`
now accept typed arguments (`CheckStatusesArgs` and `ListenOnInstanceArgs`
respectively) instead of `interface{}`.

### Removed

* Deprecated `NewCall16Request` and `NewCall17Request` constructors. Use
`NewCallRequest` instead.
* `test_helpers.Retry` function. Use `assert.Eventually` from testify instead.
`test_helpers.WaitUntilReconnected` reimplemented without `Retry`.

### Fixed

Expand Down
137 changes: 88 additions & 49 deletions pool/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ var connOpts = tarantool.Opts{
Timeout: 5 * time.Second,
}

var defaultCountRetry = 5
var defaultTimeoutRetry = 500 * time.Millisecond
const defaultCountRetry = 5

const tick = 500 * time.Millisecond
const timeout = defaultCountRetry * tick

var helpInstances []*test_helpers.TarantoolInstance

Expand Down Expand Up @@ -437,9 +439,10 @@ func TestReconnect(t *testing.T) {
server: false,
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

err = test_helpers.RestartTarantool(helpInstances[0])
Expand All @@ -454,9 +457,10 @@ func TestReconnect(t *testing.T) {
server: true,
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -486,8 +490,10 @@ func TestDisconnect_withReconnect(t *testing.T) {
servers[serverId]: false,
},
}
err = test_helpers.Retry(test_helpers.CheckPoolStatuses,
args, defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

// Restart the server after success.
Expand All @@ -503,9 +509,10 @@ func TestDisconnect_withReconnect(t *testing.T) {
servers[serverId]: true,
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses,
args, defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -534,9 +541,10 @@ func TestDisconnectAll(t *testing.T) {
server2: false,
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

err = test_helpers.RestartTarantool(helpInstances[0])
Expand All @@ -555,9 +563,10 @@ func TestDisconnectAll(t *testing.T) {
server2: true,
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -592,8 +601,10 @@ func TestAdd(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -639,8 +650,10 @@ func TestAdd_exist(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -676,8 +689,10 @@ func TestAdd_unreachable(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -781,8 +796,10 @@ func TestRemove(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -810,8 +827,10 @@ func TestRemove_double(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand All @@ -838,8 +857,10 @@ func TestRemove_unknown(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -887,8 +908,10 @@ func TestRemove_concurrent(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -972,8 +995,10 @@ func TestClose(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -1035,8 +1060,10 @@ func TestCloseGraceful(t *testing.T) {
},
}

err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down Expand Up @@ -1397,8 +1424,10 @@ func TestRequestOnClosed(t *testing.T) {
server2: false,
},
}
err = test_helpers.Retry(test_helpers.CheckPoolStatuses, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.CheckPoolStatuses(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

_, err = connPool.Do(tarantool.NewPingRequest(), pool.ANY).Get()
Expand Down Expand Up @@ -1968,8 +1997,10 @@ func TestUpdateInstancesRoles(t *testing.T) {
Mode: pool.ANY,
}

err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.ProcessListenOnInstance(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

// RW
Expand All @@ -1980,8 +2011,10 @@ func TestUpdateInstancesRoles(t *testing.T) {
Mode: pool.RW,
}

err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.ProcessListenOnInstance(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

// RO
Expand All @@ -1992,8 +2025,10 @@ func TestUpdateInstancesRoles(t *testing.T) {
Mode: pool.RO,
}

err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.ProcessListenOnInstance(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

// PreferRW
Expand All @@ -2004,8 +2039,10 @@ func TestUpdateInstancesRoles(t *testing.T) {
Mode: pool.PreferRW,
}

err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.ProcessListenOnInstance(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)

// PreferRO
Expand All @@ -2016,8 +2053,10 @@ func TestUpdateInstancesRoles(t *testing.T) {
Mode: pool.PreferRO,
}

err = test_helpers.Retry(test_helpers.ProcessListenOnInstance, args,
defaultCountRetry, defaultTimeoutRetry)
assert.Eventually(t, func() bool {
err = test_helpers.ProcessListenOnInstance(args)
return err == nil
}, timeout, tick)
require.NoError(t, err)
}

Expand Down
27 changes: 9 additions & 18 deletions shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package tarantool_test

import (
"fmt"
"sync"
"syscall"
"testing"
Expand Down Expand Up @@ -84,24 +83,16 @@ func testGracefulShutdown(t *testing.T, conn *Connection, inst *test_helpers.Tar
require.NoError(t, inst.Signal(syscall.SIGTERM))

// Check that we can't send new requests after shutdown starts.
// Retry helps to wait a bit until server starts to shutdown
// assert.Eventually helps to wait a bit until server starts to shutdown
// and send us the shutdown event.
shutdownWaitRetries := 5
shutdownWaitTimeout := 100 * time.Millisecond

err = test_helpers.Retry(func(interface{}) error {
_, err = conn.Do(NewPingRequest()).Get()
if err == nil {
return fmt.Errorf("expected error for requests sent on shutdown")
}

if err.Error() != "server shutdown in progress (0x4005)" {
return err
}

return nil
}, nil, shutdownWaitRetries, shutdownWaitTimeout)
require.NoError(t, err)
const shutdownWaitRetries = 5
tick := 100 * time.Millisecond
timeout := time.Duration(shutdownWaitRetries) * tick

require.Eventually(t, func() bool {
_, err := conn.Do(NewPingRequest()).Get()
return err != nil && err.Error() == "server shutdown in progress (0x4005)"
}, timeout, tick, "expected shutdown error 'server shutdown in progress (0x4005)'")

// Check that requests started before the shutdown finish successfully.
data, err := fut.Get()
Expand Down
Loading
Loading