0
body << env['rack.input'].read
0
[200, { 'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s }, body]
0
- server = Thin::Server.new('0.0.0.0', 3333, app)
0
+ @server = Thin::Server.new('0.0.0.0', 3333, app)
0
- @thread = Thread.new {
server.start }
0
+ @thread = Thread.new {
@server.start }
0
sleep 0.1 until @thread.status == 'sleep'
0
it 'should GET from TCPSocket' do
0
- raw(
'0.0.0.0', 3333, "GET /?this HTTP/1.1\r\n\r\n").
0
+ raw(
"GET /?this HTTP/1.1\r\n\r\n").
0
should include("HTTP/1.1 200 OK",
0
"Content-Type: text/html", "Content-Length: ",
0
"Connection: close", "this")
0
it 'should return empty string on incomplete headers' do
0
- raw(
'0.0.0.0', 3333, "GET /?this HTTP/1.1\r\nHost:").should be_empty
0
+ raw(
"GET /?this HTTP/1.1\r\nHost:").should be_empty
0
it 'should return empty string on incorrect Content-Length' do
0
- raw(
'0.0.0.0', 3333, "POST / HTTP/1.1\r\nContent-Length: 300\r\n\r\naye").should be_empty
0
+ raw(
"POST / HTTP/1.1\r\nContent-Length: 300\r\n\r\naye").should be_empty
0
it 'should POST from Net::HTTP' do
0
get('/').should include('"REMOTE_ADDR"=>"127.0.0.1"')
0
+ it "should wait for current requests before soft stopping" do
0
+ socket = TCPSocket.new('0.0.0.0', 3333)
0
+ socket.write("GET / HTTP/1.1")
0
+ @server.stop # Stop the server in the middle of a request
0
+ socket.write("\r\n\r\n")
0
+ out.should_not be_empty
0
+ it "should not accept new requests when soft stopping" do
0
+ socket = TCPSocket.new('0.0.0.0', 3333)
0
+ socket.write("GET / HTTP/1.1")
0
+ @server.stop # Stop the server in the middle of a request
0
+ EventMachine.next_tick do
0
+ proc { get('/') }.should raise_error(Errno::ECONNRESET)
0
+ it "should drop current requests when hard stopping" do
0
+ socket = TCPSocket.new('0.0.0.0', 3333)
0
+ socket.write("GET / HTTP/1.1")
0
+ @server.stop! # Force stop the server in the middle of a request
0
+ EventMachine.next_tick { socket.should be_closed }
0
Net::HTTP.get(URI.parse('http://0.0.0.0:3333' + url))
0
- def raw(host, port, data)
0
- socket = TCPSocket.new(host, port)
0
+ socket = TCPSocket.new('0.0.0.0', 3333)
0
it "should remove socket file after server stops" do
0
File.exist?('/tmp/thin_test.sock').should be_false
Comments
No one has commented yet.