This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/tests: add more tests and refactor Makefile for race tests (#52)
* feature/tests: add more tests and refactor Makefile for race tests * Makefile refactored for racetests * Tests coverage up * feature/tests: fix lint * feature/tests: fix CHANGELOG * feature/tests: fixes after review --------- Co-authored-by: Maksim Konovalov <maksim.konovalov@vk.team>
- Loading branch information
1 parent
cf02580
commit ea5470b
Showing
9 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package vshard_router // nolint: revive | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
mockpool "github.com/KaymeKaydex/go-vshard-router/mocks/pool" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tarantool/go-tarantool/v2" | ||
) | ||
|
||
var emptyRouter = &Router{ | ||
cfg: Config{ | ||
TotalBucketCount: uint64(10), | ||
Logger: &EmptyLogger{}, | ||
Metrics: &EmptyMetrics{}, | ||
}, | ||
} | ||
|
||
func TestVshardMode_String_NotEmpty(t *testing.T) { | ||
t.Parallel() | ||
require.NotEmpty(t, ReadMode.String()) | ||
require.NotEmpty(t, WriteMode.String()) | ||
} | ||
|
||
func TestRouter_RouterRouteAll(t *testing.T) { | ||
t.Parallel() | ||
m := emptyRouter.RouterRouteAll() | ||
require.Empty(t, m) | ||
} | ||
|
||
func TestRouter_RouterCallImpl(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.TODO() | ||
|
||
t.Run("bucket id is out of range", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, _, err := emptyRouter.RouterCallImpl(ctx, 100, CallOpts{}, "test", []byte("test")) | ||
require.Errorf(t, err, "bucket id is out of range") | ||
}) | ||
t.Run("future error when router call impl", func(t *testing.T) { | ||
t.Parallel() | ||
r := &Router{ | ||
cfg: Config{ | ||
TotalBucketCount: uint64(10), | ||
Logger: &EmptyLogger{}, | ||
Metrics: &EmptyMetrics{}, | ||
}, | ||
routeMap: make([]*Replicaset, 11), | ||
} | ||
|
||
futureError := fmt.Errorf("testErr") | ||
errFuture := tarantool.NewFuture(tarantool.NewCallRequest("test")) | ||
errFuture.SetError(futureError) | ||
|
||
mPool := mockpool.NewPool(t) | ||
mPool.On("Do", mock.Anything, mock.Anything).Return(errFuture) | ||
|
||
r.routeMap[5] = &Replicaset{ | ||
conn: mPool, | ||
} | ||
|
||
_, _, err := r.RouterCallImpl(ctx, 5, CallOpts{Timeout: time.Second}, "test", []byte("test")) | ||
require.ErrorIs(t, futureError, err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters