Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created March 25, 2014 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi/9765129 to your computer and use it in GitHub Desktop.
Save kenichi/9765129 to your computer and use it in GitHub Desktop.
minitest "server gets a post" example with timeout and server thread
require 'minitest/autorun'
require 'httpclient'
require 'socket'
require 'timeout'
describe 'server gets post' do
it 'gets a post' do
timeout = Timeout.timeout 5 do
server_thread = Thread.new do
server = TCPServer.new 8080
client = server.accept
it_worked = false
while line = client.gets do
it_worked = true if line =~ /POST \/test/
break if line.chomp.empty?
end
client.puts ''
[client,server].each &:close
raise unless it_worked
end
HTTPClient.new.post 'http://127.0.0.1:8080/test'
server_thread.join
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment