Skip to content

Commit

Permalink
Try to close server during shutdown
Browse files Browse the repository at this point in the history
If the server never accepts a client, joining on this thread will
hang the spec and never be terminated because it happens in an
"after" section. Instead, we try to close the server if it has not
already been closed, so it will terminate gracefully.

See #925
  • Loading branch information
headius authored and eregon committed Mar 28, 2022
1 parent ada0e2e commit c96dc4f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions library/socket/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def service(socket)

socket.send data, 0
ensure
socket.close
socket.close unless socket.closed?
end
end

def shutdown
log "SpecTCPServer shutting down"
@server.close unless @server.closed?
@thread.join
@server.close
end

def log(message)
Expand Down
3 changes: 2 additions & 1 deletion library/socket/udpsocket/send_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
retry
end
ensure
@server.close if !@server.closed?
@server.close unless @server.closed?
end
end
Thread.pass while @server_thread.status and !@port
end

after :each do
@server.close unless @server.closed?
@server_thread.join
end

Expand Down

0 comments on commit c96dc4f

Please sign in to comment.