From e3adbc5f0e1809171963a1be6e96748647094827 Mon Sep 17 00:00:00 2001 From: kshvakov Date: Mon, 2 Sep 2024 13:14:58 +0000 Subject: [PATCH] test servers --- .github/workflows/run-tests.yml | 2 ++ client_benchmark_test.go | 10 +++++++--- client_extend_test.go | 12 +++++++++--- client_get_multi_test.go | 14 ++++++++++---- client_test.go | 28 +++++++++++++++++++++------- client_utils_test.go | 18 +++++------------- 6 files changed, 54 insertions(+), 30 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c144111..04d42d0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 diff --git a/client_benchmark_test.go b/client_benchmark_test.go index f77a32c..cc0b2d1 100644 --- a/client_benchmark_test.go +++ b/client_benchmark_test.go @@ -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) } @@ -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) } @@ -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{ diff --git a/client_extend_test.go b/client_extend_test.go index 33db3fb..ec9b8a7 100644 --- a/client_extend_test.go +++ b/client_extend_test.go @@ -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) } @@ -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) } @@ -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) } diff --git a/client_get_multi_test.go b/client_get_multi_test.go index 13debeb..5e1e5f0 100644 --- a/client_get_multi_test.go +++ b/client_get_multi_test.go @@ -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) } @@ -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 { @@ -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) } @@ -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) } diff --git a/client_test.go b/client_test.go index 073168d..8fa38be 100644 --- a/client_test.go +++ b/client_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/client_utils_test.go b/client_utils_test.go index 9241ab0..c2c1552 100644 --- a/client_utils_test.go +++ b/client_utils_test.go @@ -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") @@ -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 -}