Skip to content

Commit 4567442

Browse files
bigbesoleg-jukovec
authored andcommitted
const: add 'concurrent schema update' error constant
Closes #404, TNTP-3336
1 parent 20494e9 commit 4567442

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

CHANGELOG.md

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

1313
- Implemented all box.schema.user operations requests and sugar interface (#426).
1414
- Implemented box.session.su request and sugar interface only for current session granting (#426).
15+
- Defined `ErrConcurrentSchemaUpdate` constant for "concurrent schema update" error.
16+
Now you can check this error with `errors.Is(err, tarantool.ErrConcurrentSchemaUpdate)`.
1517

1618
### Changed
1719

schema.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const (
1919
vspaceSpFormatFieldNum = 7
2020
)
2121

22+
var (
23+
ErrConcurrentSchemaUpdate = errors.New("concurrent schema update")
24+
)
25+
2226
func msgpackIsUint(code byte) bool {
2327
return code == msgpcode.Uint8 || code == msgpcode.Uint16 ||
2428
code == msgpcode.Uint32 || code == msgpcode.Uint64 ||
@@ -415,7 +419,7 @@ func GetSchema(doer Doer) (Schema, error) {
415419
schema.SpacesById[spaceId].IndexesById[index.Id] = index
416420
schema.SpacesById[spaceId].Indexes[index.Name] = index
417421
} else {
418-
return Schema{}, errors.New("concurrent schema update")
422+
return Schema{}, ErrConcurrentSchemaUpdate
419423
}
420424
}
421425

schema_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8+
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910
"github.com/vmihailenco/msgpack/v5"
1011

@@ -160,3 +161,7 @@ func TestResolverNotCalledWithNameSupport(t *testing.T) {
160161
resolver.indexResolverCalls)
161162
}
162163
}
164+
165+
func TestErrConcurrentSchemaUpdate(t *testing.T) {
166+
assert.EqualError(t, tarantool.ErrConcurrentSchemaUpdate, "concurrent schema update")
167+
}

tarantool_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,14 +3999,13 @@ func TestConnect_schema_update(t *testing.T) {
39993999
for i := 0; i < 100; i++ {
40004000
fut := conn.Do(NewCallRequest("create_spaces"))
40014001

4002-
if conn, err := Connect(ctx, dialer, opts); err != nil {
4003-
if err.Error() != "concurrent schema update" {
4004-
t.Errorf("unexpected error: %s", err)
4005-
}
4006-
} else if conn == nil {
4007-
t.Errorf("conn is nil")
4008-
} else {
4009-
conn.Close()
4002+
switch conn, err := Connect(ctx, dialer, opts); {
4003+
case err != nil:
4004+
assert.ErrorIs(t, err, ErrConcurrentSchemaUpdate)
4005+
case conn == nil:
4006+
assert.Fail(t, "conn is nil")
4007+
default:
4008+
_ = conn.Close()
40104009
}
40114010

40124011
if _, err := fut.Get(); err != nil {

0 commit comments

Comments
 (0)