2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../../spec_helper'
|
|
|
|
require_relative '../fixtures/classes'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
platform_is_not :windows do
|
|
|
|
describe "UNIXServer#accept" do
|
|
|
|
before :each do
|
|
|
|
@path = SocketSpecs.socket_path
|
2017-06-15 12:48:52 +00:00
|
|
|
@server = UNIXServer.open(@path)
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
2017-06-15 12:48:52 +00:00
|
|
|
@server.close if @server
|
2017-05-14 14:09:56 +00:00
|
|
|
SocketSpecs.rm_socket @path
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts what is written by the client" do
|
2017-05-14 14:09:56 +00:00
|
|
|
client = UNIXSocket.open(@path)
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
client.send('hello', 0)
|
|
|
|
|
2017-06-15 12:48:52 +00:00
|
|
|
sock = @server.accept
|
|
|
|
begin
|
|
|
|
data, info = sock.recvfrom(5)
|
2017-05-07 12:04:49 +00:00
|
|
|
|
2017-06-15 12:48:52 +00:00
|
|
|
data.should == 'hello'
|
|
|
|
info.should_not be_empty
|
|
|
|
ensure
|
|
|
|
sock.close
|
|
|
|
client.close
|
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can be interrupted by Thread#kill" do
|
|
|
|
t = Thread.new {
|
2017-06-15 12:48:52 +00:00
|
|
|
@server.accept
|
2017-05-07 12:04:49 +00:00
|
|
|
}
|
|
|
|
Thread.pass while t.status and t.status != "sleep"
|
|
|
|
|
|
|
|
# kill thread, ensure it dies in a reasonable amount of time
|
|
|
|
t.kill
|
2017-06-15 12:48:52 +00:00
|
|
|
a = 0
|
|
|
|
while t.alive? and a < 5000
|
|
|
|
sleep 0.001
|
2017-05-07 12:04:49 +00:00
|
|
|
a += 1
|
|
|
|
end
|
2017-06-15 12:48:52 +00:00
|
|
|
a.should < 5000
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can be interrupted by Thread#raise" do
|
|
|
|
t = Thread.new {
|
2017-10-28 15:15:48 +00:00
|
|
|
-> {
|
|
|
|
@server.accept
|
|
|
|
}.should raise_error(Exception, "interrupted")
|
2017-05-07 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 15:15:48 +00:00
|
|
|
Thread.pass while t.status and t.status != "sleep"
|
|
|
|
t.raise Exception, "interrupted"
|
|
|
|
t.join
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|