Sha256: 336abfac31ba4fc25e271e3634528c07c41a420734bf276cff31202a772b2987

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'rubygems'
require File.expand_path('../../lib/faye/websocket', __FILE__)
require 'cgi'

EM.run {
  host   = 'ws://localhost:9001'
  agent  = "Faye (Ruby #{RUBY_VERSION})"
  cases  = 0
  skip   = [247,248,249,250,251,252,253,254,255,
            256,257,258,259,260,261,262,263,264]
  
  socket = Faye::WebSocket::Client.new("#{host}/getCaseCount")
  
  socket.onmessage = lambda do |event|
    puts "Total cases to run: #{event.data}"
    cases = event.data.to_i
  end
  
  socket.onclose = lambda do |event|
    run_case = lambda do |n|
      if n > cases
        socket = Faye::WebSocket::Client.new("#{host}/updateReports?agent=#{CGI.escape agent}")
        socket.onclose = lambda { |e| EM.stop }
        
      elsif skip.include?(n)
        EM.next_tick { run_case.call(n+1) }
        
      else
        puts "Running test case ##{n} ..."
        socket = Faye::WebSocket::Client.new("#{host}/runCase?case=#{n}&agent=#{CGI.escape agent}")
        
        socket.onmessage = lambda do |event|
          socket.send(event.data)
        end
        
        socket.onclose = lambda do |event|
          run_case.call(n + 1)
        end
      end
    end
    
    run_case.call(1)
  end
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faye-websocket-0.1.2 examples/autobahn_client.rb
faye-websocket-0.1.1 examples/autobahn_client.rb
faye-websocket-0.1.0 examples/autobahn_client.rb