I’ve got a bit of a problem with my network code. Perhaps someone can
help me out with this:
I’ve got a program in which I run a TCP server. The code is basically
s = TCPServer.new(@port)
Thread.start(s.accept) do |session|
# handle incoming connections…
The server code works just fine. However, my problem is that as it is,
Im having trouble testing it. Once the server is initiated, I can’t shut
it down in code. Thus Im not able to figure out how to do rspec examples
with it. If I try to start the server code in an rspec example and run
some client stuff to test it, I never get to the next examples, because
the server code wont quit. It just runs forever.
Is there a better way to do this, so I can shut it down at will, and be
able to make a proper test suite?