Sha256: 14c3c7e9a1cdcfc8cb05b6b0493d0bc38b0d75cddf961e257cf0de3a3d488566

Contents?: true

Size: 1.56 KB

Versions: 25

Compression:

Stored size: 1.56 KB

Contents

# this server simply accepts requests and blocks for a passed in interval before returning a passed in reqeust value to
# the client
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
 
class DelayFixtureServer  < EventMachine::Connection
  include EventMachine::HttpServer
 
  def process_http_request
    EventMachine.stop if ENV["PATH_INFO"] == "/die"
    puts "got a request #{ENV['PATH_INFO']}"
    resp = EventMachine::DelegatedHttpResponse.new( self )
    
    # Block which fulfills the request
    operation = proc do
      sleep DelayFixtureServer.response_delay

      resp.status = 200
      resp.content = "whatever"
    end

    # Callback block to execute once the request is fulfilled
    callback = proc do |res|
      resp.send_response
    end

    # Let the thread pool (20 Ruby threads) handle request
    EM.defer(operation, callback)
  end
  
  def self.response_fixture
    @response_fixture ||= ""
  end
  
  def self.response_fixture=(val)
    @response_fixture = val
  end

  def self.response_delay
    @response_delay ||= 0
  end

  def self.response_delay=(val)
    @response_delay = val
  end
  
  def self.reponse_number
    @response_number
  end
  
  def self.response_number=(val)
    @response_number = val
  end
end

port = (ARGV[0] || 3000).to_i

DelayFixtureServer.response_delay   = 0.5
DelayFixtureServer.response_number = 0
#DelayFixtureServer.response_fixture = File.read(File.dirname(__FILE__) + "/../fixtures/result_set.xml")

EventMachine::run {
  EventMachine.epoll
  EventMachine::start_server("0.0.0.0", port, DelayFixtureServer)
}

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
abhay-typhoeus-0.0.22 spec/servers/delay_fixture_server.rb
dbalatero-typhoeus-0.0.20 spec/servers/delay_fixture_server.rb
dbalatero-typhoeus-0.0.21 spec/servers/delay_fixture_server.rb
dbalatero-typhoeus-0.0.22 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.10 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.11 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.12 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.13 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.14 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.15 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.16 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.17 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.18 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.19 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.20 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.22 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.23 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.24 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.0.8 spec/servers/delay_fixture_server.rb
pauldix-typhoeus-0.1.0 spec/servers/delay_fixture_server.rb