Skip to content

test: fix execution with Tarantool 1.6 #198

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

Closed
wants to merge 4 commits into from
Closed
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
43 changes: 42 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
golang:
- 1.13
tarantool:
- '1.6.9'
- '1.10'
- '2.8'
- '2.10'
Expand All @@ -44,12 +45,50 @@ jobs:
golang: 1.18
coveralls: false

env:
TNT_BUILD_INSTALL_PATH: /home/runner/tnt-install

steps:
- name: Clone the connector
uses: actions/checkout@v2

- name: Cache Tarantool build
if: matrix.tarantool == '1.6.9'
id: cache-tnt-build
uses: actions/cache@v3
with:
path: ${{ env.TNT_BUILD_INSTALL_PATH }}
key: cache-tnt-${{ matrix.tarantool }}
- name: Clone Tarantool ${{ matrix.tarantool }}
if: matrix.tarantool == '1.6.9' && steps.cache-tnt-build.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: tarantool/tarantool
ref: ${{ matrix.tarantool }}
path: tarantool
fetch-depth: 0
submodules: true

- name: Build Tarantool ${{ matrix.tarantool }}
if: matrix.tarantool == '1.6.9' && steps.cache-tnt-build.outputs.cache-hit != 'true'
run: |
sudo apt-get -y install git build-essential cmake make zlib1g-dev \
libreadline-dev libncurses5-dev libssl-dev \
libunwind-dev libicu-dev python3 python3-yaml \
python3-six python3-gevent
cd ${GITHUB_WORKSPACE}/tarantool
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make DESTDIR=${TNT_BUILD_INSTALL_PATH} install
Comment on lines +72 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. I would do the following instead:

  • Build the package once for Ubuntu Focal.
  • Agree with @LeonidVas and @artembo where to place such special packages.
  • Optionally add support for setup-tarantool.

I don't insist: if it works, it is likely okay. However we can do it a bit better (faster, more durable, less code).


- name: Setup Tarantool ${{ matrix.tarantool }} from a custom build
if: matrix.tarantool == '1.6.9'
run: |
sudo cp -rvP ${TNT_BUILD_INSTALL_PATH}/usr/local/* /usr/local/

- name: Setup Tarantool ${{ matrix.tarantool }}
if: matrix.tarantool != '2.x-latest'
if: matrix.tarantool != '2.x-latest' && matrix.tarantool != '1.6.9'
uses: tarantool/setup-tarantool@v1
with:
tarantool-version: ${{ matrix.tarantool }}
Expand All @@ -66,12 +105,14 @@ jobs:
go-version: ${{ matrix.golang }}

- name: Install test dependencies
if: matrix.tarantool != '1.6.9'
run: make deps

- name: Run regression tests
run: make test

- name: Run tests with call_17
if: matrix.tarantool != '1.6.9'
run: make test TAGS="go_tarantool_call_17"

- name: Run fuzzing tests
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Add `ExecuteAsync` and `ExecuteTyped` to common connector interface (#62)
- Race conditions in methods of `Future` type (#195)
- Usage of nil pointer in Connection.peekFuture (#195)
- Tests with Tarantool 1.6 (#198)

## [1.6.0] - 2022-06-01

Expand Down
56 changes: 36 additions & 20 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

local major = tonumber(string.sub(_TARANTOOL, 1, 1))
local minor = tonumber(string.sub(_TARANTOOL, 3, 3))

local num_type = "unsigned"
local string_type = "string"
if major == 1 and minor == 6 then
num_type = "NUM"
string_type = "STR"
box.schema.func.create('func_name')
end

box.once("init", function()
local s = box.schema.space.create('test', {
id = 517,
if_not_exists = true,
})
s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})

s:create_index('primary', {type = 'tree', parts = {1, num_type}, if_not_exists = true})
local sp = box.schema.space.create('SQL_TEST', {
id = 519,
if_not_exists = true,
format = {
{name = "NAME0", type = "unsigned"},
{name = "NAME1", type = "string"},
{name = "NAME2", type = "string"},
{name = "NAME0", type = num_type},
{name = "NAME1", type = string_type},
{name = "NAME2", type = string_type},
}
})
sp:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})
sp:create_index('primary', {type = 'tree', parts = {1, num_type}, if_not_exists = true})
sp:insert{1, "test", "test"}

local st = box.schema.space.create('schematest', {
Expand All @@ -29,25 +39,25 @@ box.once("init", function()
if_not_exists = true,
field_count = 7,
format = {
{name = "name0", type = "unsigned"},
{name = "name1", type = "unsigned"},
{name = "name2", type = "string"},
{name = "name3", type = "unsigned"},
{name = "name4", type = "unsigned"},
{name = "name5", type = "string"},
{name = "name0", type = num_type},
{name = "name1", type = num_type},
{name = "name2", type = string_type},
{name = "name3", type = num_type},
{name = "name4", type = num_type},
{name = "name5", type = string_type},
},
})
st:create_index('primary', {
type = 'hash',
parts = {1, 'uint'},
parts = {1, num_type},
unique = true,
if_not_exists = true,
})
st:create_index('secondary', {
id = 3,
type = 'tree',
unique = false,
parts = { 2, 'uint', 3, 'string' },
parts = { 2, num_type, 3, string_type },
if_not_exists = true,
})
st:truncate()
Expand All @@ -58,13 +68,14 @@ box.once("init", function()
if_not_exists = true,
field_count = 3,
format = {
{name = "id", type = "unsigned"},
{name = "name", type = "string"},
{name = "id", type = num_type},
{name = "name", type = string_type},
{name = "arr1", type = "array"},
},
})
s2:create_index('primary', {type = 'tree', unique = true, parts = {1, 'unsigned'}, if_not_exists = true})
s2:create_index('secondary', {id = 5, type = 'tree', unique = false, parts = {2, 'string'}, if_not_exists = true})
s2:create_index('primary', {type = 'tree', unique = true, parts = {1, num_type}, if_not_exists = true})
s2:create_index('secondary', {id = 5, type = 'tree', unique = false, parts = {2, string_type},
if_not_exists = true})
local arr_data = {}
for i = 1,100 do
arr_data[i] = i
Expand All @@ -84,13 +95,18 @@ box.once("init", function()
-- auth testing: access control
box.schema.user.create('test', {password = 'test'})
box.schema.user.grant('test', 'execute', 'universe')
if major == 1 and minor == 6 then
box.schema.user.grant('test', 'execute', 'function', 'func_name')
end
box.schema.user.grant('test', 'read,write', 'space', 'test')
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
box.schema.user.grant('test', 'read,write', 'space', 'test_perf')

-- grants for sql tests
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space')
box.schema.user.grant('test', 'create', 'sequence')
if major >= 2 then
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space')
box.schema.user.grant('test', 'create', 'sequence')
end
end)

local function func_name()
Expand Down
11 changes: 10 additions & 1 deletion connection_pool/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,16 @@ func TestDoWithStrangerConn(t *testing.T) {
// is a separate function, see
// https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls
func runTestMain(m *testing.M) int {
isLess, err := test_helpers.IsTarantoolVersionLess(1, 7, 4)
if err != nil {
log.Fatalf("Failed to extract Tarantool version: %s", err)
}

if isLess {
log.Println("Skipping connection pool tests...")
return 0
}

initScript := "config.lua"
waitStart := 100 * time.Millisecond
var connectRetry uint = 3
Expand All @@ -1383,7 +1393,6 @@ func runTestMain(m *testing.M) int {
"work_dir1", "work_dir2",
"work_dir3", "work_dir4",
"work_dir5"}
var err error

instances, err = test_helpers.StartTarantoolInstances(servers, workDirs, test_helpers.StartOpts{
InitScript: initScript,
Expand Down
6 changes: 3 additions & 3 deletions example_custom_unpacking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func Example_customUnpacking() {
fmt.Println("Tuples (tuples2):", tuples2)

// Call a function "func_name" returning a table of custom tuples.
var tuples3 [][]Tuple3
err = conn.Call17Typed("func_name", []interface{}{}, &tuples3)
var tuples3 []Tuple3
err = conn.Call16Typed("func_name", []interface{}{}, &tuples3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I really don't like about CALL_16: it implicitly changes a shape of the result (and the rules are not very obvious). Personally I would avoid it as much as possible. Or at least call only those functions, which return exactly what we'll receive on the connector side: so it will not be wrapped into an array or unwrapped. Maybe skipping of some tests is not so evil as pollute them with CALL_16.

I don't insist, just share my feeling about this.

if err != nil {
log.Fatalf("Failed to CallTyped: %s", err.Error())
return
Expand All @@ -131,6 +131,6 @@ func Example_customUnpacking() {
// Code 0
// Tuples (tuples1) [{777 orig [{lol 1} {wut 3}]}]
// Tuples (tuples2): [{{} 777 orig [{lol 1} {wut 3}]}]
// Tuples (tuples3): [[{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]]
// Tuples (tuples3): [{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]

}
20 changes: 8 additions & 12 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@ func ExampleFuture_GetIterator() {
fmt.Printf("error in call of push_func is %v", err)
return
}
// Output:
// push message: 1
// push message: 2
// push message: 3
// push message: 4
// response: 4
}

func ExampleConnection_Ping() {
Expand Down Expand Up @@ -416,7 +410,7 @@ func ExampleConnection_Call() {
defer conn.Close()

// Call a function 'simple_incr' with arguments.
resp, err := conn.Call17("simple_incr", []interface{}{1})
resp, err := conn.Call16("simple_incr", []interface{}{1})
fmt.Println("Call simple_incr()")
fmt.Println("Error", err)
fmt.Println("Code", resp.Code)
Expand All @@ -425,7 +419,7 @@ func ExampleConnection_Call() {
// Call simple_incr()
// Error <nil>
// Code 0
// Data [2]
// Data [[2]]
}

func ExampleConnection_Eval() {
Expand Down Expand Up @@ -510,25 +504,27 @@ func ExampleSpace() {
index1 := space1.Indexes["primary"]
index2 := space2.IndexesById[3] // It's a map.
fmt.Printf("Index %d %s\n", index1.Id, index1.Name)
fmt.Printf("Index %d %s\n", index2.Id, index2.Name)

// Access index fields information by index.
/* The result depends on Tarantool version.
indexField1 := index1.Fields[0] // It's a slice.
indexField2 := index2.Fields[1] // It's a slice.
fmt.Println(indexField1, indexField2)

*/
// Access space fields information by name or id (index).
/* The result depends on Tarantool version.
spaceField1 := space2.Fields["name0"]
spaceField2 := space2.FieldsById[3]
fmt.Printf("SpaceField 1 %s %s\n", spaceField1.Name, spaceField1.Type)
fmt.Printf("SpaceField 2 %s %s\n", spaceField2.Name, spaceField2.Type)
*/

// Output:
// Space 1 ID 517 test memtx
// Space 1 ID 0 false
// Index 0 primary
// &{0 unsigned} &{2 string}
// SpaceField 1 name0 unsigned
// SpaceField 2 name3 unsigned
// Index 3 secondary
}

// To use SQL to query a tarantool instance, call Execute.
Expand Down
24 changes: 18 additions & 6 deletions multi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

local major = tonumber(string.sub(_TARANTOOL, 1, 1))
local minor = tonumber(string.sub(_TARANTOOL, 3, 3))

local num_type = "unsigned"
local string_type = "string"
if major == 1 and minor == 6 then
num_type = "NUM"
string_type = "STR"
end

-- Function to call for getting address list, part of tarantool/multi API.
local get_cluster_nodes = nodes_load.get_cluster_nodes
rawset(_G, 'get_cluster_nodes', get_cluster_nodes)
Expand All @@ -18,16 +28,18 @@ box.once("init", function()
id = 521,
if_not_exists = true,
format = {
{name = "NAME0", type = "unsigned"},
{name = "NAME1", type = "string"},
{name = "NAME2", type = "string"},
{name = "NAME0", type = num_type},
{name = "NAME1", type = string_type},
{name = "NAME2", type = string_type},
}
})
sp:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})
sp:create_index('primary', {type = 'tree', parts = {1, num_type}, if_not_exists = true})
sp:insert{1, "test", "test"}
-- grants for sql tests
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space')
box.schema.user.grant('test', 'create', 'sequence')
if major >= 2 then
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space')
box.schema.user.grant('test', 'create', 'sequence')
end
end)

local function simple_incr(a)
Expand Down
2 changes: 1 addition & 1 deletion multi/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (connMulti *ConnectionMulti) checker() {
continue
}
var resp [][]string
err := connMulti.Call17Typed(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp)
err := connMulti.Call16Typed(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp)
Copy link
Member

@Totktonada Totktonada Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a strict equivalent, see tarantool/tarantool-java#196.

if err != nil {
continue
}
Expand Down
11 changes: 9 additions & 2 deletions multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,22 @@ func TestRefresh(t *testing.T) {
t.Errorf("Expect connection to exist")
}

_, err := multiConn.Call17(multiConn.opts.NodesGetFunctionName, []interface{}{})
_, err := multiConn.Call16(multiConn.opts.NodesGetFunctionName, []interface{}{})
if err != nil {
t.Error("Expect to get data after reconnect")
}
}

func TestCall17(t *testing.T) {
isLess, err := test_helpers.IsTarantoolVersionLess(1, 7, 2)
if err != nil {
t.Fatalf("Failed to extract Tarantool version: %s", err)
}
if isLess {
t.Skip("Skipping test for Tarantool without Call17 support")
}

var resp *tarantool.Response
var err error

multiConn, err := Connect([]string{server1, server2}, connOpts)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ func TestUtube_Put(t *testing.T) {
// is a separate function, see
// https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls
func runTestMain(m *testing.M) int {
isLess, err := test_helpers.IsTarantoolVersionLess(1, 7, 4)
if err != nil {
log.Fatalf("Failed to extract Tarantool version: %s", err)
}

if isLess {
log.Println("Skipping queue tests...")
return 0
}

inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: "config.lua",
Listen: server,
Expand Down
Loading