Skip to content

All the world's a stage, and all the men and women mearly players

License

Notifications You must be signed in to change notification settings

Grandman/wsdirector

 
 

Repository files navigation

WebSocket Director

CLI for testing websocket, using scenarios.

Sponsored by Evil Martians

Installation

gem install wsdirector

Usage

wsdirector scenario path websocket_url  [-s]

If run was success it will print success If something will go not according scenario, script returns fail exit code and print extra information. There are 2 types of using: simple and multi-client

Simple scenario

- receive: # should receive message
    data: # it's json object
      type: "welcome"
- send: # should send message
    data: # json object
      command: "subscribe"
      identifier: "{\"channel\":\"TestChannel\"}"
- receive:
    data:
      identifier: "{\"channel\":\"TestChannel\"}"
      type: "confirm_subscription"
- send:
    data:
      command: "message"
      identifier: "{\"channel\":\"TestChannel\"}"
      data: "{\"text\": \"echo\",\"action\":\"echo\"}"
- receive:
    data:
      identifier: "{\"channel\":\"TestChannel\"}"
      message:
        text: "echo"
        action: "echo"

run simple scenario:

wsdirector script.yml ws://127.0.0.1:3000

Multi-client scenario

- client: # first client group (senders)
    multiplier: ":scale" # multiplies clients
    actions:
      - receive:
          data:
            type: "welcome"
      - send:
          data:
            command: "subscribe"
            identifier: "{\"channel\":\"TestChannel\"}"
      - receive:
          data:
            identifier: "{\"channel\":\"TestChannel\"}"
            type: "confirm_subscription"
      - wait_all # wait all clients in this point from both clients group in this case 
      - send:
          data:
            command: "message"
            identifier: "{\"channel\":\"TestChannel\"}"
            data: "{\"text\": \"echo\",\"action\":\"broadcast\"}"

- client: # second client group (readers)
    multiplier: ":scale * 2" # multiplies clients: 2 * senders
    actions:
      - receive:
          data:
            type: "welcome"
      - send:
          data:
            command: "subscribe"
            identifier: "{\"channel\":\"TestChannel\"}"
      - receive:
          data:
            identifier: "{\"channel\":\"TestChannel\"}"
            type: "confirm_subscription"
      - wait_all # wait all clients in this point from both clients group in this case 
      - receive:
          multiplier: ":scale" # multiplies actions, should receive as many messages as senders count
          data:
            identifier: "{\"channel\":\"TestChannel\"}"
            message:
              text: "echo"
              action: "broadcast"

:scale is multiplier of clients or actions. It pass by -s param.

This example works with ActionCable channel:

class TestChannel < ApplicationCable::Channel
  def subscribed
    stream_from "all"
  end

  def echo(data)
    transmit data
  end

  def broadcast(data)
    ActionCable.server.broadcast "all", data
  end
end

run multi-client scenario:

wsdirector script.yml ws://127.0.0.1:3000 -s 5

Development

bin/setup

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/wsdirector.

License

The gem is available as open source under the terms of the MIT License.

About

All the world's a stage, and all the men and women mearly players

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 98.9%
  • Shell 1.1%