Sha256: e0887c9442cdc30a950d8de58f639dbfdc8c0ac91efd53adf71af81cddccee8e

Contents?: true

Size: 1.25 KB

Versions: 48

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Server, "stopping" do
  before do
    start_server do |env|
      [200, { 'Content-Type' => 'text/html' }, ['ok']]
    end
    @done = false
  end
  
  it "should wait for current requests before soft stopping" do
    socket = TCPSocket.new('0.0.0.0', 3333)
    socket.write("GET / HTTP/1.1")
    EventMachine.next_tick do
      @server.stop # Stop the server in the middle of a request
      socket.write("\r\n\r\n")
      @done = true
    end
    
    timeout(2) do
      Thread.pass until @done
    end
    
    out = socket.read
    socket.close
    
    out.should_not be_empty
  end
  
  it "should not accept new requests when soft stopping" do
    socket = TCPSocket.new('0.0.0.0', 3333)
    socket.write("GET / HTTP/1.1")
    @server.stop # Stop the server in the middle of a request
    
    EventMachine.next_tick do
      proc { get('/') }.should raise_error(Errno::ECONNRESET)
    end
    
    socket.close
  end
  
  it "should drop current requests when hard stopping" do
    socket = TCPSocket.new('0.0.0.0', 3333)
    socket.write("GET / HTTP/1.1")
    @server.stop! # Force stop the server in the middle of a request
    
    EventMachine.next_tick do
      socket.should be_closed
    end
  end
  
  after do
    stop_server
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.7.4 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.7.3 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.7.2 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.7.1 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.7.0 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.9 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.8 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.7 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.6 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.5 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.4 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.3 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.2 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.1 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.6.0 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.5.17 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.5.16 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.5.15 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb
classiccms-0.5.14 vendor/bundle/gems/thin-1.3.1/spec/server/stopping_spec.rb