Skip to content

Commit

Permalink
Test Consistency with Two Nodes (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuangTung97 committed Nov 30, 2023
1 parent ed92e5a commit e66c806
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
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)
}
})
}

0 comments on commit e66c806

Please sign in to comment.