diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ea36601..f9b6d549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. - Implemented all box.schema.user operations requests and sugar interface (#426). - Implemented box.session.su request and sugar interface only for current session granting (#426). +- Defined `ErrConcurrentSchemaUpdate` constant for "concurrent schema update" error. + Now you can check this error with `errors.Is(err, tarantool.ErrConcurrentSchemaUpdate)`. ### Changed diff --git a/schema.go b/schema.go index 72b5e397..e7c09f80 100644 --- a/schema.go +++ b/schema.go @@ -19,6 +19,10 @@ const ( vspaceSpFormatFieldNum = 7 ) +var ( + ErrConcurrentSchemaUpdate = errors.New("concurrent schema update") +) + func msgpackIsUint(code byte) bool { return code == msgpcode.Uint8 || code == msgpcode.Uint16 || code == msgpcode.Uint32 || code == msgpcode.Uint64 || @@ -415,7 +419,7 @@ func GetSchema(doer Doer) (Schema, error) { schema.SpacesById[spaceId].IndexesById[index.Id] = index schema.SpacesById[spaceId].Indexes[index.Name] = index } else { - return Schema{}, errors.New("concurrent schema update") + return Schema{}, ErrConcurrentSchemaUpdate } } diff --git a/schema_test.go b/schema_test.go index 631591cb..cbc86391 100644 --- a/schema_test.go +++ b/schema_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vmihailenco/msgpack/v5" @@ -160,3 +161,7 @@ func TestResolverNotCalledWithNameSupport(t *testing.T) { resolver.indexResolverCalls) } } + +func TestErrConcurrentSchemaUpdate(t *testing.T) { + assert.EqualError(t, tarantool.ErrConcurrentSchemaUpdate, "concurrent schema update") +} diff --git a/tarantool_test.go b/tarantool_test.go index b053c5ae..14bb63ef 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -3999,14 +3999,13 @@ func TestConnect_schema_update(t *testing.T) { for i := 0; i < 100; i++ { fut := conn.Do(NewCallRequest("create_spaces")) - if conn, err := Connect(ctx, dialer, opts); err != nil { - if err.Error() != "concurrent schema update" { - t.Errorf("unexpected error: %s", err) - } - } else if conn == nil { - t.Errorf("conn is nil") - } else { - conn.Close() + switch conn, err := Connect(ctx, dialer, opts); { + case err != nil: + assert.ErrorIs(t, err, ErrConcurrentSchemaUpdate) + case conn == nil: + assert.Fail(t, "conn is nil") + default: + _ = conn.Close() } if _, err := fut.Get(); err != nil {