Skip to content

Commit

Permalink
test servers
Browse files Browse the repository at this point in the history
  • Loading branch information
kshvakov committed Sep 2, 2024
1 parent 65734e6 commit e3adbc5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
- name: Start memcached
run: |
memcached -d -p 11211
memcached -d -p 11212
memcached -d -p 11213
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v4
Expand Down
10 changes: 7 additions & 3 deletions client_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
)

func BenchmarkParallel(b *testing.B) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -43,7 +45,9 @@ func BenchmarkParallel(b *testing.B) {
}

func BenchmarkGet(b *testing.B) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
b.Fatal(err)
}
Expand All @@ -62,7 +66,7 @@ func BenchmarkGet(b *testing.B) {
}

func BenchmarkOriginalGet(b *testing.B) {
cache := memcache.New(testServerAddr)
cache := memcache.New(testServerAddrs...)
b.ReportAllocs()
b.ResetTimer()
cache.Set(&memcache.Item{
Expand Down
12 changes: 9 additions & 3 deletions client_extend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

func TestMinUses(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -46,7 +48,9 @@ func TestMinUses(t *testing.T) {

func TestScalingExpiration(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -80,7 +84,9 @@ func TestScalingExpiration(t *testing.T) {

func TestNamespace(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down
14 changes: 10 additions & 4 deletions client_get_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

func TestGetMulti(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -44,7 +46,7 @@ func TestGetMulti(t *testing.T) {

func TestGetMultiXXKeyHash(t *testing.T) {
cache, err := mc.New(&mc.Options{
Addrs: []string{testServerAddr},
Addrs: testServerAddrs,
KeyHashFunc: mc.XXKeyHashFunc,
})
if err != nil {
Expand Down Expand Up @@ -77,7 +79,9 @@ func TestGetMultiXXKeyHash(t *testing.T) {
}
}
func TestGetMultiScalingExpiration(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -117,7 +121,9 @@ func TestGetMultiScalingExpiration(t *testing.T) {
}

func TestGetMultiNamespace(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down
28 changes: 21 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
)

func TestAddSet(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -51,7 +53,9 @@ func TestAddSet(t *testing.T) {
}

func TestCompareAndSwap(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -94,7 +98,9 @@ func TestCompareAndSwap(t *testing.T) {

func TestIncrDecr(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -124,7 +130,9 @@ func TestIncrDecr(t *testing.T) {
}
func TestIncrDecrBad(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand All @@ -147,7 +155,9 @@ func TestIncrDecrBad(t *testing.T) {
}
func TestIncrDecrWithInitial(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand All @@ -168,7 +178,9 @@ func TestIncrDecrWithInitial(t *testing.T) {

func TestDelete(t *testing.T) {
ctx := context.Background()
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -197,7 +209,9 @@ func TestDelete(t *testing.T) {
}

func TestDeadline(t *testing.T) {
cache, err := newTestClient(testServerAddr)
cache, err := mc.New(&mc.Options{
Addrs: testServerAddrs,
})
if err != nil {
t.Fatal(err)
}
Expand Down
18 changes: 5 additions & 13 deletions client_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package mc_test

import (
"math/rand"

"github.com/kinescope/mc"
)

const testServerAddr = "127.0.0.1:11211"
var testServerAddrs = []string{
"127.0.0.1:11211",
"127.0.0.1:11212",
"127.0.0.1:11213",
}

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

Expand All @@ -17,13 +19,3 @@ func randSeq(n int) string {
}
return string(b)
}

func newTestClient(addr ...string) (*mc.Client, error) {
cache, err := mc.New(&mc.Options{
Addrs: addr,
})
if err != nil {
return nil, err
}
return cache, nil
}

0 comments on commit e3adbc5

Please sign in to comment.