Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
and Future.GetIterator() methods, ResponseIterator and TimeoutResponseIterator types,
Future.pushes[] (#480).
* `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480)
* Removed deprecated `Connection` methods, related interfaces and tests are updated (#479)

### Fixed

Expand Down
1 change: 1 addition & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TODO
* Removed deprecated `pool` methods, related interfaces and tests are updated.
* Removed `box.session.push()` support: Future.AppendPush() and Future.GetIterator()
methods, ResponseIterator and TimeoutResponseIterator types.
* Removed deprecated `Connection` methods, related interfaces and tests are updated.

## Migration from v1.x.x to v2.x.x

Expand Down
206 changes: 0 additions & 206 deletions boxerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/vmihailenco/msgpack/v5"

. "github.com/tarantool/go-tarantool/v3"
"github.com/tarantool/go-tarantool/v3/test_helpers"
)

var samples = map[string]BoxError{
Expand Down Expand Up @@ -215,9 +214,6 @@ func TestMessagePackEncodeNil(t *testing.T) {
require.Equal(t, "msgpack: unexpected nil BoxError on encode", err.Error())
}

var space = "test_error_type"
var index = "primary"

type TupleBoxError struct {
pk string // BoxError cannot be used as a primary key.
val BoxError
Expand Down Expand Up @@ -295,205 +291,3 @@ func TestErrorTypeMPEncodeDecode(t *testing.T) {
})
}
}

func TestErrorTypeEval(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why have you deleted these tests, instead of rewriting it using "NewEvalRequest?"

Copy link
Collaborator Author

@laines-it laines-it Nov 19, 2025

Choose a reason for hiding this comment

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

My bad, I thought error types of RequestObjects have been tested in other tests, but they haven't. Indeed, I should just rewrite tests, not delete them.
I'll fix this in next commit amendment.

test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
data, err := conn.Eval("return ...", []interface{}{&testcase.tuple.val})
require.Nil(t, err)
require.NotNil(t, data)
require.Equal(t, len(data), 1)
actual, ok := data[0].(*BoxError)
require.Truef(t, ok, "Response data has valid type")
require.Equal(t, testcase.tuple.val, *actual)
})
}
}

func TestErrorTypeEvalTyped(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
var res []BoxError
err := conn.EvalTyped("return ...", []interface{}{&testcase.tuple.val}, &res)
require.Nil(t, err)
require.NotNil(t, res)
require.Equal(t, len(res), 1)
require.Equal(t, testcase.tuple.val, res[0])
})
}
}

func TestErrorTypeInsert(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
_, err := conn.Eval(truncateEval, []interface{}{})
require.Nil(t, err)

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
_, err = conn.Insert(space, &testcase.tuple)
require.Nil(t, err)

checkEval := fmt.Sprintf(`
local err = rawget(_G, %q)
assert(err ~= nil)
local tuple = box.space[%q]:get(%q)
assert(tuple ~= nil)
local tuple_err = tuple[2]
assert(tuple_err ~= nil)
return compare_box_errors(tuple_err, err)
`, testcase.ttObj, space, testcase.tuple.pk)

// In fact, compare_box_errors does not check than File and Line
// of connector BoxError are equal to the Tarantool ones
// since they may differ between different Tarantool versions
// and editions.
_, err := conn.Eval(checkEval, []interface{}{})
require.Nilf(t, err, "Tuple has been successfully inserted")
})
}
}

func TestErrorTypeInsertTyped(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
_, err := conn.Eval(truncateEval, []interface{}{})
require.Nil(t, err)

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
var res []TupleBoxError
err = conn.InsertTyped(space, &testcase.tuple, &res)
require.Nil(t, err)
require.NotNil(t, res)
require.Equal(t, len(res), 1)
require.Equal(t, testcase.tuple, res[0])

checkEval := fmt.Sprintf(`
local err = rawget(_G, %q)
assert(err ~= nil)
local tuple = box.space[%q]:get(%q)
assert(tuple ~= nil)
local tuple_err = tuple[2]
assert(tuple_err ~= nil)
return compare_box_errors(tuple_err, err)
`, testcase.ttObj, space, testcase.tuple.pk)

// In fact, compare_box_errors does not check than File and Line
// of connector BoxError are equal to the Tarantool ones
// since they may differ between different Tarantool versions
// and editions.
_, err := conn.Eval(checkEval, []interface{}{})
require.Nilf(t, err, "Tuple has been successfully inserted")
})
}
}

func TestErrorTypeSelect(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
_, err := conn.Eval(truncateEval, []interface{}{})
require.Nil(t, err)

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
insertEval := fmt.Sprintf(`
local err = rawget(_G, %q)
assert(err ~= nil)
local tuple = box.space[%q]:insert{%q, err}
assert(tuple ~= nil)
`, testcase.ttObj, space, testcase.tuple.pk)

_, err := conn.Eval(insertEval, []interface{}{})
require.Nilf(t, err, "Tuple has been successfully inserted")

var offset uint32 = 0
var limit uint32 = 1
data, err := conn.Select(space, index, offset, limit, IterEq,
[]interface{}{testcase.tuple.pk})
require.Nil(t, err)
require.NotNil(t, data)
require.Equalf(t, len(data), 1, "Exactly one tuple had been found")
tpl, ok := data[0].([]interface{})
require.Truef(t, ok, "Tuple has valid type")
require.Equal(t, testcase.tuple.pk, tpl[0])
actual, ok := tpl[1].(*BoxError)
require.Truef(t, ok, "BoxError tuple field has valid type")
// In fact, CheckEqualBoxErrors does not check than File and Line
// of connector BoxError are equal to the Tarantool ones
// since they may differ between different Tarantool versions
// and editions.
test_helpers.CheckEqualBoxErrors(t, testcase.tuple.val, *actual)
})
}
}

func TestErrorTypeSelectTyped(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

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

truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
_, err := conn.Eval(truncateEval, []interface{}{})
require.Nil(t, err)

for name, testcase := range tupleCases {
t.Run(name, func(t *testing.T) {
insertEval := fmt.Sprintf(`
local err = rawget(_G, %q)
assert(err ~= nil)
local tuple = box.space[%q]:insert{%q, err}
assert(tuple ~= nil)
`, testcase.ttObj, space, testcase.tuple.pk)

_, err := conn.Eval(insertEval, []interface{}{})
require.Nilf(t, err, "Tuple has been successfully inserted")

var offset uint32 = 0
var limit uint32 = 1
var resp []TupleBoxError
err = conn.SelectTyped(space, index, offset, limit, IterEq,
[]interface{}{testcase.tuple.pk}, &resp)
require.Nil(t, err)
require.NotNil(t, resp)
require.Equalf(t, len(resp), 1, "Exactly one tuple had been found")
require.Equal(t, testcase.tuple.pk, resp[0].pk)
// In fact, CheckEqualBoxErrors does not check than File and Line
// of connector BoxError are equal to the Tarantool ones
// since they may differ between different Tarantool versions
// and editions.
test_helpers.CheckEqualBoxErrors(t, testcase.tuple.val, resp[0].val)
})
}
}
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func (conn *Connection) pinger() {
return
case <-t.C:
}
conn.Ping()
conn.Do(NewPingRequest())
}
}

Expand Down
Loading
Loading