receivedChannel2 = channel
}, "{prefix}", "---", "{prefix}channel2")
+ time.Sleep(1 * time.Second)
db.UnsubscribeChannelDB("{prefix}channel1")
ch <- &msg2
db.UnsubscribeChannelDB("{prefix}channel2")
ps.AssertExpectations(t)
}
+func TestSubscribeChannelReDBSubscribeAfterUnsubscribe(t *testing.T) {
+ ps, r, db := setup(true)
+ ch := make(chan *redis.Message)
+ msg := redis.Message{
+ Channel: "{prefix}channel",
+ Pattern: "pattern",
+ Payload: "event",
+ }
+ ps.On("Channel").Return(ch)
+ ps.On("Unsubscribe").Return(nil)
+ ps.On("Close").Return(nil)
+ count := 0
+ receivedChannel := ""
+
+ db.SubscribeChannelDB(func(channel string, payload ...string) {
+ count++
+ receivedChannel = channel
+ }, "{prefix}", "---", "{prefix}channel")
+ ch <- &msg
+ db.UnsubscribeChannelDB("{prefix}channel")
+ time.Sleep(1 * time.Second)
+
+ db.SubscribeChannelDB(func(channel string, payload ...string) {
+ count++
+ receivedChannel = channel
+ }, "{prefix}", "---", "{prefix}channel")
+ ch <- &msg
+ db.UnsubscribeChannelDB("{prefix}channel")
+
+ time.Sleep(1 * time.Second)
+ assert.Equal(t, 2, count)
+ assert.Equal(t, "channel", receivedChannel)
+ r.AssertExpectations(t)
+ ps.AssertExpectations(t)
+}
+
func TestPTTLSuccessfully(t *testing.T) {
_, r, db := setup(true)
expectedKey := "key"