From a916922caa32c7125923d517a286884d1940cfe1 Mon Sep 17 00:00:00 2001 From: DerekBum Date: Wed, 25 Oct 2023 21:15:58 +0300 Subject: [PATCH] api: use `iproto` types and constants for the `protocol` Replaced the local `ProtocolFeature` type with the `iproto.Feature`. Replaced local `Feature` constants with their `iproto.IPROTO_FEATURE_` analogues. Closes #337 --- CHANGELOG.md | 3 + README.md | 5 ++ connection.go | 14 ++-- connection_test.go | 7 +- dial_test.go | 9 ++- example_test.go | 22 +++--- pool/connection_pool.go | 12 +-- pool/connection_pool_test.go | 27 +++---- pool/example_test.go | 28 +++++-- protocol.go | 62 +++------------- protocol_test.go | 18 +---- request_test.go | 2 +- response.go | 4 +- shutdown_test.go | 3 +- tarantool_test.go | 139 ++++++++++++++++++----------------- 15 files changed, 167 insertions(+), 188 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4886780..63ed00b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. `pool.Connect` and `pool.Add` now accept context as first argument, which user may cancel in process. If `pool.Connect` is canceled in progress, an error will be returned. All created connections will be closed. +- `iproto.Feature` type now used instead of `ProtocolFeature` (#337) +- `iproto.IPROTO_FEATURE_` constants now used instead of local `Feature` + constants for `protocol` (#337) ### Deprecated diff --git a/README.md b/README.md index 378c344b3..2c7de68c4 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,11 @@ now does not attempt to reconnect and tries to establish a connection only once. Function might be canceled via context. Context accepted as first argument, and user may cancel it in process. +#### Protocol changes + +* `iproto.Feature` type used instead of `ProtocolFeature`. +* `iproto.IPROTO_FEATURE_` constants used instead of local ones. + ## Contributing See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how diff --git a/connection.go b/connection.go index f304a12ba..018df6caa 100644 --- a/connection.go +++ b/connection.go @@ -564,7 +564,8 @@ func (conn *Connection) dial(ctx context.Context) error { // Subscribe shutdown event to process graceful shutdown. if conn.shutdownWatcher == nil && - isFeatureInSlice(WatchersFeature, conn.serverProtocolInfo.Features) { + isFeatureInSlice(iproto.IPROTO_FEATURE_WATCHERS, + conn.serverProtocolInfo.Features) { watcher, werr := conn.newWatcherImpl(shutdownEventKey, shutdownEventCallback) if werr != nil { return werr @@ -1425,7 +1426,7 @@ func subscribeWatchChannel(conn *Connection, key string) (chan watchState, error return st, nil } -func isFeatureInSlice(expected ProtocolFeature, actualSlice []ProtocolFeature) bool { +func isFeatureInSlice(expected iproto.Feature, actualSlice []iproto.Feature) bool { for _, actual := range actualSlice { if expected == actual { return true @@ -1436,8 +1437,8 @@ func isFeatureInSlice(expected ProtocolFeature, actualSlice []ProtocolFeature) b // NewWatcher creates a new Watcher object for the connection. // -// You need to require WatchersFeature to use watchers, see examples for the -// function. +// You need to require IPROTO_FEATURE_WATCHERS to use watchers, see examples +// for the function. // // After watcher creation, the watcher callback is invoked for the first time. // In this case, the callback is triggered whether or not the key has already @@ -1472,9 +1473,10 @@ func (conn *Connection) NewWatcher(key string, callback WatchCallback) (Watcher, // asynchronous. We do not expect any response from a Tarantool instance // That's why we can't just check the Tarantool response for an unsupported // request error. - if !isFeatureInSlice(WatchersFeature, conn.opts.RequiredProtocolInfo.Features) { + if !isFeatureInSlice(iproto.IPROTO_FEATURE_WATCHERS, + conn.opts.RequiredProtocolInfo.Features) { err := fmt.Errorf("the feature %s must be required by connection "+ - "options to create a watcher", WatchersFeature) + "options to create a watcher", iproto.IPROTO_FEATURE_WATCHERS) return nil, err } diff --git a/connection_test.go b/connection_test.go index 3e7be1966..20d06b183 100644 --- a/connection_test.go +++ b/connection_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" . "github.com/tarantool/go-tarantool/v2" ) @@ -12,20 +13,20 @@ func TestOptsClonePreservesRequiredProtocolFeatures(t *testing.T) { original := Opts{ RequiredProtocolInfo: ProtocolInfo{ Version: ProtocolVersion(100), - Features: []ProtocolFeature{ProtocolFeature(99), ProtocolFeature(100)}, + Features: []iproto.Feature{iproto.Feature(99), iproto.Feature(100)}, }, } origCopy := original.Clone() - original.RequiredProtocolInfo.Features[1] = ProtocolFeature(98) + original.RequiredProtocolInfo.Features[1] = iproto.Feature(98) require.Equal(t, origCopy, Opts{ RequiredProtocolInfo: ProtocolInfo{ Version: ProtocolVersion(100), - Features: []ProtocolFeature{ProtocolFeature(99), ProtocolFeature(100)}, + Features: []iproto.Feature{iproto.Feature(99), iproto.Feature(100)}, }, }) } diff --git a/dial_test.go b/dial_test.go index acd6737c5..209fc50cd 100644 --- a/dial_test.go +++ b/dial_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" "github.com/tarantool/go-tarantool/v2" "github.com/tarantool/go-tarantool/v2/test_helpers" @@ -72,8 +73,8 @@ func TestDialer_Dial_passedOpts(t *testing.T) { RequiredProtocol: tarantool.ProtocolInfo{ Auth: tarantool.ChapSha1Auth, Version: 33, - Features: []tarantool.ProtocolFeature{ - tarantool.ErrorExtensionFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_ERROR_EXTENSION, }, }, Auth: tarantool.ChapSha1Auth, @@ -302,8 +303,8 @@ func TestConn_ProtocolInfo(t *testing.T) { info := tarantool.ProtocolInfo{ Auth: tarantool.ChapSha1Auth, Version: 33, - Features: []tarantool.ProtocolFeature{ - tarantool.ErrorExtensionFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_ERROR_EXTENSION, }, } conn, dialer := dialIo(t, func(conn *mockIoConn) { diff --git a/example_test.go b/example_test.go index 5557e7a4c..f85f532d0 100644 --- a/example_test.go +++ b/example_test.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "github.com/tarantool/go-iproto" + "github.com/tarantool/go-tarantool/v2" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -627,12 +629,12 @@ func ExampleProtocolVersion() { } // Output: // Connector client protocol version: 6 - // Connector client protocol feature: StreamsFeature - // Connector client protocol feature: TransactionsFeature - // Connector client protocol feature: ErrorExtensionFeature - // Connector client protocol feature: WatchersFeature - // Connector client protocol feature: PaginationFeature - // Connector client protocol feature: WatchOnceFeature + // Connector client protocol feature: IPROTO_FEATURE_STREAMS + // Connector client protocol feature: IPROTO_FEATURE_TRANSACTIONS + // Connector client protocol feature: IPROTO_FEATURE_ERROR_EXTENSION + // Connector client protocol feature: IPROTO_FEATURE_WATCHERS + // Connector client protocol feature: IPROTO_FEATURE_PAGINATION + // Connector client protocol feature: IPROTO_FEATURE_WATCH_ONCE } func getTestTxnOpts() tarantool.Opts { @@ -641,9 +643,9 @@ func getTestTxnOpts() tarantool.Opts { // Assert that server supports expected protocol features txnOpts.RequiredProtocolInfo = tarantool.ProtocolInfo{ Version: tarantool.ProtocolVersion(1), - Features: []tarantool.ProtocolFeature{ - tarantool.StreamsFeature, - tarantool.TransactionsFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, }, } @@ -1168,7 +1170,7 @@ func ExampleConnection_NewWatcher() { Pass: "test", // You need to require the feature to create a watcher. RequiredProtocolInfo: tarantool.ProtocolInfo{ - Features: []tarantool.ProtocolFeature{tarantool.WatchersFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_WATCHERS}, }, } ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) diff --git a/pool/connection_pool.go b/pool/connection_pool.go index e101b3208..aa84d8c24 100644 --- a/pool/connection_pool.go +++ b/pool/connection_pool.go @@ -17,6 +17,8 @@ import ( "sync" "time" + "github.com/tarantool/go-iproto" + "github.com/tarantool/go-tarantool/v2" ) @@ -911,8 +913,8 @@ func (p *ConnectionPool) NewPrepared(expr string, userMode Mode) (*tarantool.Pre // NewWatcher creates a new Watcher object for the connection pool. // -// You need to require WatchersFeature to use watchers, see examples for the -// function. +// You need to require IPROTO_FEATURE_WATCHERS to use watchers, see examples +// for the function. // // The behavior is same as if Connection.NewWatcher() called for each // connection with a suitable role. @@ -932,14 +934,14 @@ func (p *ConnectionPool) NewWatcher(key string, callback tarantool.WatchCallback, mode Mode) (tarantool.Watcher, error) { watchersRequired := false for _, feature := range p.connOpts.RequiredProtocolInfo.Features { - if tarantool.WatchersFeature == feature { + if iproto.IPROTO_FEATURE_WATCHERS == feature { watchersRequired = true break } } if !watchersRequired { - return nil, errors.New("the feature WatchersFeature must be " + - "required by connection options to create a watcher") + return nil, errors.New("the feature IPROTO_FEATURE_WATCHERS must " + + "be required by connection options to create a watcher") } watcher := &poolWatcher{ diff --git a/pool/connection_pool_test.go b/pool/connection_pool_test.go index b944d0c6c..27310be23 100644 --- a/pool/connection_pool_test.go +++ b/pool/connection_pool_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" "github.com/vmihailenco/msgpack/v5" "github.com/tarantool/go-tarantool/v2" @@ -2832,7 +2833,7 @@ func TestConnectionPool_NewWatcher_noWatchersFeature(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{} + opts.RequiredProtocolInfo.Features = []iproto.Feature{} err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") @@ -2847,8 +2848,8 @@ func TestConnectionPool_NewWatcher_noWatchersFeature(t *testing.T) { func(event tarantool.WatchEvent) {}, pool.ANY) require.Nilf(t, watcher, "watcher must not be created") require.NotNilf(t, err, "an error is expected") - expected := "the feature WatchersFeature must be required by connection " + - "options to create a watcher" + expected := "the feature IPROTO_FEATURE_WATCHERS must be required by " + + "connection options to create a watcher" require.Equal(t, expected, err.Error()) } @@ -2860,8 +2861,8 @@ func TestConnectionPool_NewWatcher_modes(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") @@ -2941,8 +2942,8 @@ func TestConnectionPool_NewWatcher_update(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") @@ -3030,8 +3031,8 @@ func TestWatcher_Unregister(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") @@ -3091,8 +3092,8 @@ func TestConnectionPool_NewWatcher_concurrent(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") @@ -3133,8 +3134,8 @@ func TestWatcher_Unregister_concurrent(t *testing.T) { roles := []bool{true, false, false, true, true} opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } err := test_helpers.SetClusterRO(servers, opts, roles) require.Nilf(t, err, "fail to set roles for cluster") diff --git a/pool/example_test.go b/pool/example_test.go index dae28de90..a38ae2831 100644 --- a/pool/example_test.go +++ b/pool/example_test.go @@ -2,8 +2,11 @@ package pool_test import ( "fmt" + "strings" "time" + "github.com/tarantool/go-iproto" + "github.com/tarantool/go-tarantool/v2" "github.com/tarantool/go-tarantool/v2/pool" "github.com/tarantool/go-tarantool/v2/test_helpers" @@ -92,8 +95,8 @@ func ExampleConnectionPool_NewWatcher() { const value = "bar" opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{ - tarantool.WatchersFeature, + opts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } connPool, err := examplePool(testRoles, connOpts) @@ -123,7 +126,7 @@ func ExampleConnectionPool_NewWatcher_noWatchersFeature() { const key = "foo" opts := connOpts.Clone() - opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{} + opts.RequiredProtocolInfo.Features = []iproto.Feature{} connPool, err := examplePool(testRoles, connOpts) if err != nil { @@ -134,10 +137,19 @@ func ExampleConnectionPool_NewWatcher_noWatchersFeature() { callback := func(event tarantool.WatchEvent) {} watcher, err := connPool.NewWatcher(key, callback, pool.ANY) fmt.Println(watcher) - fmt.Println(err) + if err != nil { + // Need to split the error message into two lines to pass + // golangci-lint. + str := err.Error() + fmt.Println(strings.Trim(str[:56], " ")) + fmt.Println(str[56:]) + } else { + fmt.Println(err) + } // Output: // - // the feature WatchersFeature must be required by connection options to create a watcher + // the feature IPROTO_FEATURE_WATCHERS must be required by + // connection options to create a watcher } func getTestTxnOpts() tarantool.Opts { @@ -146,9 +158,9 @@ func getTestTxnOpts() tarantool.Opts { // Assert that server supports expected protocol features txnOpts.RequiredProtocolInfo = tarantool.ProtocolInfo{ Version: tarantool.ProtocolVersion(1), - Features: []tarantool.ProtocolFeature{ - tarantool.StreamsFeature, - tarantool.TransactionsFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, }, } diff --git a/protocol.go b/protocol.go index b947c6cbb..7de8b197e 100644 --- a/protocol.go +++ b/protocol.go @@ -2,7 +2,6 @@ package tarantool import ( "context" - "fmt" "github.com/tarantool/go-iproto" "github.com/vmihailenco/msgpack/v5" @@ -11,9 +10,6 @@ import ( // ProtocolVersion type stores Tarantool protocol version. type ProtocolVersion uint64 -// ProtocolVersion type stores a Tarantool protocol feature. -type ProtocolFeature iproto.Feature - // ProtocolInfo type aggregates Tarantool protocol version and features info. type ProtocolInfo struct { // Auth is an authentication method. @@ -21,7 +17,7 @@ type ProtocolInfo struct { // Version is the supported protocol version. Version ProtocolVersion // Features are supported protocol features. - Features []ProtocolFeature + Features []iproto.Feature } // Clone returns an exact copy of the ProtocolInfo object. @@ -30,53 +26,13 @@ func (info ProtocolInfo) Clone() ProtocolInfo { infoCopy := info if info.Features != nil { - infoCopy.Features = make([]ProtocolFeature, len(info.Features)) + infoCopy.Features = make([]iproto.Feature, len(info.Features)) copy(infoCopy.Features, info.Features) } return infoCopy } -const ( - // StreamsFeature represents streams support (supported by connector). - StreamsFeature ProtocolFeature = 0 - // TransactionsFeature represents interactive transactions support. - // (supported by connector). - TransactionsFeature ProtocolFeature = 1 - // ErrorExtensionFeature represents support of MP_ERROR objects over MessagePack - // (supported by connector). - ErrorExtensionFeature ProtocolFeature = 2 - // WatchersFeature represents support of watchers - // (supported by connector). - WatchersFeature ProtocolFeature = 3 - // PaginationFeature represents support of pagination - // (supported by connector). - PaginationFeature ProtocolFeature = 4 - // WatchOnceFeature represents support of WatchOnce request types. - WatchOnceFeature ProtocolFeature = 6 -) - -// String returns the name of a Tarantool feature. -// If value X is not a known feature, returns "Unknown feature (code X)" string. -func (ftr ProtocolFeature) String() string { - switch ftr { - case StreamsFeature: - return "StreamsFeature" - case TransactionsFeature: - return "TransactionsFeature" - case ErrorExtensionFeature: - return "ErrorExtensionFeature" - case WatchersFeature: - return "WatchersFeature" - case PaginationFeature: - return "PaginationFeature" - case WatchOnceFeature: - return "WatchOnceFeature" - default: - return fmt.Sprintf("Unknown feature (code %d)", ftr) - } -} - var clientProtocolInfo ProtocolInfo = ProtocolInfo{ // Protocol version supported by connector. Version 3 // was introduced in Tarantool 2.10.0, version 4 was @@ -94,13 +50,13 @@ var clientProtocolInfo ProtocolInfo = ProtocolInfo{ // connector since 1.11.0. // WatchOnce request type was introduces in protocol version 6 // (Tarantool 3.0.0), in connector since 2.0.0. - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, - PaginationFeature, - WatchOnceFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, + iproto.IPROTO_FEATURE_PAGINATION, + iproto.IPROTO_FEATURE_WATCH_ONCE, }, } diff --git a/protocol_test.go b/protocol_test.go index 2ec4b0bc3..81ed2d3b5 100644 --- a/protocol_test.go +++ b/protocol_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" . "github.com/tarantool/go-tarantool/v2" ) @@ -11,28 +12,17 @@ import ( func TestProtocolInfoClonePreservesFeatures(t *testing.T) { original := ProtocolInfo{ Version: ProtocolVersion(100), - Features: []ProtocolFeature{ProtocolFeature(99), ProtocolFeature(100)}, + Features: []iproto.Feature{iproto.Feature(99), iproto.Feature(100)}, } origCopy := original.Clone() - original.Features[1] = ProtocolFeature(98) + original.Features[1] = iproto.Feature(98) require.Equal(t, origCopy, ProtocolInfo{ Version: ProtocolVersion(100), - Features: []ProtocolFeature{ProtocolFeature(99), ProtocolFeature(100)}, + Features: []iproto.Feature{iproto.Feature(99), iproto.Feature(100)}, }) } - -func TestFeatureStringRepresentation(t *testing.T) { - require.Equal(t, StreamsFeature.String(), "StreamsFeature") - require.Equal(t, TransactionsFeature.String(), "TransactionsFeature") - require.Equal(t, ErrorExtensionFeature.String(), "ErrorExtensionFeature") - require.Equal(t, WatchersFeature.String(), "WatchersFeature") - require.Equal(t, PaginationFeature.String(), "PaginationFeature") - require.Equal(t, WatchOnceFeature.String(), "WatchOnceFeature") - - require.Equal(t, ProtocolFeature(15532).String(), "Unknown feature (code 15532)") -} diff --git a/request_test.go b/request_test.go index da825b707..6d08533d3 100644 --- a/request_test.go +++ b/request_test.go @@ -35,7 +35,7 @@ var validStmt *Prepared = &Prepared{StatementID: 1, Conn: &Connection{}} var validProtocolInfo ProtocolInfo = ProtocolInfo{ Version: ProtocolVersion(3), - Features: []ProtocolFeature{StreamsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS}, } type ValidSchemeResolver struct { diff --git a/response.go b/response.go index 7ee314e04..0d6d062b8 100644 --- a/response.go +++ b/response.go @@ -156,7 +156,7 @@ func (resp *Response) decodeBody() (err error) { var l, larr int var stmtID, bindCount uint64 var serverProtocolInfo ProtocolInfo - var feature ProtocolFeature + var feature iproto.Feature var errorExtendedInfo *BoxError = nil d := msgpack.NewDecoder(&resp.buf) @@ -215,7 +215,7 @@ func (resp *Response) decodeBody() (err error) { return err } - serverProtocolInfo.Features = make([]ProtocolFeature, larr) + serverProtocolInfo.Features = make([]iproto.Feature, larr) for i := 0; i < larr; i++ { if err = d.Decode(&feature); err != nil { return err diff --git a/shutdown_test.go b/shutdown_test.go index 412d27ea4..cf4894344 100644 --- a/shutdown_test.go +++ b/shutdown_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" . "github.com/tarantool/go-tarantool/v2" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -25,7 +26,7 @@ var shtdnClntOpts = Opts{ Timeout: 20 * time.Second, Reconnect: 500 * time.Millisecond, MaxReconnects: 10, - RequiredProtocolInfo: ProtocolInfo{Features: []ProtocolFeature{WatchersFeature}}, + RequiredProtocolInfo: ProtocolInfo{Features: []iproto.Feature{iproto.IPROTO_FEATURE_WATCHERS}}, } var shtdnSrvOpts = test_helpers.StartOpts{ InitScript: "config.lua", diff --git a/tarantool_test.go b/tarantool_test.go index fc5788f23..0ad365286 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -3273,20 +3273,21 @@ func TestConnectionProtocolInfoSupported(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, server, opts) defer conn.Close() - // First Tarantool protocol version (1, StreamsFeature and TransactionsFeature) - // was introduced between 2.10.0-beta1 and 2.10.0-beta2. - // Versions 2 (ErrorExtensionFeature) and 3 (WatchersFeature) were also - // introduced between 2.10.0-beta1 and 2.10.0-beta2. Version 4 - // (PaginationFeature) was introduced in master 948e5cd (possible 2.10.5 or - // 2.11.0). So each release Tarantool >= 2.10 (same as each Tarantool with - // id support) has protocol version >= 3 and first four features. + // First Tarantool protocol version (1, IPROTO_FEATURE_STREAMS and + // IPROTO_FEATURE_TRANSACTIONS) was introduced between 2.10.0-beta1 and + // 2.10.0-beta2. Versions 2 (IPROTO_FEATURE_ERROR_EXTENSION) and + // 3 (IPROTO_FEATURE_WATCHERS) were also introduced between 2.10.0-beta1 and + // 2.10.0-beta2. Version 4 (IPROTO_FEATURE_PAGINATION) was introduced in + // master 948e5cd (possible 2.10.5 or 2.11.0). So each release + // Tarantool >= 2.10 (same as each Tarantool with id support) has protocol + // version >= 3 and first four features. tarantool210ProtocolInfo := ProtocolInfo{ Version: ProtocolVersion(3), - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, }, } @@ -3295,13 +3296,13 @@ func TestConnectionProtocolInfoSupported(t *testing.T) { clientProtocolInfo, ProtocolInfo{ Version: ProtocolVersion(6), - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, - PaginationFeature, - WatchOnceFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, + iproto.IPROTO_FEATURE_PAGINATION, + iproto.IPROTO_FEATURE_WATCH_ONCE, }, }) @@ -3322,17 +3323,17 @@ func TestClientIdRequestObject(t *testing.T) { tarantool210ProtocolInfo := ProtocolInfo{ Version: ProtocolVersion(3), - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, }, } req := NewIdRequest(ProtocolInfo{ Version: ProtocolVersion(1), - Features: []ProtocolFeature{StreamsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS}, }) resp, err := conn.Do(req).Get() require.Nilf(t, err, "No errors on Id request execution") @@ -3358,17 +3359,17 @@ func TestClientIdRequestObjectWithNilContext(t *testing.T) { tarantool210ProtocolInfo := ProtocolInfo{ Version: ProtocolVersion(3), - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, }, } req := NewIdRequest(ProtocolInfo{ Version: ProtocolVersion(1), - Features: []ProtocolFeature{StreamsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS}, }).Context(nil) //nolint resp, err := conn.Do(req).Get() require.Nilf(t, err, "No errors on Id request execution") @@ -3393,7 +3394,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) req := NewIdRequest(ProtocolInfo{ Version: ProtocolVersion(1), - Features: []ProtocolFeature{StreamsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS}, }).Context(ctx) //nolint cancel() resp, err := conn.Do(req).Get() @@ -3413,13 +3414,13 @@ func TestConnectionProtocolInfoUnsupported(t *testing.T) { clientProtocolInfo, ProtocolInfo{ Version: ProtocolVersion(6), - Features: []ProtocolFeature{ - StreamsFeature, - TransactionsFeature, - ErrorExtensionFeature, - WatchersFeature, - PaginationFeature, - WatchOnceFeature, + Features: []iproto.Feature{ + iproto.IPROTO_FEATURE_STREAMS, + iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.IPROTO_FEATURE_ERROR_EXTENSION, + iproto.IPROTO_FEATURE_WATCHERS, + iproto.IPROTO_FEATURE_PAGINATION, + iproto.IPROTO_FEATURE_WATCH_ONCE, }, }) @@ -3433,7 +3434,7 @@ func TestConnectionClientFeaturesUmmutable(t *testing.T) { info := conn.ClientProtocolInfo() infoOrig := info.Clone() - info.Features[0] = ProtocolFeature(15532) + info.Features[0] = iproto.Feature(15532) require.Equal(t, conn.ClientProtocolInfo(), infoOrig) require.NotEqual(t, conn.ClientProtocolInfo(), info) @@ -3447,7 +3448,7 @@ func TestConnectionServerFeaturesUmmutable(t *testing.T) { info := conn.ServerProtocolInfo() infoOrig := info.Clone() - info.Features[0] = ProtocolFeature(15532) + info.Features[0] = iproto.Feature(15532) require.Equal(t, conn.ServerProtocolInfo(), infoOrig) require.NotEqual(t, conn.ServerProtocolInfo(), info) @@ -3493,7 +3494,7 @@ func TestConnectionProtocolFeatureRequirementSuccess(t *testing.T) { connOpts := opts.Clone() connOpts.RequiredProtocolInfo = ProtocolInfo{ - Features: []ProtocolFeature{TransactionsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_TRANSACTIONS}, } ctx, cancel := test_helpers.GetConnectContext() @@ -3511,7 +3512,7 @@ func TestConnectionProtocolFeatureRequirementFail(t *testing.T) { connOpts := opts.Clone() connOpts.RequiredProtocolInfo = ProtocolInfo{ - Features: []ProtocolFeature{TransactionsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_TRANSACTIONS}, } ctx, cancel := test_helpers.GetConnectContext() @@ -3521,7 +3522,8 @@ func TestConnectionProtocolFeatureRequirementFail(t *testing.T) { require.Nilf(t, conn, "Connect fail") require.NotNilf(t, err, "Got error on connect") require.Contains(t, err.Error(), - "invalid server protocol: protocol feature TransactionsFeature is not supported") + "invalid server protocol: protocol feature "+ + "IPROTO_FEATURE_TRANSACTIONS is not supported") } func TestConnectionProtocolFeatureRequirementManyFail(t *testing.T) { @@ -3529,7 +3531,8 @@ func TestConnectionProtocolFeatureRequirementManyFail(t *testing.T) { connOpts := opts.Clone() connOpts.RequiredProtocolInfo = ProtocolInfo{ - Features: []ProtocolFeature{TransactionsFeature, ProtocolFeature(15532)}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_TRANSACTIONS, + iproto.Feature(15532)}, } ctx, cancel := test_helpers.GetConnectContext() @@ -3540,8 +3543,8 @@ func TestConnectionProtocolFeatureRequirementManyFail(t *testing.T) { require.NotNilf(t, err, "Got error on connect") require.Contains(t, err.Error(), - "invalid server protocol: protocol features TransactionsFeature, "+ - "Unknown feature (code 15532) are not supported") + "invalid server protocol: protocol features IPROTO_FEATURE_TRANSACTIONS, "+ + "Feature(15532) are not supported") } func TestConnectionFeatureOptsImmutable(t *testing.T) { @@ -3564,7 +3567,7 @@ func TestConnectionFeatureOptsImmutable(t *testing.T) { connOpts.Reconnect = timeout connOpts.MaxReconnects = retries connOpts.RequiredProtocolInfo = ProtocolInfo{ - Features: []ProtocolFeature{TransactionsFeature}, + Features: []iproto.Feature{iproto.IPROTO_FEATURE_TRANSACTIONS}, } // Connect with valid opts @@ -3572,7 +3575,7 @@ func TestConnectionFeatureOptsImmutable(t *testing.T) { defer conn.Close() // Change opts outside - connOpts.RequiredProtocolInfo.Features[0] = ProtocolFeature(15532) + connOpts.RequiredProtocolInfo.Features[0] = iproto.Feature(15532) // Trigger reconnect with opts re-check test_helpers.StopTarantool(inst) @@ -3685,8 +3688,8 @@ func TestConnection_NewWatcher(t *testing.T) { const key = "TestConnection_NewWatcher" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -3721,15 +3724,15 @@ func TestConnection_NewWatcher(t *testing.T) { func TestConnection_NewWatcher_noWatchersFeature(t *testing.T) { const key = "TestConnection_NewWatcher_noWatchersFeature" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{} + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{} conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() watcher, err := conn.NewWatcher(key, func(event WatchEvent) {}) require.Nilf(t, watcher, "watcher must not be created") require.NotNilf(t, err, "an error is expected") - expected := "the feature WatchersFeature must be required by connection " + - "options to create a watcher" + expected := "the feature IPROTO_FEATURE_WATCHERS must be required by " + + "connection options to create a watcher" require.Equal(t, expected, err.Error()) } @@ -3756,8 +3759,8 @@ func TestConnection_NewWatcher_reconnect(t *testing.T) { reconnectOpts := opts reconnectOpts.Reconnect = 100 * time.Millisecond reconnectOpts.MaxReconnects = 10 - reconnectOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + reconnectOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, reconnectOpts) defer conn.Close() @@ -3794,8 +3797,8 @@ func TestBroadcastRequest(t *testing.T) { const value = "bar" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -3844,8 +3847,8 @@ func TestBroadcastRequest_multi(t *testing.T) { const key = "TestBroadcastRequest_multi" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -3892,8 +3895,8 @@ func TestConnection_NewWatcher_multiOnKey(t *testing.T) { const value = "bar" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -3955,8 +3958,8 @@ func TestWatcher_Unregister(t *testing.T) { const value = "bar" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -3991,8 +3994,8 @@ func TestConnection_NewWatcher_concurrent(t *testing.T) { const testConcurrency = 1000 const key = "TestConnection_NewWatcher_concurrent" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close() @@ -4036,8 +4039,8 @@ func TestWatcher_Unregister_concurrent(t *testing.T) { const testConcurrency = 1000 const key = "TestWatcher_Unregister_concurrent" connOpts := opts.Clone() - connOpts.RequiredProtocolInfo.Features = []ProtocolFeature{ - WatchersFeature, + connOpts.RequiredProtocolInfo.Features = []iproto.Feature{ + iproto.IPROTO_FEATURE_WATCHERS, } conn := test_helpers.ConnectWithValidation(t, server, connOpts) defer conn.Close()