Files
redis-go/cluster/pubsub_test.go
finley bf7f628810 raft cluster
wip: raft does not care about migrating

wip: optimize code

wip: raft election

wip

wip: fix raft leader missing log entries

wip

fix a dead lock

batch set slot route

wip: raft persist

wip

refactor cluster suite

remove relay

rename relay2

refactor: allow customizing client factory

test raft

refactor re-balance

avoid errors caused by inconsistent status on follower nodes during raft commits

test raft election
2023-06-10 22:48:24 +08:00

50 lines
1.2 KiB
Go

package cluster
import (
"github.com/hdt3213/godis/lib/utils"
"github.com/hdt3213/godis/redis/connection"
"github.com/hdt3213/godis/redis/parser"
"github.com/hdt3213/godis/redis/protocol/asserts"
"testing"
)
func TestPublish(t *testing.T) {
testNodeA := testCluster[0]
channel := utils.RandString(5)
msg := utils.RandString(5)
conn := connection.NewFakeConn()
Subscribe(testNodeA, conn, utils.ToCmdLine("SUBSCRIBE", channel))
conn.Clean() // clean subscribe success
Publish(testNodeA, conn, utils.ToCmdLine("PUBLISH", channel, msg))
data := conn.Bytes()
ret, err := parser.ParseOne(data)
if err != nil {
t.Error(err)
return
}
asserts.AssertMultiBulkReply(t, ret, []string{
"message",
channel,
msg,
})
// unsubscribe
UnSubscribe(testNodeA, conn, utils.ToCmdLine("UNSUBSCRIBE", channel))
conn.Clean()
Publish(testNodeA, conn, utils.ToCmdLine("PUBLISH", channel, msg))
data = conn.Bytes()
if len(data) > 0 {
t.Error("expect no msg")
}
// unsubscribe all
Subscribe(testNodeA, conn, utils.ToCmdLine("SUBSCRIBE", channel))
UnSubscribe(testNodeA, conn, utils.ToCmdLine("UNSUBSCRIBE"))
conn.Clean()
Publish(testNodeA, conn, utils.ToCmdLine("PUBLISH", channel, msg))
data = conn.Bytes()
if len(data) > 0 {
t.Error("expect no msg")
}
}