celluloid-io 0.17.1 → 0.17.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.travis.yml +17 -10
- data/CHANGES.md +11 -1
- data/Gemfile +0 -1
- data/Guardfile +2 -2
- data/Rakefile +3 -3
- data/benchmarks/actor.rb +4 -3
- data/celluloid-io.gemspec +5 -5
- data/examples/echo_client.rb +3 -4
- data/examples/echo_server.rb +2 -2
- data/examples/echo_unix_client.rb +2 -3
- data/examples/echo_unix_server.rb +2 -3
- data/lib/celluloid/io.rb +15 -15
- data/lib/celluloid/io/dns_resolver.rb +8 -9
- data/lib/celluloid/io/reactor.rb +6 -6
- data/lib/celluloid/io/ssl_server.rb +1 -2
- data/lib/celluloid/io/ssl_socket.rb +17 -15
- data/lib/celluloid/io/tcp_socket.rb +10 -10
- data/lib/celluloid/io/unix_socket.rb +5 -5
- data/lib/celluloid/io/version.rb +1 -1
- data/spec/celluloid/io/actor_spec.rb +2 -2
- data/spec/celluloid/io/dns_resolver_spec.rb +9 -9
- data/spec/celluloid/io/mailbox_spec.rb +2 -2
- data/spec/celluloid/io/reactor_spec.rb +8 -8
- data/spec/celluloid/io/ssl_server_spec.rb +4 -5
- data/spec/celluloid/io/ssl_socket_spec.rb +26 -26
- data/spec/celluloid/io/tcp_server_spec.rb +4 -4
- data/spec/celluloid/io/tcp_socket_spec.rb +26 -21
- data/spec/celluloid/io/udp_socket_spec.rb +3 -3
- data/spec/celluloid/io/unix_server_spec.rb +8 -10
- data/spec/celluloid/io/unix_socket_spec.rb +21 -18
- data/spec/celluloid/io_spec.rb +5 -5
- data/spec/spec_helper.rb +7 -124
- data/spec/support/examples/classes.rb +12 -0
- data/spec/support/examples/methods.rb +90 -0
- metadata +60 -57
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "socket"
|
2
2
|
|
3
3
|
module Celluloid
|
4
4
|
module IO
|
@@ -10,7 +10,7 @@ module Celluloid
|
|
10
10
|
|
11
11
|
# Open a UNIX connection.
|
12
12
|
def self.open(socket_path, &block)
|
13
|
-
|
13
|
+
new(socket_path, &block)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Convert a Ruby UNIXSocket into a Celluloid::IO::UNIXSocket
|
@@ -31,9 +31,9 @@ module Celluloid
|
|
31
31
|
|
32
32
|
# FIXME: not doing non-blocking connect
|
33
33
|
@socket = if block
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
::UNIXSocket.open(socket_path, &block)
|
35
|
+
else
|
36
|
+
::UNIXSocket.new(socket_path)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/celluloid/io/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::DNSResolver do
|
4
|
-
|
5
|
-
it
|
3
|
+
RSpec.describe Celluloid::IO::DNSResolver, library: :IO do
|
4
|
+
context '#resolve' do
|
5
|
+
it "resolves hostnames statically from hosts file without nameservers" do
|
6
6
|
# /etc/resolv.conf doesn't exist on Mac OSX when no networking is
|
7
7
|
# disabled, thus .nameservers would return nil
|
8
8
|
expect(Celluloid::IO::DNSResolver).to receive(:nameservers).at_most(:once) { nil }
|
9
9
|
resolver = Celluloid::IO::DNSResolver.new
|
10
|
-
expect(resolver.resolve(
|
10
|
+
expect(resolver.resolve("localhost")).to eq(Resolv::IPv4.create("127.0.0.1")).or eq(Resolv::IPv6.create("::1"))
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it "resolves hostnames" do
|
14
14
|
resolver = Celluloid::IO::DNSResolver.new
|
15
|
-
expect(resolver.resolve(
|
15
|
+
expect(resolver.resolve("localhost")).to eq(Resolv::IPv4.create("127.0.0.1")).or eq(Resolv::IPv6.create("::1"))
|
16
16
|
end
|
17
17
|
|
18
18
|
it "resolves domain names" do
|
@@ -26,7 +26,7 @@ describe Celluloid::IO::DNSResolver do
|
|
26
26
|
resolver = Celluloid::IO::DNSResolver.new
|
27
27
|
results = resolver.resolve("www.google.com")
|
28
28
|
if results.is_a?(Array)
|
29
|
-
results.all? {|i| expect(i).to be_an_instance_of(Resolv::IPv4) }
|
29
|
+
results.all? { |i| expect(i).to be_an_instance_of(Resolv::IPv4) }
|
30
30
|
else
|
31
31
|
expect(results).to be_an_instance_of(Resolv::IPv4)
|
32
32
|
end
|
@@ -34,7 +34,7 @@ describe Celluloid::IO::DNSResolver do
|
|
34
34
|
# single entry.
|
35
35
|
results = resolver.resolve("www.yahoo.com")
|
36
36
|
if results.is_a?(Array)
|
37
|
-
results.all? {|i| expect(i).to be_an_instance_of(Resolv::IPv4) }
|
37
|
+
results.all? { |i| expect(i).to be_an_instance_of(Resolv::IPv4) }
|
38
38
|
else
|
39
39
|
expect(results).to be_an_instance_of(Resolv::IPv4)
|
40
40
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::Reactor do
|
3
|
+
RSpec.describe Celluloid::IO::Reactor, library: :IO do
|
4
4
|
let(:payload) { "balls" }
|
5
5
|
let(:example_port) { assign_port }
|
6
|
-
|
6
|
+
|
7
7
|
it "shouldn't crash" do
|
8
8
|
server = ::TCPServer.new example_addr, example_port
|
9
|
-
|
9
|
+
|
10
10
|
thread = Thread.new { server.accept }
|
11
|
-
|
11
|
+
|
12
12
|
socket = within_io_actor { Celluloid::IO::TCPSocket.new example_addr, example_port }
|
13
13
|
peer = thread.value
|
14
14
|
peer_thread = Thread.new { loop { peer << payload } }
|
15
15
|
handle = false
|
16
|
-
|
16
|
+
|
17
17
|
# Main server body:
|
18
18
|
within_io_actor do
|
19
19
|
begin
|
@@ -29,9 +29,9 @@ describe Celluloid::IO::Reactor do
|
|
29
29
|
handle = true
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
expect(handle).to be_truthy
|
34
|
-
|
34
|
+
|
35
35
|
server.close
|
36
36
|
peer.close
|
37
37
|
socket.close
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::SSLServer do
|
3
|
+
RSpec.describe Celluloid::IO::SSLServer, library: :IO do
|
4
4
|
let(:client_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("client.crt").read }
|
5
5
|
let(:client_key) { OpenSSL::PKey::RSA.new fixture_dir.join("client.key").read }
|
6
6
|
let(:client_context) do
|
@@ -9,7 +9,7 @@ describe Celluloid::IO::SSLServer do
|
|
9
9
|
context.key = client_key
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
let(:example_port) { assign_port }
|
14
14
|
let(:server_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("server.crt").read }
|
15
15
|
let(:server_key) { OpenSSL::PKey::RSA.new fixture_dir.join("server.key").read }
|
@@ -21,7 +21,7 @@ describe Celluloid::IO::SSLServer do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#accept" do
|
24
|
-
let(:payload) {
|
24
|
+
let(:payload) { "ohai" }
|
25
25
|
|
26
26
|
context "inside Celluloid::IO" do
|
27
27
|
it "should be evented" do
|
@@ -89,4 +89,3 @@ describe Celluloid::IO::SSLServer do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "openssl"
|
3
3
|
|
4
|
-
describe Celluloid::IO::SSLSocket do
|
5
|
-
let(:request) {
|
6
|
-
let(:response) {
|
4
|
+
RSpec.describe Celluloid::IO::SSLSocket, library: :IO do
|
5
|
+
let(:request) { "ping" }
|
6
|
+
let(:response) { "pong" }
|
7
7
|
|
8
8
|
let(:example_port) { assign_port }
|
9
9
|
let(:client_cert) { OpenSSL::X509::Certificate.new fixture_dir.join("client.crt").read }
|
@@ -15,28 +15,28 @@ describe Celluloid::IO::SSLSocket do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
after(:each)
|
18
|
+
after(:each) do
|
19
19
|
client.close rescue nil
|
20
20
|
server.close rescue nil
|
21
|
-
|
21
|
+
end
|
22
22
|
|
23
23
|
let(:client) do
|
24
24
|
attempts = 0
|
25
25
|
socket = begin
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
Timeout.timeout(Specs::MAX_EXECUTION) do
|
27
|
+
begin
|
28
|
+
TCPSocket.new example_addr, example_port
|
29
|
+
rescue Errno::ECONNREFUSED
|
30
|
+
raise if attempts >= Specs::MAX_ATTEMPTS
|
31
|
+
attempts += 1
|
32
|
+
# HAX: sometimes this fails to connect? o_O
|
33
|
+
# ... This can often fail 20 times in a row ... so yeah
|
34
|
+
# This is quite likely due to the Thread.pass style spinlocks for startup
|
35
|
+
# Seems gimpy, but sleep and retry
|
36
|
+
sleep 0.0126
|
37
|
+
retry
|
38
|
+
end
|
38
39
|
end
|
39
|
-
}
|
40
40
|
rescue => ex
|
41
41
|
attempted = "Tried #{attempts} times to instantiate socket."
|
42
42
|
raise ex.class.new(attempted)
|
@@ -77,7 +77,7 @@ describe Celluloid::IO::SSLSocket do
|
|
77
77
|
context "duck typing ::SSLSocket" do
|
78
78
|
it "responds to #peeraddr" do
|
79
79
|
with_ssl_sockets do |ssl_client, ssl_peer|
|
80
|
-
expect{ ssl_client.peeraddr }.to_not raise_error
|
80
|
+
expect { ssl_client.peeraddr }.to_not raise_error
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -96,7 +96,7 @@ describe Celluloid::IO::SSLSocket do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "starts SSL on a connected TCP socket" do
|
99
|
-
if RUBY_PLATFORM ==
|
99
|
+
if RUBY_PLATFORM == "java"
|
100
100
|
pending "JRuby support"
|
101
101
|
fail "Bypassing potential deadlock."
|
102
102
|
end
|
@@ -136,7 +136,7 @@ describe Celluloid::IO::SSLSocket do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it "starts SSL on a connected TCP socket" do
|
139
|
-
if RUBY_PLATFORM ==
|
139
|
+
if RUBY_PLATFORM == "java"
|
140
140
|
pending "JRuby support"
|
141
141
|
fail "Bypassing potential deadlock."
|
142
142
|
end
|
@@ -164,7 +164,7 @@ describe Celluloid::IO::SSLSocket do
|
|
164
164
|
|
165
165
|
it "knows its cert" do
|
166
166
|
# FIXME: seems bad? o_O
|
167
|
-
pending "wtf is wrong with this on JRuby" if RUBY_PLATFORM ==
|
167
|
+
pending "wtf is wrong with this on JRuby" if RUBY_PLATFORM == "java"
|
168
168
|
with_ssl_sockets do |ssl_client|
|
169
169
|
expect(ssl_client.cert.to_der).to eq(client_cert.to_der)
|
170
170
|
end
|
@@ -192,7 +192,7 @@ describe Celluloid::IO::SSLSocket do
|
|
192
192
|
|
193
193
|
it "knows its client_ca" do
|
194
194
|
# jruby-openssl does not implement this method
|
195
|
-
pending "jruby-openssl support" if RUBY_PLATFORM ==
|
195
|
+
pending "jruby-openssl support" if RUBY_PLATFORM == "java"
|
196
196
|
|
197
197
|
with_ssl_sockets do |ssl_client|
|
198
198
|
expect(ssl_client.client_ca).to eq(ssl_client.to_io.client_ca)
|
@@ -201,7 +201,7 @@ describe Celluloid::IO::SSLSocket do
|
|
201
201
|
|
202
202
|
it "verifies peer certificates" do
|
203
203
|
# FIXME: JRuby seems to be giving the wrong result here o_O
|
204
|
-
pending "jruby-openssl support" if RUBY_PLATFORM ==
|
204
|
+
pending "jruby-openssl support" if RUBY_PLATFORM == "java"
|
205
205
|
|
206
206
|
with_ssl_sockets do |ssl_client, ssl_peer|
|
207
207
|
expect(ssl_client.verify_result).to eq(OpenSSL::X509::V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::TCPServer do
|
4
|
-
|
5
|
-
let(:payload) {
|
3
|
+
RSpec.describe Celluloid::IO::TCPServer, library: :IO do
|
4
|
+
context "#accept" do
|
5
|
+
let(:payload) { "ohai" }
|
6
6
|
let(:example_port) { assign_port }
|
7
7
|
|
8
8
|
it "can be initialized without a host" do
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::TCPSocket do
|
4
|
-
let(:payload) {
|
3
|
+
RSpec.describe Celluloid::IO::TCPSocket, library: :IO do
|
4
|
+
let(:payload) { "ohai" }
|
5
5
|
let(:example_port) { assign_port }
|
6
|
+
let(:logger) { Specs::FakeLogger.current }
|
6
7
|
|
7
8
|
context "inside Celluloid::IO" do
|
8
|
-
|
9
9
|
describe ".open" do
|
10
10
|
it "returns the open socket" do
|
11
11
|
server = ::TCPServer.new example_addr, example_port
|
@@ -22,10 +22,10 @@ describe Celluloid::IO::TCPSocket do
|
|
22
22
|
it "returns the block evaluation" do
|
23
23
|
server = ::TCPServer.new example_addr, example_port
|
24
24
|
thread = Thread.new { server.accept }
|
25
|
-
|
25
|
+
|
26
26
|
value = within_io_actor { Celluloid::IO::TCPSocket.open(example_addr, example_port) { true } }
|
27
27
|
expect(value).to be_truthy
|
28
|
-
|
28
|
+
|
29
29
|
server.close
|
30
30
|
thread.terminate
|
31
31
|
end
|
@@ -102,44 +102,47 @@ describe Celluloid::IO::TCPSocket do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it "raises Errno::ECONNREFUSED when the connection is refused" do
|
105
|
-
|
105
|
+
allow(logger).to receive(:crash).with("Actor crashed!", Errno::ECONNREFUSED)
|
106
|
+
expect do
|
106
107
|
within_io_actor { ::TCPSocket.new(example_addr, example_port) }
|
107
|
-
|
108
|
+
end.to raise_error(Errno::ECONNREFUSED)
|
108
109
|
end
|
109
110
|
|
110
|
-
context
|
111
|
+
context "eof?" do
|
111
112
|
it "blocks actor then returns by close" do
|
112
113
|
with_connected_sockets(example_port) do |subject, peer|
|
113
114
|
started_at = Time.now
|
114
|
-
Thread.new{ sleep 0.5; peer.close; }
|
115
|
+
Thread.new { sleep 0.5; peer.close; }
|
115
116
|
within_io_actor { subject.eof? }
|
116
117
|
expect(Time.now - started_at).to be > 0.5
|
117
118
|
end
|
118
119
|
end
|
119
|
-
|
120
|
+
|
120
121
|
it "blocks until gets the next byte" do
|
122
|
+
allow(logger).to receive(:crash).with("Actor crashed!", Celluloid::TaskTimeout)
|
121
123
|
with_connected_sockets(example_port) do |subject, peer|
|
122
124
|
peer << 0x00
|
123
125
|
peer.flush
|
124
|
-
expect
|
125
|
-
within_io_actor
|
126
|
+
expect do
|
127
|
+
within_io_actor do
|
126
128
|
subject.read(1)
|
127
|
-
Celluloid.timeout(0.5)
|
129
|
+
Celluloid.timeout(0.5) do
|
128
130
|
expect(subject.eof?).to be_falsey
|
129
|
-
|
130
|
-
|
131
|
-
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end.to raise_error(Celluloid::TaskTimeout)
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
138
|
context "readpartial" do
|
137
139
|
it "raises EOFError when reading from a closed socket" do
|
140
|
+
allow(logger).to receive(:crash).with("Actor crashed!", EOFError)
|
138
141
|
with_connected_sockets(example_port) do |subject, peer|
|
139
142
|
peer.close
|
140
|
-
expect
|
143
|
+
expect do
|
141
144
|
within_io_actor { subject.readpartial(payload.size) }
|
142
|
-
|
145
|
+
end.to raise_error(EOFError)
|
143
146
|
end
|
144
147
|
end
|
145
148
|
|
@@ -147,7 +150,8 @@ describe Celluloid::IO::TCPSocket do
|
|
147
150
|
pending "not implemented"
|
148
151
|
|
149
152
|
with_connected_sockets(example_port) do |subject, peer|
|
150
|
-
actor =
|
153
|
+
actor = with_wrapper_actor
|
154
|
+
allow(logger).to receive(:crash).with("Actor crashed!", IOError)
|
151
155
|
begin
|
152
156
|
read_future = actor.future.wrap do
|
153
157
|
subject.readpartial(payload.size)
|
@@ -164,7 +168,8 @@ describe Celluloid::IO::TCPSocket do
|
|
164
168
|
it "raises IOError when partial reading from a socket the peer closed" do
|
165
169
|
pending "async block running on receiver"
|
166
170
|
with_connected_sockets(example_port) do |subject, peer|
|
167
|
-
actor =
|
171
|
+
actor = with_wrapper_actor
|
172
|
+
allow(logger).to receive(:crash).with("Actor crashed!", IOError)
|
168
173
|
begin
|
169
174
|
actor.async.wrap { sleep 0.01; peer.close }
|
170
175
|
expect do
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::UDPSocket do
|
4
|
-
let(:payload) {
|
3
|
+
RSpec.describe Celluloid::IO::UDPSocket, library: :IO do
|
4
|
+
let(:payload) { "ohai" }
|
5
5
|
let(:example_port) { assign_port }
|
6
6
|
subject do
|
7
7
|
Celluloid::IO::UDPSocket.new.tap do |sock|
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe Celluloid::IO::UNIXServer do
|
3
|
+
RSpec.describe Celluloid::IO::UNIXServer, library: :IO do
|
4
4
|
let(:example_port) { assign_port }
|
5
5
|
|
6
6
|
describe "#accept" do
|
7
|
-
|
8
|
-
let(:payload) { 'ohai' }
|
7
|
+
let(:payload) { "ohai" }
|
9
8
|
|
10
9
|
context "inside Celluloid::IO" do
|
11
10
|
it "should be evented" do
|
@@ -15,7 +14,7 @@ describe Celluloid::IO::UNIXServer do
|
|
15
14
|
end
|
16
15
|
|
17
16
|
it "accepts a connection and returns a Celluloid::IO::UNIXSocket" do
|
18
|
-
pending if RUBY_PLATFORM ==
|
17
|
+
pending if RUBY_PLATFORM == "java"
|
19
18
|
with_unix_server do |subject|
|
20
19
|
thread = Thread.new { UNIXSocket.new(example_unix_sock) }
|
21
20
|
peer = within_io_actor { subject.accept }
|
@@ -30,9 +29,9 @@ describe Celluloid::IO::UNIXServer do
|
|
30
29
|
it "raises if server already up" do
|
31
30
|
with_unix_server do |subject|
|
32
31
|
within_io_actor do
|
33
|
-
expect
|
32
|
+
expect do
|
34
33
|
Celluloid::IO::UNIXServer.open(example_unix_sock)
|
35
|
-
|
34
|
+
end.to raise_error(Errno::EADDRINUSE)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -58,12 +57,11 @@ describe Celluloid::IO::UNIXServer do
|
|
58
57
|
|
59
58
|
it "raises if server already up" do
|
60
59
|
with_unix_server do |subject|
|
61
|
-
expect
|
60
|
+
expect do
|
62
61
|
Celluloid::IO::UNIXServer.open(example_unix_sock)
|
63
|
-
|
62
|
+
end.to raise_error(Errno::EADDRINUSE)
|
64
63
|
end
|
65
64
|
end
|
66
|
-
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|