diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d73e36..723ce9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ REFACTOR: * resolve issue #38: simplify DiscoveryAllBuckets and remove suspicious if * resolve issue #46: drastically simplify RouterMapCallRWImpl and added tests with real tnt * Use typed nil pointers instead of memory allocation for EmptyMetrics and emptyLogger structs +* New test for RouterCallImpl (and fix the old one) EXAMPLES: * customer go mod fixed diff --git a/tests/tnt/Makefile b/tests/tnt/Makefile index 8e82e1b..b6b32d1 100644 --- a/tests/tnt/Makefile +++ b/tests/tnt/Makefile @@ -1,5 +1,6 @@ -NREPLICASETS?=5 -START_PORT?=33000 +export NREPLICASETS:=5 +export START_PORT:=33000 +export OBJC_DISABLE_INITIALIZE_FORK_SAFETY:=YES # See review comments for PR #56 why RED=\033[0;31m GREEN=\033[0;32m @@ -19,7 +20,7 @@ clean: # prepare vshard-storages, that contains ${NREPLICASETS} replicasets. # every replicaset has one master and one follower instance. -# every replicaset runs in background mode, no logs are stored (/dev/null) +# every replicaset runs in background mode cluster-up: @echo "${GREEN}STAGE: CLUSTER UP${NC}" mkdir -p tmp @@ -30,16 +31,16 @@ cluster-up: ln -sf `(pwd)`/cfgmaker.lua tmp/$${rsid}/master/cfgmaker.lua; \ ln -sf `(pwd)`/storage.lua tmp/$${rsid}/follower/storage_$${rsid}_follower.lua; \ ln -sf `(pwd)`/cfgmaker.lua tmp/$${rsid}/follower/cfgmaker.lua; \ - TT_WORK_DIR=tmp/$${rsid}/master/ TT_PID_FILE="tarantool.pid" TT_BACKGROUND=true START_PORT=${START_PORT} TT_LOG=/dev/null NREPLICASETS=${NREPLICASETS} tarantool tmp/$${rsid}/master/storage_$${rsid}_master.lua; \ - TT_WORK_DIR=tmp/$${rsid}/follower/ TT_PID_FILE="tarantool.pid" TT_BACKGROUND=true START_PORT=${START_PORT} TT_LOG=/dev/null NREPLICASETS=${NREPLICASETS} tarantool tmp/$${rsid}/follower/storage_$${rsid}_follower.lua; \ + TT_WORK_DIR=tmp/$${rsid}/master/ TT_PID_FILE=tarantool.pid TT_BACKGROUND=true TT_LOG=tarantool.log tarantool tmp/$${rsid}/master/storage_$${rsid}_master.lua; \ + TT_WORK_DIR=tmp/$${rsid}/follower/ TT_PID_FILE=tarantool.pid TT_BACKGROUND=true TT_LOG=tarantool.log tarantool tmp/$${rsid}/follower/storage_$${rsid}_follower.lua; \ ((rsid = rsid + 1)) ; \ - done + done # bootstrap vshard cluster using lua vshard.router bootstrap: @echo "${GREEN}STAGE: BOOTSTRAP CLUSTER${NC}" mkdir -p tmp/router_work_dir - TT_WORK_DIR=tmp/router_work_dir/ NREPLICASETS=${NREPLICASETS} START_PORT=${START_PORT} tarantool router.lua + TT_WORK_DIR=tmp/router_work_dir/ tarantool router.lua # stop vshard storage tarantool cluster-down: @@ -53,5 +54,5 @@ cluster-down: # run go tests, minus "-" signs before command allows failures, otherwise cluster-down stage won't run. gotest: @echo "${GREEN}STAGE: RUN GOTESTS${NC}" - -NREPLICASETS=${NREPLICASETS} START_PORT=${START_PORT} go test -race -parallel=20 -coverpkg="../../" -coverprofile cover.out -timeout=90s + -go test -race -parallel=20 -coverpkg="../../" -coverprofile cover.out -timeout=90s # go tool cover -html=cover.out diff --git a/tests/tnt/cfgmaker.lua b/tests/tnt/cfgmaker.lua index ec0f434..437bf27 100644 --- a/tests/tnt/cfgmaker.lua +++ b/tests/tnt/cfgmaker.lua @@ -89,7 +89,6 @@ end local function clustercfg(start_port, nreplicasets) local cfg = { sharding = {}, - replication_connect_quorum = 0, } for rs_id = 1, nreplicasets do diff --git a/tests/tnt/concurrent_topology_test.go b/tests/tnt/concurrent_topology_test.go index 3811ea3..972f03f 100644 --- a/tests/tnt/concurrent_topology_test.go +++ b/tests/tnt/concurrent_topology_test.go @@ -10,6 +10,7 @@ import ( "time" vshardrouter "github.com/KaymeKaydex/go-vshard-router" + "github.com/stretchr/testify/require" ) type concurrentTopologyProvider struct { @@ -115,7 +116,9 @@ func TestConncurrentTopologyChange(t *testing.T) { return } - t.Parallel() + // Don't run this parallel with other tests, because this test is heavy and used to detect data races. + // Therefore this test may impact other ones. + // t.Parallel() tc := &concurrentTopologyProvider{} @@ -127,9 +130,8 @@ func TestConncurrentTopologyChange(t *testing.T) { User: defaultTntUser, Password: defaultTntPassword, }) - if err != nil { - panic(err) - } + + require.Nil(t, err, "NewRouter finished successfully") wg := sync.WaitGroup{} @@ -151,7 +153,11 @@ func TestConncurrentTopologyChange(t *testing.T) { bucketID := uint64((rand.Int() % totalBucketCount) + 1) args := []interface{}{"arg1"} - _, _, _ = router.RouterCallImpl(ctx, bucketID, vshardrouter.CallOpts{}, "echo", args) + callOpts := vshardrouter.CallOpts{ + VshardMode: vshardrouter.ReadMode, + } + + _, _, _ = router.RouterCallImpl(ctx, bucketID, callOpts, "echo", args) } }() diff --git a/tests/tnt/router_call_test.go b/tests/tnt/router_call_test.go new file mode 100644 index 0000000..5eccd2d --- /dev/null +++ b/tests/tnt/router_call_test.go @@ -0,0 +1,50 @@ +package tnt_test + +import ( + "context" + "log" + "math/rand" + "testing" + "time" + + vshardrouter "github.com/KaymeKaydex/go-vshard-router" + "github.com/KaymeKaydex/go-vshard-router/providers/static" + "github.com/stretchr/testify/require" + "github.com/tarantool/go-tarantool/v2/pool" +) + +func TestRouterCall(t *testing.T) { + if !isCorrectRun() { + log.Printf("Incorrect run of tnt-test framework") + return + } + + t.Parallel() + + ctx := context.Background() + + cfg := getCfg() + + router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{ + TopologyProvider: static.NewProvider(cfg), + DiscoveryTimeout: 5 * time.Second, + DiscoveryMode: vshardrouter.DiscoveryModeOn, + TotalBucketCount: totalBucketCount, + User: defaultTntUser, + Password: defaultTntPassword, + }) + + require.Nil(t, err, "NewRouter finished successfully") + + //nolint:gosec + bucketID := uint64((rand.Int() % totalBucketCount) + 1) + args := []interface{}{"arg1"} + + resp, _, err := router.RouterCallImpl(ctx, bucketID, vshardrouter.CallOpts{ + VshardMode: vshardrouter.ReadMode, + PoolMode: pool.PreferRO, + }, "echo", args) + + require.Nil(t, err, "RouterCallImpl echo finished with no err") + require.EqualValues(t, args, resp, "RouterCallImpl echo resp correct") +} diff --git a/tests/tnt/routermap_call_test.go b/tests/tnt/routermap_call_test.go index fb06d22..d0bdf3e 100644 --- a/tests/tnt/routermap_call_test.go +++ b/tests/tnt/routermap_call_test.go @@ -17,6 +17,8 @@ func TestRouterMapCall(t *testing.T) { return } + t.Parallel() + ctx := context.Background() cfg := getCfg() @@ -30,9 +32,7 @@ func TestRouterMapCall(t *testing.T) { Password: defaultTntPassword, }) - if err != nil { - panic(err) - } + require.Nil(t, err, "NewRouter finished successfully") const arg = "arg1" diff --git a/tests/tnt/storage.lua b/tests/tnt/storage.lua index 930f735..3587123 100644 --- a/tests/tnt/storage.lua +++ b/tests/tnt/storage.lua @@ -85,6 +85,8 @@ box.once("testapp:schema:1", function() box.schema.role.grant('public', 'execute', 'function', 'raise_luajit_error') box.schema.func.create('raise_client_error') box.schema.role.grant('public', 'execute', 'function', 'raise_client_error') + + box.schema.user.grant('guest', 'super') end)