Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Consistency with Two Nodes #37

Merged
merged 1 commit into from
Nov 30, 2023
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
6 changes: 5 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ jobs:
runs-on: ubuntu-20.04
services:
memcached:
image: memcached:1.6.18
image: memcached:1.6.19
ports:
- 11211:11211
memcached2:
image: memcached:1.6.19
ports:
- 11212:11211
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
Expand Down
81 changes: 75 additions & 6 deletions item/item_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package item
import (
"context"
"fmt"
"github.com/QuangTung97/go-memcache/memcache"
"github.com/QuangTung97/memproxy"
"github.com/QuangTung97/memproxy/proxy"
"github.com/stretchr/testify/assert"
"math/rand"
"sync"
"testing"
"time"

"github.com/QuangTung97/go-memcache/memcache"
"github.com/stretchr/testify/assert"

"github.com/QuangTung97/memproxy"
"github.com/QuangTung97/memproxy/proxy"
)

type itemPropertyTest struct {
client *memcache.Client
mc memproxy.Memcache
client *memcache.Client
client2 *memcache.Client

mc memproxy.Memcache

mut sync.Mutex
currentAge int64
Expand Down Expand Up @@ -62,6 +66,14 @@ func (p *itemPropertyTest) flushAll() {
if err != nil {
panic(err)
}

if p.client2 != nil {
pipe := p.client2.Pipeline()
err := pipe.FlushAll()()
if err != nil {
panic(err)
}
}
}

func newItemPropertyTest(t *testing.T) *itemPropertyTest {
Expand Down Expand Up @@ -107,6 +119,50 @@ func newItemPropertyTestWithProxy(t *testing.T) *itemPropertyTest {
return p
}

func newItemPropertyTestWithProxyTwoNodes(t *testing.T) *itemPropertyTest {
p := &itemPropertyTest{}

client1, err := memcache.New("localhost:11211", 3)
if err != nil {
panic(err)
}

client2, err := memcache.New("localhost:11212", 3)
if err != nil {
panic(err)
}

t.Cleanup(func() {
_ = client1.Close()
_ = client2.Close()
})

p.client = client1
p.client2 = client2

servers := []proxy.SimpleServerConfig{
{
Host: "localhost",
Port: 11211,
},
{
Host: "localhost",
Port: 11212,
},
}
mc, closeFunc, err := proxy.NewSimpleReplicatedMemcache(
servers, 3,
proxy.NewSimpleStats(servers),
)
if err != nil {
panic(err)
}
t.Cleanup(closeFunc)
p.mc = mc

return p
}

func (p *itemPropertyTest) testConsistency(t *testing.T) {
var wg sync.WaitGroup

Expand Down Expand Up @@ -193,4 +249,17 @@ func TestProperty_SingleKey(t *testing.T) {
p.testConsistency(t)
}
})

t.Run("with-proxy-two-nodes", func(t *testing.T) {
seed := time.Now().UnixNano()
rand.Seed(seed)
fmt.Println("SEED:", seed)

p := newItemPropertyTestWithProxy(t)

for i := 0; i < 100; i++ {
p.flushAll()
p.testConsistency(t)
}
})
}
Loading