celluloid-io 0.16.2 → 0.16.5.pre0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ describe Celluloid::IO::TCPServer do
11
11
  context "inside Celluloid::IO" do
12
12
  it "should be evented" do
13
13
  with_tcp_server do |subject|
14
- within_io_actor { Celluloid::IO.evented? }.should be_true
14
+ expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
15
15
  end
16
16
  end
17
17
 
@@ -19,18 +19,18 @@ describe Celluloid::IO::TCPServer do
19
19
  with_tcp_server do |subject|
20
20
  thread = Thread.new { TCPSocket.new(example_addr, example_port) }
21
21
  peer = within_io_actor { subject.accept }
22
- peer.should be_a Celluloid::IO::TCPSocket
22
+ expect(peer).to be_a Celluloid::IO::TCPSocket
23
23
 
24
24
  client = thread.value
25
25
  client.write payload
26
- peer.read(payload.size).should eq payload
26
+ expect(peer.read(payload.size)).to eq payload
27
27
  end
28
28
  end
29
29
 
30
30
  context "outside Celluloid::IO" do
31
31
  it "should be blocking" do
32
32
  with_tcp_server do |subject|
33
- Celluloid::IO.should_not be_evented
33
+ expect(Celluloid::IO).not_to be_evented
34
34
  end
35
35
  end
36
36
 
@@ -38,11 +38,11 @@ describe Celluloid::IO::TCPServer do
38
38
  with_tcp_server do |subject|
39
39
  thread = Thread.new { TCPSocket.new(example_addr, example_port) }
40
40
  peer = subject.accept
41
- peer.should be_a Celluloid::IO::TCPSocket
41
+ expect(peer).to be_a Celluloid::IO::TCPSocket
42
42
 
43
43
  client = thread.value
44
44
  client.write payload
45
- peer.read(payload.size).should eq payload
45
+ expect(peer.read(payload.size)).to eq payload
46
46
  end
47
47
  end
48
48
  end
@@ -11,7 +11,7 @@ describe Celluloid::IO::TCPSocket do
11
11
  thread = Thread.new { server.accept }
12
12
 
13
13
  socket = within_io_actor { Celluloid::IO::TCPSocket.open(example_addr, example_port) }
14
- socket.should be_a(Celluloid::IO::TCPSocket)
14
+ expect(socket).to be_a(Celluloid::IO::TCPSocket)
15
15
 
16
16
  server.close
17
17
  thread.terminate
@@ -23,7 +23,7 @@ describe Celluloid::IO::TCPSocket do
23
23
  thread = Thread.new { server.accept }
24
24
 
25
25
  value = within_io_actor { Celluloid::IO::TCPSocket.open(example_addr, example_port) { true } }
26
- value.should be_true
26
+ expect(value).to be_truthy
27
27
 
28
28
  server.close
29
29
  thread.terminate
@@ -38,7 +38,7 @@ describe Celluloid::IO::TCPSocket do
38
38
  peer = thread.value
39
39
 
40
40
  peer << payload
41
- within_io_actor { socket.read(payload.size) }.should eq payload
41
+ expect(within_io_actor { socket.read(payload.size) }).to eq payload
42
42
 
43
43
  server.close
44
44
  socket.close
@@ -47,56 +47,56 @@ describe Celluloid::IO::TCPSocket do
47
47
 
48
48
  it "should be evented" do
49
49
  with_connected_sockets do |subject|
50
- within_io_actor { Celluloid::IO.evented? }.should be_true
50
+ expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
51
51
  end
52
52
  end
53
53
 
54
54
  it "read complete payload when nil size is given to #read" do
55
55
  with_connected_sockets do |subject, peer|
56
56
  peer << payload
57
- within_io_actor { subject.read(nil) }.should eq payload
57
+ expect(within_io_actor { subject.read(nil) }).to eq payload
58
58
  end
59
59
  end
60
60
 
61
61
  it "read complete payload when no size is given to #read" do
62
62
  with_connected_sockets do |subject, peer|
63
63
  peer << payload
64
- within_io_actor { subject.read }.should eq payload
64
+ expect(within_io_actor { subject.read }).to eq payload
65
65
  end
66
66
  end
67
67
 
68
68
  it "reads data" do
69
69
  with_connected_sockets do |subject, peer|
70
70
  peer << payload
71
- within_io_actor { subject.read(payload.size) }.should eq payload
71
+ expect(within_io_actor { subject.read(payload.size) }).to eq payload
72
72
  end
73
73
  end
74
74
 
75
75
  it "reads data in binary encoding" do
76
76
  with_connected_sockets do |subject, peer|
77
77
  peer << payload
78
- within_io_actor { subject.read(payload.size).encoding }.should eq Encoding::BINARY
78
+ expect(within_io_actor { subject.read(payload.size).encoding }).to eq Encoding::BINARY
79
79
  end
80
80
  end
81
81
 
82
82
  it "reads partial data" do
83
83
  with_connected_sockets do |subject, peer|
84
84
  peer << payload * 2
85
- within_io_actor { subject.readpartial(payload.size) }.should eq payload
85
+ expect(within_io_actor { subject.readpartial(payload.size) }).to eq payload
86
86
  end
87
87
  end
88
88
 
89
89
  it "reads partial data in binary encoding" do
90
90
  with_connected_sockets do |subject, peer|
91
91
  peer << payload * 2
92
- within_io_actor { subject.readpartial(payload.size).encoding }.should eq Encoding::BINARY
92
+ expect(within_io_actor { subject.readpartial(payload.size).encoding }).to eq Encoding::BINARY
93
93
  end
94
94
  end
95
95
 
96
96
  it "writes data" do
97
97
  with_connected_sockets do |subject, peer|
98
98
  within_io_actor { subject << payload }
99
- peer.read(payload.size).should eq payload
99
+ expect(peer.read(payload.size)).to eq payload
100
100
  end
101
101
  end
102
102
 
@@ -112,7 +112,7 @@ describe Celluloid::IO::TCPSocket do
112
112
  started_at = Time.now
113
113
  Thread.new{ sleep 0.5; peer.close; }
114
114
  within_io_actor { subject.eof? }
115
- (Time.now - started_at).should > 0.5
115
+ expect(Time.now - started_at).to be > 0.5
116
116
  end
117
117
  end
118
118
 
@@ -124,7 +124,7 @@ describe Celluloid::IO::TCPSocket do
124
124
  within_io_actor {
125
125
  subject.read(1)
126
126
  Celluloid.timeout(0.5) {
127
- subject.eof?.should be_false
127
+ expect(subject.eof?).to be_falsey
128
128
  }
129
129
  }
130
130
  }.to raise_error(Celluloid::Task::TimeoutError)
@@ -185,7 +185,7 @@ describe Celluloid::IO::TCPSocket do
185
185
  peer = thread.value
186
186
 
187
187
  peer << payload
188
- socket.read(payload.size).should eq payload
188
+ expect(socket.read(payload.size)).to eq payload
189
189
 
190
190
  server.close
191
191
  socket.close
@@ -194,28 +194,28 @@ describe Celluloid::IO::TCPSocket do
194
194
 
195
195
  it "should be blocking" do
196
196
  with_connected_sockets do |subject|
197
- Celluloid::IO.should_not be_evented
197
+ expect(Celluloid::IO).not_to be_evented
198
198
  end
199
199
  end
200
200
 
201
201
  it "reads data" do
202
202
  with_connected_sockets do |subject, peer|
203
203
  peer << payload
204
- subject.read(payload.size).should eq payload
204
+ expect(subject.read(payload.size)).to eq payload
205
205
  end
206
206
  end
207
207
 
208
208
  it "reads partial data" do
209
209
  with_connected_sockets do |subject, peer|
210
210
  peer << payload * 2
211
- subject.readpartial(payload.size).should eq payload
211
+ expect(subject.readpartial(payload.size)).to eq payload
212
212
  end
213
213
  end
214
214
 
215
215
  it "writes data" do
216
216
  with_connected_sockets do |subject, peer|
217
217
  subject << payload
218
- peer.read(payload.size).should eq payload
218
+ expect(peer.read(payload.size)).to eq payload
219
219
  end
220
220
  end
221
221
  end
@@ -12,25 +12,25 @@ describe Celluloid::IO::UDPSocket do
12
12
 
13
13
  context "inside Celluloid::IO" do
14
14
  it "should be evented" do
15
- within_io_actor { Celluloid::IO.evented? }.should be_true
15
+ expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
16
16
  end
17
17
 
18
18
  it "sends and receives packets" do
19
19
  within_io_actor do
20
20
  subject.send payload, 0, example_addr, example_port
21
- subject.recvfrom(payload.size).first.should == payload
21
+ expect(subject.recvfrom(payload.size).first).to eq(payload)
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  context "outside Celluloid::IO" do
27
27
  it "should be blocking" do
28
- Celluloid::IO.should_not be_evented
28
+ expect(Celluloid::IO).not_to be_evented
29
29
  end
30
30
 
31
31
  it "sends and receives packets" do
32
32
  subject.send payload, 0, example_addr, example_port
33
- subject.recvfrom(payload.size).first.should == payload
33
+ expect(subject.recvfrom(payload.size).first).to eq(payload)
34
34
  end
35
35
  end
36
36
  end
@@ -1,17 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Celluloid::IO::UNIXServer do
4
- describe "#accept" do
5
- before do
6
- pending "JRuby support" if defined?(JRUBY_VERSION)
4
+
5
+ if RUBY_PLATFORM == 'java'
6
+ before(:each) do
7
+ pending "jRuby support"
8
+ fail "Avoid potential deadlock under jRuby"
7
9
  end
10
+ end
11
+
12
+ describe "#accept" do
8
13
 
9
14
  let(:payload) { 'ohai' }
10
15
 
11
16
  context "inside Celluloid::IO" do
12
17
  it "should be evented" do
13
18
  with_unix_server do |subject|
14
- within_io_actor { Celluloid::IO.evented? }.should be_true
19
+ expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
15
20
  end
16
21
  end
17
22
 
@@ -19,11 +24,11 @@ describe Celluloid::IO::UNIXServer do
19
24
  with_unix_server do |subject|
20
25
  thread = Thread.new { UNIXSocket.new(example_unix_sock) }
21
26
  peer = within_io_actor { subject.accept }
22
- peer.should be_a Celluloid::IO::UNIXSocket
27
+ expect(peer).to be_a Celluloid::IO::UNIXSocket
23
28
 
24
29
  client = thread.value
25
30
  client.write payload
26
- peer.read(payload.size).should eq payload
31
+ expect(peer.read(payload.size)).to eq payload
27
32
  end
28
33
  end
29
34
 
@@ -40,7 +45,7 @@ describe Celluloid::IO::UNIXServer do
40
45
  context "outside Celluloid::IO" do
41
46
  it "should be blocking" do
42
47
  with_unix_server do |subject|
43
- Celluloid::IO.should_not be_evented
48
+ expect(Celluloid::IO).not_to be_evented
44
49
  end
45
50
  end
46
51
 
@@ -48,11 +53,11 @@ describe Celluloid::IO::UNIXServer do
48
53
  with_unix_server do |subject|
49
54
  thread = Thread.new { UNIXSocket.new(example_unix_sock) }
50
55
  peer = subject.accept
51
- peer.should be_a Celluloid::IO::UNIXSocket
56
+ expect(peer).to be_a Celluloid::IO::UNIXSocket
52
57
 
53
58
  client = thread.value
54
59
  client.write payload
55
- peer.read(payload.size).should eq payload
60
+ expect(peer.read(payload.size)).to eq payload
56
61
  end
57
62
  end
58
63
 
@@ -1,8 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Celluloid::IO::UNIXSocket do
4
- before do
5
- pending "JRuby support" if defined?(JRUBY_VERSION)
4
+
5
+ if RUBY_PLATFORM == 'java'
6
+ before(:each) do
7
+ pending "jRuby support"
8
+ fail "Avoid potential deadlock under jRuby"
9
+ end
6
10
  end
7
11
 
8
12
  let(:payload) { 'ohai' }
@@ -15,7 +19,7 @@ describe Celluloid::IO::UNIXSocket do
15
19
  peer = thread.value
16
20
 
17
21
  peer << payload
18
- within_io_actor { socket.read(payload.size) }.should eq payload
22
+ expect(within_io_actor { socket.read(payload.size) }).to eq payload
19
23
 
20
24
  server.close
21
25
  socket.close
@@ -25,56 +29,56 @@ describe Celluloid::IO::UNIXSocket do
25
29
 
26
30
  it "should be evented" do
27
31
  with_connected_unix_sockets do |subject|
28
- within_io_actor { Celluloid::IO.evented? }.should be_true
32
+ expect(within_io_actor { Celluloid::IO.evented? }).to be_truthy
29
33
  end
30
34
  end
31
35
 
32
36
  it "read complete payload when nil size is given to #read" do
33
37
  with_connected_unix_sockets do |subject, peer|
34
38
  peer << payload
35
- within_io_actor { subject.read(nil) }.should eq payload
39
+ expect(within_io_actor { subject.read(nil) }).to eq payload
36
40
  end
37
41
  end
38
42
 
39
43
  it "read complete payload when no size is given to #read" do
40
44
  with_connected_unix_sockets do |subject, peer|
41
45
  peer << payload
42
- within_io_actor { subject.read }.should eq payload
46
+ expect(within_io_actor { subject.read }).to eq payload
43
47
  end
44
48
  end
45
49
 
46
50
  it "reads data" do
47
51
  with_connected_unix_sockets do |subject, peer|
48
52
  peer << payload
49
- within_io_actor { subject.read(payload.size) }.should eq payload
53
+ expect(within_io_actor { subject.read(payload.size) }).to eq payload
50
54
  end
51
55
  end
52
56
 
53
57
  it "reads data in binary encoding" do
54
58
  with_connected_unix_sockets do |subject, peer|
55
59
  peer << payload
56
- within_io_actor { subject.read(payload.size).encoding }.should eq Encoding::BINARY
60
+ expect(within_io_actor { subject.read(payload.size).encoding }).to eq Encoding::BINARY
57
61
  end
58
62
  end
59
63
 
60
64
  it "reads partial data" do
61
65
  with_connected_unix_sockets do |subject, peer|
62
66
  peer << payload * 2
63
- within_io_actor { subject.readpartial(payload.size) }.should eq payload
67
+ expect(within_io_actor { subject.readpartial(payload.size) }).to eq payload
64
68
  end
65
69
  end
66
70
 
67
71
  it "reads partial data in binary encoding" do
68
72
  with_connected_unix_sockets do |subject, peer|
69
73
  peer << payload * 2
70
- within_io_actor { subject.readpartial(payload.size).encoding }.should eq Encoding::BINARY
74
+ expect(within_io_actor { subject.readpartial(payload.size).encoding }).to eq Encoding::BINARY
71
75
  end
72
76
  end
73
77
 
74
78
  it "writes data" do
75
79
  with_connected_unix_sockets do |subject, peer|
76
80
  within_io_actor { subject << payload }
77
- peer.read(payload.size).should eq payload
81
+ expect(peer.read(payload.size)).to eq payload
78
82
  end
79
83
  end
80
84
 
@@ -99,7 +103,7 @@ describe Celluloid::IO::UNIXSocket do
99
103
  started_at = Time.now
100
104
  Thread.new{ sleep 0.5; peer.close; }
101
105
  within_io_actor { subject.eof? }
102
- (Time.now - started_at).should > 0.5
106
+ expect(Time.now - started_at).to be > 0.5
103
107
  end
104
108
  end
105
109
 
@@ -111,7 +115,7 @@ describe Celluloid::IO::UNIXSocket do
111
115
  within_io_actor {
112
116
  subject.read(1)
113
117
  Celluloid.timeout(0.5) {
114
- subject.eof?.should be_false
118
+ expect(subject.eof?).to be_falsey
115
119
  }
116
120
  }
117
121
  }.to raise_error(Celluloid::Task::TimeoutError)
@@ -128,7 +132,7 @@ describe Celluloid::IO::UNIXSocket do
128
132
  peer = thread.value
129
133
 
130
134
  peer << payload
131
- socket.read(payload.size).should eq payload
135
+ expect(socket.read(payload.size)).to eq payload
132
136
 
133
137
  server.close
134
138
  socket.close
@@ -138,28 +142,28 @@ describe Celluloid::IO::UNIXSocket do
138
142
 
139
143
  it "should be blocking" do
140
144
  with_connected_unix_sockets do |subject|
141
- Celluloid::IO.should_not be_evented
145
+ expect(Celluloid::IO).not_to be_evented
142
146
  end
143
147
  end
144
148
 
145
149
  it "reads data" do
146
150
  with_connected_unix_sockets do |subject, peer|
147
151
  peer << payload
148
- subject.read(payload.size).should eq payload
152
+ expect(subject.read(payload.size)).to eq payload
149
153
  end
150
154
  end
151
155
 
152
156
  it "reads partial data" do
153
157
  with_connected_unix_sockets do |subject, peer|
154
158
  peer << payload * 2
155
- subject.readpartial(payload.size).should eq payload
159
+ expect(subject.readpartial(payload.size)).to eq payload
156
160
  end
157
161
  end
158
162
 
159
163
  it "writes data" do
160
164
  with_connected_unix_sockets do |subject, peer|
161
165
  subject << payload
162
- peer.read(payload.size).should eq payload
166
+ expect(peer.read(payload.size)).to eq payload
163
167
  end
164
168
  end
165
169
  end
data/spec/spec_helper.rb CHANGED
@@ -35,7 +35,7 @@ class ExampleActor
35
35
  end
36
36
  end
37
37
 
38
- EXAMPLE_PORT = 12345
38
+ EXAMPLE_PORT = 12345 + Random.rand(1024)
39
39
 
40
40
  def example_addr; '127.0.0.1'; end
41
41
  def example_port; EXAMPLE_PORT; end
@@ -72,8 +72,7 @@ end
72
72
 
73
73
  def with_connected_sockets
74
74
  with_tcp_server do |server|
75
- # FIXME: client isn't actually a Celluloid::IO::TCPSocket yet
76
- client = ::TCPSocket.new(example_addr, example_port)
75
+ client = Celluloid::IO::TCPSocket.new(example_addr, example_port)
77
76
  peer = server.accept
78
77
 
79
78
  begin