Skip to content

Commit

Permalink
Fix race condition in the mocked owserver startup
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocr committed May 16, 2013
1 parent a1c6843 commit b941a7d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/mock_owserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,26 @@ def initialize(opts={})
@paths[canonical_path("uncached/"+canon)] = v
end
@mutex = Mutex.new

@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
@socket.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
@socket.bind(Socket.pack_sockaddr_in(@port, @address))
@socket.listen 10
end

def run!
@stopped = false
@nrequests = 0
@thread = Thread.new do
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
socket.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
socket.bind(Socket.pack_sockaddr_in(@port, @address))
socket.listen 10
while !@stopped
begin
client, client_sockaddr = socket.accept_nonblock
client, client_sockaddr = @socket.accept_nonblock
respond(client)
rescue Errno::EAGAIN
sleep 0.1
end
end
socket.close
@socket.close
end
end

Expand Down

0 comments on commit b941a7d

Please sign in to comment.