diff options
Diffstat (limited to 'plugins/broadcast/root/rpc_test.go')
-rw-r--r-- | plugins/broadcast/root/rpc_test.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/plugins/broadcast/root/rpc_test.go b/plugins/broadcast/root/rpc_test.go new file mode 100644 index 00000000..157c4e70 --- /dev/null +++ b/plugins/broadcast/root/rpc_test.go @@ -0,0 +1,72 @@ +package broadcast + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRPC_Broadcast(t *testing.T) { + br, rpc, c := setup(`{}`) + defer c.Stop() + + client := br.NewClient() + defer client.Close() + + rcpClient, err := rpc.Client() + assert.NoError(t, err) + + // must not be delivered + ok := false + assert.NoError(t, rcpClient.Call( + "broadcast.Publish", + []*Message{newMessage("topic", `"hello1"`)}, + &ok, + )) + assert.True(t, ok) + + assert.NoError(t, client.Subscribe("topic")) + + assert.NoError(t, rcpClient.Call( + "broadcast.Publish", + []*Message{newMessage("topic", `"hello1"`)}, + &ok, + )) + assert.True(t, ok) + assert.Equal(t, `"hello1"`, readStr(<-client.Channel())) + + assert.NoError(t, rcpClient.Call( + "broadcast.Publish", + []*Message{newMessage("topic", `"hello2"`)}, + &ok, + )) + assert.True(t, ok) + assert.Equal(t, `"hello2"`, readStr(<-client.Channel())) + + assert.NoError(t, client.Unsubscribe("topic")) + + assert.NoError(t, rcpClient.Call( + "broadcast.Publish", + []*Message{newMessage("topic", `"hello3"`)}, + &ok, + )) + assert.True(t, ok) + + assert.NoError(t, client.Subscribe("topic")) + + assert.NoError(t, rcpClient.Call( + "broadcast.Publish", + []*Message{newMessage("topic", `"hello4"`)}, + &ok, + )) + assert.True(t, ok) + assert.Equal(t, `"hello4"`, readStr(<-client.Channel())) + + assert.NoError(t, rcpClient.Call( + "broadcast.PublishAsync", + []*Message{newMessage("topic", `"hello5"`)}, + &ok, + )) + assert.True(t, ok) + assert.Equal(t, `"hello5"`, readStr(<-client.Channel())) +} |