Skip to content

Commit 2f37bff

Browse files
committed
code-health: update format for Call to 1.7
An incompatible change was introduced in Tarantool 1.7 which was released in 2016. This change is about a new binary protocol command for CALL, which no more restricts a function to returning an array of tuples and allows returning an arbitrary MsgPack/JSON result, including scalars, nil and void (nothing). We should be in-line with tarantool here and provide `Call17` as just `Call` and rename current `Call` to `Call16`. Closes #125
1 parent 1a1fe7b commit 2f37bff

21 files changed

+256
-66
lines changed

.github/workflows/testing.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
- name: Run tests
6161
run: make test
6262

63+
- name: Run tests with call_17
64+
run: make test TAGS="go_tarantool_call_17"
65+
6366
- name: Run tests, collect code coverage data and send to Coveralls
6467
if: ${{ matrix.coveralls }}
6568
env:
@@ -134,6 +137,13 @@ jobs:
134137
env:
135138
TEST_TNT_SSL: ${{matrix.ssl}}
136139

140+
- name: Run tests with call_17
141+
run: |
142+
source tarantool-enterprise/env.sh
143+
make test TAGS="go_tarantool_call_17"
144+
env:
145+
TEST_TNT_SSL: ${{matrix.ssl}}
146+
137147
- name: Run tests, collect code coverage data and send to Coveralls
138148
if: ${{ matrix.coveralls }}
139149
env:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1515

1616
### Changed
1717

18+
- Breaking change: rename `Call` to `Call16` and `Call17` to `Call` (#125)
19+
1820
### Fixed
1921

2022
## [1.6.0] - 2022-06-01

Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ BENCH_REFERENCE_REPO := ${BENCH_PATH}/go-tarantool
1313
BENCH_OPTIONS := -bench=. -run=^Benchmark -benchmem -benchtime=${DURATION} -count=${COUNT}
1414
GO_TARANTOOL_URL := https://github.com/tarantool/go-tarantool
1515
GO_TARANTOOL_DIR := ${PROJECT_DIR}/${BENCH_PATH}/go-tarantool
16+
TAGS :=
1617

1718
.PHONY: clean
1819
clean:
@@ -33,7 +34,7 @@ golangci-lint:
3334

3435
.PHONY: test
3536
test:
36-
go test ./... -v -p 1
37+
go test -tags "$(TAGS)" ./... -v -p 1
3738

3839
.PHONY: testdata
3940
testdata:
@@ -43,38 +44,38 @@ testdata:
4344
test-connection-pool:
4445
@echo "Running tests in connection_pool package"
4546
go clean -testcache
46-
go test ./connection_pool/ -v -p 1
47+
go test -tags "$(TAGS)" ./connection_pool/ -v -p 1
4748

4849
.PHONY: test-multi
4950
test-multi:
5051
@echo "Running tests in multiconnection package"
5152
go clean -testcache
52-
go test ./multi/ -v -p 1
53+
go test -tags "$(TAGS)" ./multi/ -v -p 1
5354

5455
.PHONY: test-queue
5556
test-queue:
5657
@echo "Running tests in queue package"
5758
cd ./queue/ && tarantool -e "require('queue')"
5859
go clean -testcache
59-
go test ./queue/ -v -p 1
60+
go test -tags "$(TAGS)" ./queue/ -v -p 1
6061

6162
.PHONY: test-uuid
6263
test-uuid:
6364
@echo "Running tests in UUID package"
6465
go clean -testcache
65-
go test ./uuid/ -v -p 1
66+
go test -tags "$(TAGS)" ./uuid/ -v -p 1
6667

6768
.PHONY: test-main
6869
test-main:
6970
@echo "Running tests in main package"
7071
go clean -testcache
71-
go test . -v -p 1
72+
go test -tags "$(TAGS)" . -v -p 1
7273

7374
.PHONY: coverage
7475
coverage:
7576
go clean -testcache
7677
go get golang.org/x/tools/cmd/cover
77-
go test ./... -v -p 1 -covermode=atomic -coverprofile=$(COVERAGE_FILE) -coverpkg=./...
78+
go test -tags "$(TAGS)" ./... -v -p 1 -covermode=atomic -coverprofile=$(COVERAGE_FILE) -coverpkg=./...
7879
go tool cover -func=$(COVERAGE_FILE)
7980

8081
.PHONY: coveralls
@@ -94,7 +95,7 @@ ${BENCH_PATH} bench-deps:
9495
.PHONY: bench
9596
${BENCH_FILE} bench: ${BENCH_PATH}
9697
@echo "Running benchmark tests from the current branch"
97-
go test ${TEST_PATH} ${BENCH_OPTIONS} 2>&1 \
98+
go test -tags "$(TAGS)" ${TEST_PATH} ${BENCH_OPTIONS} 2>&1 \
9899
| tee ${BENCH_FILE}
99100
benchstat ${BENCH_FILE}
100101

@@ -104,7 +105,7 @@ ${GO_TARANTOOL_DIR}:
104105

105106
${REFERENCE_FILE}: ${GO_TARANTOOL_DIR}
106107
@echo "Running benchmark tests from master for using results in bench-diff target"
107-
cd ${GO_TARANTOOL_DIR} && git pull && go test ./... ${BENCH_OPTIONS} 2>&1 \
108+
cd ${GO_TARANTOOL_DIR} && git pull && go test ./... -tags "$(TAGS)" ${BENCH_OPTIONS} 2>&1 \
108109
| tee ${REFERENCE_FILE}
109110

110111
bench-diff: ${BENCH_FILES}

call_16_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build !go_tarantool_call_17
2+
// +build !go_tarantool_call_17
3+
4+
package tarantool_test
5+
6+
import (
7+
"testing"
8+
9+
. "github.com/tarantool/go-tarantool"
10+
)
11+
12+
func TestConnection_Call(t *testing.T) {
13+
var resp *Response
14+
var err error
15+
16+
conn := connect(t, server, opts)
17+
defer conn.Close()
18+
19+
// Call16
20+
resp, err = conn.Call("simple_incr", []interface{}{1})
21+
if err != nil {
22+
t.Errorf("Failed to use Call")
23+
}
24+
if resp.Data[0].([]interface{})[0].(uint64) != 2 {
25+
t.Errorf("result is not {{1}} : %v", resp.Data)
26+
}
27+
}

call_17_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build go_tarantool_call_17
2+
// +build go_tarantool_call_17
3+
4+
package tarantool_test
5+
6+
import (
7+
"testing"
8+
9+
. "github.com/tarantool/go-tarantool"
10+
)
11+
12+
func TestConnection_Call(t *testing.T) {
13+
var resp *Response
14+
var err error
15+
16+
conn := connect(t, server, opts)
17+
defer conn.Close()
18+
19+
// Call17
20+
resp, err = conn.Call17("simple_incr", []interface{}{1})
21+
if err != nil {
22+
t.Errorf("Failed to use Call")
23+
}
24+
if resp.Data[0].(uint64) != 2 {
25+
t.Errorf("result is not {{1}} : %v", resp.Data)
26+
}
27+
}

connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
116116
//
117117
// ATTENTION: result argument for *Typed methods should deserialize from
118118
// msgpack array, cause Tarantool always returns result as an array.
119-
// For all space related methods and Call* (but not Call17*) methods Tarantool
119+
// For all space related methods and Call16* (but not Call*) methods Tarantool
120120
// always returns array of array (array of tuples for space related methods).
121-
// For Eval* and Call17* Tarantool always returns array, but does not forces
121+
// For Eval* and Call* Tarantool always returns array, but does not forces
122122
// array of arrays.
123123
type Connection struct {
124124
addr string

connection_pool/connection_pool.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}
255255
return conn.Upsert(space, tuple, ops)
256256
}
257257

258-
// Call calls registered Tarantool function.
259-
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
258+
// Call16 calls registered Tarantool function.
259+
// It uses request code for Tarantool >= 1.7 if go-tarantool
260+
// was build with go_tarantool_call_17 tag.
261+
// Otherwise, uses request code for Tarantool 1.6.
260262
func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
261263
conn, err := connPool.getNextConnection(userMode)
262264
if err != nil {
@@ -266,8 +268,20 @@ func (connPool *ConnectionPool) Call(functionName string, args interface{}, user
266268
return conn.Call(functionName, args)
267269
}
268270

271+
// Call16 calls registered Tarantool function.
272+
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
273+
// Deprecated since 1.7.4.
274+
func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
275+
conn, err := connPool.getNextConnection(userMode)
276+
if err != nil {
277+
return nil, err
278+
}
279+
280+
return conn.Call16(functionName, args)
281+
}
282+
269283
// Call17 calls registered Tarantool function.
270-
// It uses request code for Tarantool 1.7, so result is not converted
284+
// It uses request code for Tarantool >= 1.7, so result is not converted
271285
// (though, keep in mind, result is always array).
272286
func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
273287
conn, err := connPool.getNextConnection(userMode)
@@ -352,7 +366,9 @@ func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops i
352366
}
353367

354368
// CallTyped calls registered function.
355-
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
369+
// It uses request code for Tarantool >= 1.7 if go-tarantool
370+
// was build with go_tarantool_call_17 tag.
371+
// Otherwise, uses request code for Tarantool 1.6.
356372
func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
357373
conn, err := connPool.getNextConnection(userMode)
358374
if err != nil {
@@ -362,8 +378,20 @@ func (connPool *ConnectionPool) CallTyped(functionName string, args interface{},
362378
return conn.CallTyped(functionName, args, result)
363379
}
364380

381+
// Call16Typed calls registered function.
382+
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
383+
// Deprecated since 1.7.4.
384+
func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
385+
conn, err := connPool.getNextConnection(userMode)
386+
if err != nil {
387+
return err
388+
}
389+
390+
return conn.Call16Typed(functionName, args, result)
391+
}
392+
365393
// Call17Typed calls registered function.
366-
// It uses request code for Tarantool 1.7, so result is not converted
394+
// It uses request code for Tarantool >= 1.7, so result is not converted
367395
// (though, keep in mind, result is always array).
368396
func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
369397
conn, err := connPool.getNextConnection(userMode)
@@ -450,7 +478,9 @@ func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}
450478
}
451479

452480
// CallAsync sends a call to registered Tarantool function and returns Future.
453-
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
481+
// It uses request code for Tarantool >= 1.7 if go-tarantool
482+
// was build with go_tarantool_call_17 tag.
483+
// Otherwise, uses request code for Tarantool 1.6.
454484
func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future {
455485
conn, err := connPool.getNextConnection(userMode)
456486
if err != nil {
@@ -460,8 +490,20 @@ func (connPool *ConnectionPool) CallAsync(functionName string, args interface{},
460490
return conn.CallAsync(functionName, args)
461491
}
462492

493+
// Call16Async sends a call to registered Tarantool function and returns Future.
494+
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
495+
// Deprecated since 1.7.4.
496+
func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
497+
conn, err := connPool.getNextConnection(userMode)
498+
if err != nil {
499+
return tarantool.NewErrorFuture(err)
500+
}
501+
502+
return conn.Call16Async(functionName, args)
503+
}
504+
463505
// Call17Async sends a call to registered Tarantool function and returns Future.
464-
// It uses request code for Tarantool 1.7, so future's result will not be converted
506+
// It uses request code for Tarantool >= 1.7, so future's result will not be converted
465507
// (though, keep in mind, result is always array).
466508
func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
467509
conn, err := connPool.getNextConnection(userMode)

connection_pool/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func ExampleConnectionPool_Update() {
490490
// Data [[key1 new_value]]
491491
}
492492

493-
func ExampleConnectionPool_Call17() {
493+
func ExampleConnectionPool_Call() {
494494
pool, err := examplePool(testRoles)
495495
if err != nil {
496496
fmt.Println(err)

connector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Connector interface {
1515
Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
1616
Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
1717
Call(functionName string, args interface{}) (resp *Response, err error)
18+
Call16(functionName string, args interface{}) (resp *Response, err error)
1819
Call17(functionName string, args interface{}) (resp *Response, err error)
1920
Eval(expr string, args interface{}) (resp *Response, err error)
2021
Execute(expr string, args interface{}) (resp *Response, err error)
@@ -26,6 +27,7 @@ type Connector interface {
2627
DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
2728
UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
2829
CallTyped(functionName string, args interface{}, result interface{}) (err error)
30+
Call16Typed(functionName string, args interface{}, result interface{}) (err error)
2931
Call17Typed(functionName string, args interface{}, result interface{}) (err error)
3032
EvalTyped(expr string, args interface{}, result interface{}) (err error)
3133

@@ -36,6 +38,7 @@ type Connector interface {
3638
UpdateAsync(space, index interface{}, key, ops interface{}) *Future
3739
UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
3840
CallAsync(functionName string, args interface{}) *Future
41+
Call16Async(functionName string, args interface{}) *Future
3942
Call17Async(functionName string, args interface{}) *Future
4043
EvalAsync(expr string, args interface{}) *Future
4144
}

const.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const (
66
ReplaceRequest = 3
77
UpdateRequest = 4
88
DeleteRequest = 5
9-
CallRequest = 6 /* call in 1.6 format */
9+
Call16Request = 6 /* call in 1.6 format */
1010
AuthRequest = 7
1111
EvalRequest = 8
1212
UpsertRequest = 9
13-
Call17Request = 10
13+
Call17Request = 10 /* call in >= 1.7 format */
1414
ExecuteRequest = 11
1515
PingRequest = 64
1616
SubscribeRequest = 66

const_call_16.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !go_tarantool_call_17
2+
// +build !go_tarantool_call_17
3+
4+
package tarantool
5+
6+
const (
7+
CallRequest = 6 // CALL_16
8+
)

const_call_17.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build go_tarantool_call_17
2+
// +build go_tarantool_call_17
3+
4+
package tarantool
5+
6+
const (
7+
CallRequest = 10 // CALL_17
8+
)

example_custom_unpacking_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func Example_customUnpacking() {
118118
fmt.Println("Tuples (tuples2):", tuples2)
119119

120120
// Call a function "func_name" returning a table of custom tuples.
121-
var tuples3 []Tuple3
122-
err = conn.CallTyped("func_name", []interface{}{}, &tuples3)
121+
var tuples3 [][]Tuple3
122+
err = conn.Call17Typed("func_name", []interface{}{}, &tuples3)
123123
if err != nil {
124124
log.Fatalf("Failed to CallTyped: %s", err.Error())
125125
return
@@ -131,6 +131,6 @@ func Example_customUnpacking() {
131131
// Code 0
132132
// Tuples (tuples1) [{777 orig [{lol 1} {wut 3}]}]
133133
// Tuples (tuples2): [{{} 777 orig [{lol 1} {wut 3}]}]
134-
// Tuples (tuples3): [{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]
134+
// Tuples (tuples3): [[{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]]
135135

136136
}

example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func ExampleConnection_Update() {
309309
// Data [[14 bye bla]]
310310
}
311311

312-
func ExampleConnection_Call17() {
312+
func ExampleConnection_Call() {
313313
conn := example_connect()
314314
defer conn.Close()
315315

0 commit comments

Comments
 (0)