Sha256: 6b150e63aa9a975303a48fe53ce7e508d324c98749980109df4a8340f2353c72

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

require 'rubygems'
require 'bundler/setup'
require 'cgi'
require 'faye/websocket'
require 'permessage_deflate'
require 'progressbar'

EM.run {
  host    = 'ws://localhost:9001'
  ruby    = RUBY_PLATFORM =~ /java/ ? 'jruby' : 'cruby'
  agent   = CGI.escape("#{ruby}-#{RUBY_VERSION}")
  cases   = 0
  options = {:extensions => [PermessageDeflate]}

  socket   = Faye::WebSocket::Client.new("#{host}/getCaseCount")
  progress = nil

  socket.onmessage = lambda do |event|
    puts "Total cases to run: #{event.data}"
    cases = event.data.to_i
    progress = ProgressBar.new('Autobahn', cases)
  end

  run_case = lambda do |n|
    if n > cases
      socket = Faye::WebSocket::Client.new("#{host}/updateReports?agent=#{agent}")
      progress.finish
      socket.onclose = lambda { |e| EM.stop }
      next
    end

    url = "#{host}/runCase?case=#{n}&agent=#{agent}"
    socket = Faye::WebSocket::Client.new(url, [], options)

    socket.onmessage = lambda do |event|
      socket.send(event.data)
    end

    socket.on :close do |event|
      progress.inc
      run_case[n + 1]
    end
  end

  socket.onclose = lambda do |event|
    run_case[1]
  end
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
faye-websocket-0.10.5 examples/autobahn_client.rb
faye-websocket-0.10.4 examples/autobahn_client.rb
faye-websocket-0.10.3 examples/autobahn_client.rb
faye-websocket-0.10.2 examples/autobahn_client.rb
faye-websocket-0.10.1 examples/autobahn_client.rb
faye-websocket-0.10.0 examples/autobahn_client.rb