Sha256: 8a114f7caa14a47e64b1db4323327ee45753471e5358a4568de25b3b342224aa

Contents?: true

Size: 1.28 KB

Versions: 31

Compression:

Stored size: 1.28 KB

Contents

require File.dirname(__FILE__) + '/../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

31 entries across 31 versions & 4 rubygems

Version Path
michaelyta-thin-1.2.2 spec/server/stopping_spec.rb
thin-1.2.11 spec/server/stopping_spec.rb
thin-1.2.11-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.11-x86-mingw32 spec/server/stopping_spec.rb
thin-1.2.10 spec/server/stopping_spec.rb
thin-1.2.10-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.10-x86-mingw32 spec/server/stopping_spec.rb
thin-1.2.9 spec/server/stopping_spec.rb
thin-1.2.9-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.9-x86-mingw32 spec/server/stopping_spec.rb
thin-1.2.8 spec/server/stopping_spec.rb
thin-1.2.8-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.8-x86-mingw32 spec/server/stopping_spec.rb
steamcannon-thin-1.2.8 spec/server/stopping_spec.rb
thin-1.2.7 spec/server/stopping_spec.rb
thin-1.2.7-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.7-x86-mingw32 spec/server/stopping_spec.rb
thin-1.2.6 spec/server/stopping_spec.rb
thin-1.2.6-x86-mswin32 spec/server/stopping_spec.rb
thin-1.2.6-x86-mingw32 spec/server/stopping_spec.rb