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 1 commit
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
14 changes: 12 additions & 2 deletions tests/tnt/concurrent_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ func TestConncurrentTopologyChange(t *testing.T) {
return
}

t.Parallel()
// suppress the below linter warning:
// unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
_ = t
osperelygin marked this conversation as resolved.
Show resolved Hide resolved

// 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 Down Expand Up @@ -151,7 +157,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
52 changes: 52 additions & 0 deletions tests/tnt/router_call_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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,
})

if err != nil {
panic(err)
KaymeKaydex marked this conversation as resolved.
Show resolved Hide resolved
}

//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")
}
2 changes: 2 additions & 0 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 Down
Loading