spegling av https://git.mills.io/prologic/msgbus.git
Add a failing unit test for testing the wal feature
This commit is contained in:
förälder
5ba388849b
incheckning
dc2d6b3224
|
@ -161,25 +161,39 @@ func TestMessageBusWAL(t *testing.T) {
|
|||
mb, err := NewMessageBus(WithLogPath(testdir))
|
||||
require.NoError(err)
|
||||
|
||||
msgs := mb.Subscribe("id1", "foo")
|
||||
|
||||
topic := mb.NewTopic("foo")
|
||||
expected := mb.NewMessage(topic, []byte("foo"))
|
||||
mb.Put(expected)
|
||||
|
||||
actual := <-msgs
|
||||
assert.Equal(expected, actual)
|
||||
assert.Equal(0, actual.ID)
|
||||
|
||||
mb.Unsubscribe("id1", "foo")
|
||||
msgs := mb.Subscribe("id1", "hello")
|
||||
|
||||
topic := mb.NewTopic("hello")
|
||||
mb.Put(mb.NewMessage(topic, []byte("foo"))) // ID == 0
|
||||
mb.Put(mb.NewMessage(topic, []byte("bar"))) // ID == 1
|
||||
mb.Put(mb.NewMessage(topic, []byte("baz"))) // ID == 2
|
||||
|
||||
msgs = mb.Subscribe("id1", "foo", WithIndex(1))
|
||||
|
||||
assert.Equal([]byte("foo"), (<-msgs).Payload)
|
||||
assert.Equal([]byte("bar"), (<-msgs).Payload)
|
||||
assert.Equal([]byte("baz"), (<-msgs).Payload)
|
||||
|
||||
assert.Equal(3, topic.Sequence)
|
||||
|
||||
mb.Unsubscribe("id1", "foo")
|
||||
|
||||
// Now ensure when we start back up we've re-filled the queues and retain the same
|
||||
// message ids and topic sequence number
|
||||
|
||||
mb, err = NewMessageBus(WithLogPath(testdir))
|
||||
require.NoError(err)
|
||||
|
||||
// we have to tell the bus we want to subscribe from the start
|
||||
msgs = mb.Subscribe("id1", "hello", WithIndex(0))
|
||||
|
||||
topic = mb.NewTopic("hello")
|
||||
assert.Equal(3, topic.Sequence)
|
||||
|
||||
assert.Equal([]byte("foo"), (<-msgs).Payload)
|
||||
assert.Equal([]byte("bar"), (<-msgs).Payload)
|
||||
assert.Equal([]byte("baz"), (<-msgs).Payload)
|
||||
|
||||
msg := mb.NewMessage(topic, []byte("foobar"))
|
||||
assert.Equal(4, msg.ID)
|
||||
}
|
||||
|
||||
func TestServeHTTPGETIndexEmpty(t *testing.T) {
|
||||
|
|
Laddar…
Referens i nytt ärende