Sha256: 914b5d76ff3fca654f52b7419204def875e92791b28c459b4d448be018cdc302

Contents?: true

Size: 1.13 KB

Versions: 3

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, nil, 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

3 entries across 3 versions & 1 rubygems

Version Path
faye-websocket-0.9.2 examples/autobahn_client.rb
faye-websocket-0.9.1 examples/autobahn_client.rb
faye-websocket-0.9.0 examples/autobahn_client.rb