Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many flaky tests on macOs #281

Closed
wants to merge 10 commits into from
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

### Changed

- queue module version bumped to 1.3.0 (#278)

### Fixed

- Several non-critical data race issues (#218)
- ConnectionPool does not properly handle disconnection with Opts.Reconnect
set (#272)
- Connect() panics on concurrent schema update (#278)
- Wrong Ttr setup by Queue.Cfg() (#278)
- Flaky queue/Example_connectionPool (#278)
- Flaky queue/Example_simpleQueueCustomMsgPack (#277)

## [1.10.0] - 2022-12-31

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ clean:

.PHONY: deps
deps: clean
( cd ./queue/testdata; $(TTCTL) rocks install queue 1.2.1 )
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.0.0 )
( cd ./queue/testdata; $(TTCTL) rocks install queue 1.3.0 )
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.1.1 )

.PHONY: datetime-timezones
datetime-timezones:
Expand Down
17 changes: 17 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ local function push_func(cnt)
end
rawset(_G, 'push_func', push_func)

local function create_spaces()
for i=1,10 do
local s = box.schema.space.create('test' .. tostring(i), {
id = 700 + i,
if_not_exists = true,
})
local idx = s:create_index('test' .. tostring(i) .. 'primary', {
type = 'tree',
parts = {1, 'uint'},
if_not_exists = true
})
idx:drop()
s:drop()
end
end
rawset(_G, 'create_spaces', create_spaces)

local function tarantool_version_at_least(wanted_major, wanted_minor, wanted_patch)
-- https://github.com/tarantool/crud/blob/733528be02c1ffa3dacc12c034ee58c9903127fc/test/helper.lua#L316-L337
local major_minor_patch = _TARANTOOL:split('-', 1)[1]
Expand Down
2 changes: 1 addition & 1 deletion connection_pool/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var servers = []string{
}

var connOpts = tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
Expand Down
2 changes: 1 addition & 1 deletion crud/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
)

var exampleOpts = tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
Expand Down
47 changes: 37 additions & 10 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var invalidSpaceName = "invalid"
var indexNo = uint32(0)
var indexName = "primary_index"
var opts = tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
Expand Down Expand Up @@ -104,6 +104,33 @@ var object = crud.MapObject{
"name": "bla",
}

func connect(t testing.TB) *tarantool.Connection {
for i := 0; i < 10; i++ {
conn, err := tarantool.Connect(server, opts)
if err != nil {
t.Fatalf("Failed to connect: %s", err)
}

ret := struct {
_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
Result bool
}{}
err = conn.Do(tarantool.NewCall17Request("is_ready")).GetTyped(&ret)
if err != nil {
t.Fatalf("Failed to check is_ready: %s", err)
}

if ret.Result {
return conn
}

time.Sleep(time.Second)
}

t.Fatalf("Failed to wait for a ready state connect.")
return nil
}

var testProcessDataCases = []struct {
name string
expectedRespLen int
Expand Down Expand Up @@ -454,7 +481,7 @@ func testCrudRequestCheck(t *testing.T, req tarantool.Request,
}

func TestCrudGenerateData(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

for _, testCase := range testGenerateDataCases {
Expand All @@ -477,7 +504,7 @@ func TestCrudGenerateData(t *testing.T) {
}

func TestCrudProcessData(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

for _, testCase := range testProcessDataCases {
Expand Down Expand Up @@ -527,7 +554,7 @@ func TestUnflattenRows(t *testing.T) {
tpls []interface{}
)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

// Do `replace`.
Expand Down Expand Up @@ -586,7 +613,7 @@ func TestUnflattenRows(t *testing.T) {
}

func TestResultWithErr(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

for _, testCase := range testResultWithErrCases {
Expand All @@ -601,7 +628,7 @@ func TestResultWithErr(t *testing.T) {
}

func TestBoolResult(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

req := crud.MakeTruncateRequest(spaceName).Opts(baseOpts)
Expand All @@ -624,7 +651,7 @@ func TestBoolResult(t *testing.T) {
}

func TestNumberResult(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

req := crud.MakeCountRequest(spaceName).Opts(countOpts)
Expand Down Expand Up @@ -665,7 +692,7 @@ func TestBaseResult(t *testing.T) {
},
}

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

req := crud.MakeSelectRequest(spaceName).Opts(selectOpts)
Expand Down Expand Up @@ -708,7 +735,7 @@ func TestManyResult(t *testing.T) {
},
}

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

req := crud.MakeReplaceManyRequest(spaceName).Tuples(tuples).Opts(opManyOpts)
Expand All @@ -733,7 +760,7 @@ func TestManyResult(t *testing.T) {
}

func TestStorageInfoResult(t *testing.T) {
conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := connect(t)
defer conn.Close()

req := crud.MakeStorageInfoRequest().Opts(baseOpts)
Expand Down
16 changes: 12 additions & 4 deletions crud/testdata/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ s:create_index('bucket_id', {
unique = false,
})

local function is_ready_false()
return false
end

local function is_ready_true()
return true
end

rawset(_G, 'is_ready', is_ready_false)

-- Setup vshard.
_G.vshard = vshard
box.once('guest', function()
Expand Down Expand Up @@ -93,7 +103,5 @@ box.schema.user.grant('test', 'execute', 'universe', nil, { if_not_exists = true
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space', nil, { if_not_exists = true })
box.schema.user.grant('test', 'create', 'sequence', nil, { if_not_exists = true })

-- Set listen only when every other thing is configured.
box.cfg{
listen = os.getenv("TEST_TNT_LISTEN"),
}
-- Set is_ready = is_ready_true only when every other thing is configured.
rawset(_G, 'is_ready', is_ready_true)
2 changes: 1 addition & 1 deletion datetime/datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var isDatetimeSupported = false

var server = "127.0.0.1:3013"
var opts = Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
Expand Down
2 changes: 1 addition & 1 deletion decimal/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func Example() {
server := "127.0.0.1:3013"
opts := tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
Reconnect: 1 * time.Second,
MaxReconnects: 3,
User: "test",
Expand Down
22 changes: 9 additions & 13 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ func ExampleConnection_Eval() {

func ExampleConnect() {
conn, err := tarantool.Connect("127.0.0.1:3013", tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
Concurrency: 32,
Expand Down Expand Up @@ -895,11 +895,9 @@ func ExampleConnection_Execute() {
}
server := "127.0.0.1:3013"
opts := tarantool.Opts{
Timeout: 500 * time.Millisecond,
Reconnect: 1 * time.Second,
MaxReconnects: 3,
User: "test",
Pass: "test",
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
client, err := tarantool.Connect(server, opts)
if err != nil {
Expand Down Expand Up @@ -1015,11 +1013,9 @@ func ExampleConnection_NewPrepared() {

server := "127.0.0.1:3013"
opts := tarantool.Opts{
Timeout: 500 * time.Millisecond,
Reconnect: 1 * time.Second,
MaxReconnects: 3,
User: "test",
Pass: "test",
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
conn, err := tarantool.Connect(server, opts)
if err != nil {
Expand Down Expand Up @@ -1057,8 +1053,8 @@ func ExampleConnection_NewWatcher() {

server := "127.0.0.1:3013"
opts := tarantool.Opts{
Timeout: 500 * time.Millisecond,
Reconnect: 1 * time.Second,
Timeout: 5 * time.Second,
Reconnect: 5 * time.Second,
MaxReconnects: 3,
User: "test",
Pass: "test",
Expand Down
4 changes: 2 additions & 2 deletions multi/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func ExampleConnect() {
multiConn, err := Connect([]string{"127.0.0.1:3031", "127.0.0.1:3032"}, tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
})
Expand All @@ -21,7 +21,7 @@ func ExampleConnect() {

func ExampleConnectWithOpts() {
multiConn, err := ConnectWithOpts([]string{"127.0.0.1:3301", "127.0.0.1:3302"}, tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}, OptsMulti{
Expand Down
2 changes: 1 addition & 1 deletion multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var spaceNo = uint32(617)
var spaceName = "test"
var indexNo = uint32(0)
var connOpts = tarantool.Opts{
Timeout: 500 * time.Millisecond,
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
Expand Down
Loading