diff --git a/tests/gocase/unit/config/config_test.go b/tests/gocase/unit/config/config_test.go index 0c434e72c55..c43b7da91d7 100644 --- a/tests/gocase/unit/config/config_test.go +++ b/tests/gocase/unit/config/config_test.go @@ -275,3 +275,48 @@ func TestChangeProtoMaxBulkLen(t *testing.T) { // Must be >= 1MB require.Error(t, rdb.ConfigSet(ctx, "proto-max-bulk-len", "1024").Err()) } + +func TestGetConfigTxnContext(t *testing.T) { + srv := util.StartServer(t, map[string]string{ + "txn-context-enabled": "yes", + }) + defer srv.Close() + + ctx := context.Background() + rdb := srv.NewClient() + defer func() { require.NoError(t, rdb.Close()) }() + val := rdb.ConfigGet(ctx, "txn-context-enabled").Val() + require.EqualValues(t, "yes", val["txn-context-enabled"]) + + // default value "no" + srv1 := util.StartServer(t, map[string]string{}) + defer srv1.Close() + + rdb = srv1.NewClient() + val = rdb.ConfigGet(ctx, "txn-context-enabled").Val() + require.EqualValues(t, "no", val["txn-context-enabled"]) +} + +func TestGenerateConfigsMatrix(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + + require.NoError(t, err) + require.Equal(t, 4, len(configsMatrix)) + require.Contains(t, configsMatrix, util.KvrocksServerConfigs{"txn-context-enabled": "yes", "resp3-enabled": "yes"}) + require.Contains(t, configsMatrix, util.KvrocksServerConfigs{"txn-context-enabled": "yes", "resp3-enabled": "no"}) + require.Contains(t, configsMatrix, util.KvrocksServerConfigs{"txn-context-enabled": "no", "resp3-enabled": "yes"}) + require.Contains(t, configsMatrix, util.KvrocksServerConfigs{"txn-context-enabled": "no", "resp3-enabled": "no"}) +} diff --git a/tests/gocase/unit/geo/geo_test.go b/tests/gocase/unit/geo/geo_test.go index a920ddabbce..6d474d645ba 100644 --- a/tests/gocase/unit/geo/geo_test.go +++ b/tests/gocase/unit/geo/geo_test.go @@ -87,18 +87,30 @@ func compareLists(list1, list2 []string) []string { return result } -func TestGeoWithRESP2(t *testing.T) { - testGeo(t, "no") -} +func TestGeo(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestGeoWithRESP3(t *testing.T) { - testGeo(t, "yes") + for _, configs := range configsMatrix { + testGeo(t, configs) + } } -var testGeo = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var testGeo = func(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/pubsub/pubsub_test.go b/tests/gocase/unit/pubsub/pubsub_test.go index bf4d655a726..6c398757e75 100644 --- a/tests/gocase/unit/pubsub/pubsub_test.go +++ b/tests/gocase/unit/pubsub/pubsub_test.go @@ -36,18 +36,30 @@ func receiveType[T any](t *testing.T, pubsub *redis.PubSub, typ T) T { return msg.(T) } -func TestPubSubWithRESP2(t *testing.T) { - testPubSub(t, "no") -} +func TestPubSub(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestPubSubWithRESP3(t *testing.T) { - testPubSub(t, "yes") + for _, configs := range configsMatrix { + testPubSub(t, configs) + } } -func testPubSub(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +func testPubSub(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() diff --git a/tests/gocase/unit/scripting/function_test.go b/tests/gocase/unit/scripting/function_test.go index 8d71158498a..9ab7eff04d4 100644 --- a/tests/gocase/unit/scripting/function_test.go +++ b/tests/gocase/unit/scripting/function_test.go @@ -97,18 +97,30 @@ func decodeListLibResult(t *testing.T, v interface{}) ListLibResult { return ListLibResult{} } -func TestFunctionsWithRESP3(t *testing.T) { - testFunctions(t, "yes") -} +func TestFunctions(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestFunctionsWithoutRESP2(t *testing.T) { - testFunctions(t, "no") + for _, configs := range configsMatrix { + testFunctions(t, configs) + } } -var testFunctions = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var testFunctions = func(t *testing.T, config util.KvrocksServerConfigs) { + srv := util.StartServer(t, config) defer srv.Close() ctx := context.Background() diff --git a/tests/gocase/unit/type/bloom/bloom_test.go b/tests/gocase/unit/type/bloom/bloom_test.go index ebfd952e08f..13009afd493 100644 --- a/tests/gocase/unit/type/bloom/bloom_test.go +++ b/tests/gocase/unit/type/bloom/bloom_test.go @@ -29,8 +29,24 @@ import ( "github.com/stretchr/testify/require" ) -func TestBloom(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) +func TestBloomInfo(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testBloom(t, configs) + } +} +func testBloom(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/hash/hash_test.go b/tests/gocase/unit/type/hash/hash_test.go index 3c769649295..caab802af77 100644 --- a/tests/gocase/unit/type/hash/hash_test.go +++ b/tests/gocase/unit/type/hash/hash_test.go @@ -50,18 +50,30 @@ func getVals(hash map[string]string) []string { return r } -func TestHashWithRESP2(t *testing.T) { - testHash(t, "no") -} +func TestHash(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestHashWithRESP3(t *testing.T) { - testHash(t, "yes") + for _, configs := range configsMatrix { + testHash(t, configs) + } } -var testHash = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var testHash = func(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/incr/incr_test.go b/tests/gocase/unit/type/incr/incr_test.go index a90f9e1d66d..f8a1785cfb1 100644 --- a/tests/gocase/unit/type/incr/incr_test.go +++ b/tests/gocase/unit/type/incr/incr_test.go @@ -28,7 +28,24 @@ import ( ) func TestIncr(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testIncr(t, configs) + } +} + +func testIncr(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/json/json_test.go b/tests/gocase/unit/type/json/json_test.go index a5e02dba80b..b943a32a714 100644 --- a/tests/gocase/unit/type/json/json_test.go +++ b/tests/gocase/unit/type/json/json_test.go @@ -30,7 +30,23 @@ import ( ) func TestJson(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testJSON(t, configs) + } +} +func testJSON(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/list/list_test.go b/tests/gocase/unit/type/list/list_test.go index 79f7b360bfa..8b7a2c58f4e 100644 --- a/tests/gocase/unit/type/list/list_test.go +++ b/tests/gocase/unit/type/list/list_test.go @@ -42,7 +42,24 @@ var largeValue = map[string]string{ } func TestLTRIM(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testLTRIM(t, configs) + } +} + +func testLTRIM(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() @@ -85,7 +102,24 @@ func TestLTRIM(t *testing.T) { } func TestZipList(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testZipList(t, configs) + } +} + +func testZipList(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClientWithOption(&redis.Options{ @@ -233,7 +267,29 @@ func TestZipList(t *testing.T) { } func TestList(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testList(t, configs) + } +} + +func testList(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/set/set_test.go b/tests/gocase/unit/type/set/set_test.go index 0d596620936..3c910513f02 100644 --- a/tests/gocase/unit/type/set/set_test.go +++ b/tests/gocase/unit/type/set/set_test.go @@ -57,17 +57,29 @@ func GetArrayUnion(arrays ...[]string) []string { } func TestSet(t *testing.T) { - setTests(t, "no") -} + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestSetWithRESP3(t *testing.T) { - setTests(t, "yes") + for _, configs := range configsMatrix { + setTests(t, configs) + } } -var setTests = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var setTests = func(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/sint/sint_test.go b/tests/gocase/unit/type/sint/sint_test.go index aa45859f33c..4b4f0cb35bc 100644 --- a/tests/gocase/unit/type/sint/sint_test.go +++ b/tests/gocase/unit/type/sint/sint_test.go @@ -27,8 +27,25 @@ import ( "github.com/stretchr/testify/require" ) -func TestSint(t *testing.T) { - srv := util.StartServer(t, map[string]string{}) +func TestString(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testSint(t, configs) + } +} + +func testSint(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/stream/stream_test.go b/tests/gocase/unit/type/stream/stream_test.go index 8ff7a503c3f..943127fcaaa 100644 --- a/tests/gocase/unit/type/stream/stream_test.go +++ b/tests/gocase/unit/type/stream/stream_test.go @@ -34,18 +34,30 @@ import ( "github.com/stretchr/testify/require" ) -func TestStreamWithRESP2(t *testing.T) { - streamTests(t, "no") -} +func TestStream(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } -func TestStreamWithRESP3(t *testing.T) { - streamTests(t, "yes") + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + streamTests(t, configs) + } } -var streamTests = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var streamTests = func(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() diff --git a/tests/gocase/unit/type/strings/strings_test.go b/tests/gocase/unit/type/strings/strings_test.go index 49963d0b559..e5938182b8c 100644 --- a/tests/gocase/unit/type/strings/strings_test.go +++ b/tests/gocase/unit/type/strings/strings_test.go @@ -35,6 +35,22 @@ import ( ) func TestString(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) + + for _, configs := range configsMatrix { + testString(t, configs) + } +} +func testString(t *testing.T, configs util.KvrocksServerConfigs) { srv := util.StartServer(t, map[string]string{}) defer srv.Close() ctx := context.Background() diff --git a/tests/gocase/unit/type/zset/zset_test.go b/tests/gocase/unit/type/zset/zset_test.go index 20441b5b17e..ad57defaa85 100644 --- a/tests/gocase/unit/type/zset/zset_test.go +++ b/tests/gocase/unit/type/zset/zset_test.go @@ -1907,24 +1907,36 @@ func stressTests(t *testing.T, rdb *redis.Client, ctx context.Context, encoding }) } -func TestZSetWithRESP2(t *testing.T) { - testZSet(t, "no") -} +func TestZSet(t *testing.T) { + configOptions := []util.ConfigOptions{ + { + Name: "txn-context-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + { + Name: "resp3-enabled", + Options: []string{"yes", "no"}, + ConfigType: util.YesNo, + }, + } + + configsMatrix, err := util.GenerateConfigsMatrix(configOptions) + require.NoError(t, err) -func TestZSetWithRESP3(t *testing.T) { - testZSet(t, "yes") + for _, configs := range configsMatrix { + testZSet(t, configs) + } } -var testZSet = func(t *testing.T, enabledRESP3 string) { - srv := util.StartServer(t, map[string]string{ - "resp3-enabled": enabledRESP3, - }) +var testZSet = func(t *testing.T, configs util.KvrocksServerConfigs) { + srv := util.StartServer(t, configs) defer srv.Close() ctx := context.Background() rdb := srv.NewClient() defer func() { require.NoError(t, rdb.Close()) }() - basicTests(t, rdb, ctx, enabledRESP3, "skiplist", srv) + basicTests(t, rdb, ctx, configs["resp3-enabled"], "skiplist", srv) t.Run("ZUNIONSTORE regression, should not create NaN in scores", func(t *testing.T) { rdb.ZAdd(ctx, "z", redis.Z{Score: math.Inf(-1), Member: "neginf"}) diff --git a/tests/gocase/util/configs.go b/tests/gocase/util/configs.go new file mode 100644 index 00000000000..c575f25a8cc --- /dev/null +++ b/tests/gocase/util/configs.go @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package util + +import "fmt" + +type FieldType int + +const ( + YesNo FieldType = iota +) + +type ConfigOptions struct { + Name string + Options []string + ConfigType FieldType +} + +type KvrocksServerConfigs map[string]string + +func verifyConfigOptions(configType FieldType, option string) error { + switch configType { + case YesNo: + if option == "yes" || option == "no" { + break + } + return fmt.Errorf("invalid option for yes/no config") + default: + return fmt.Errorf("unsupported config type") + } + return nil +} + +// / GenerateConfigsMatrix generates all possible combinations of config options +func GenerateConfigsMatrix(configOptions []ConfigOptions) ([]KvrocksServerConfigs, error) { + configsMatrix := make([]KvrocksServerConfigs, 0) + + var helper func(configs []ConfigOptions, index int, currentConfig map[string]string) error + + helper = func(configs []ConfigOptions, currentIndex int, currentConfig map[string]string) error { + if currentIndex == len(configOptions) { + configsMatrix = append(configsMatrix, currentConfig) + return nil + } + + currentConfigBackup := make(KvrocksServerConfigs, len(currentConfig)) + for k, v := range currentConfig { + currentConfigBackup[k] = v + } + + for _, option := range configs[currentIndex].Options { + err := verifyConfigOptions(configs[currentIndex].ConfigType, option) + if err != nil { + return err + } + + currentConfig[configs[currentIndex].Name] = option + err = helper(configs, currentIndex+1, currentConfig) + if err != nil { + return err + } + currentConfig = currentConfigBackup + } + + return nil + } + + err := helper(configOptions, 0, make(KvrocksServerConfigs, 0)) + + return configsMatrix, err +}