Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Add tnt test for RouterCallImpl #56

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## 0.0.12

Expand Down
17 changes: 9 additions & 8 deletions tests/tnt/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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; \
osperelygin marked this conversation as resolved.
Show resolved Hide resolved
((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:
Expand All @@ -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
1 change: 0 additions & 1 deletion tests/tnt/cfgmaker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ end
local function clustercfg(start_port, nreplicasets)
local cfg = {
sharding = {},
replication_connect_quorum = 0,
}

for rs_id = 1, nreplicasets do
Expand Down
16 changes: 11 additions & 5 deletions tests/tnt/concurrent_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

vshardrouter "github.com/KaymeKaydex/go-vshard-router"
"github.com/stretchr/testify/require"
)

type concurrentTopologyProvider struct {
Expand Down Expand Up @@ -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{}

Expand All @@ -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{}

Expand All @@ -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)
}
}()

Expand Down
50 changes: 50 additions & 0 deletions tests/tnt/router_call_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
6 changes: 3 additions & 3 deletions tests/tnt/routermap_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestRouterMapCall(t *testing.T) {
return
}

t.Parallel()

ctx := context.Background()

cfg := getCfg()
Expand All @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions tests/tnt/storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading