agent 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22c5bf05cd41b0171dfce316431f8c42434fa3c1
4
- data.tar.gz: 96b5280262b5c4412fd366b6eb897031fa6fd709
3
+ metadata.gz: cb98d2b1912834ca7a296fb6dd1895c90c62d371
4
+ data.tar.gz: ea72c26e2be6e8bbd7ef710a2a2a87e0ef8141c6
5
5
  SHA512:
6
- metadata.gz: 3aa2fcea9b6cf2e55abd8ff3f3139f12f88e8fae2304bddb4d9076ce2d5ba99959fe64cd60291a24433da577aeea104fa6c4fcf7f1d9d9f1e98c88b8037a5b0f
7
- data.tar.gz: dbf9aedd6e99043347dba38415f80d7fa166afa1d36abcea0d3c61964d9b09e53f3b5c681e194836b3e7db390166580a749d801a2318ed5076b95a9c05a92618
6
+ metadata.gz: c3bcd58b2138db30b0c1f732673b7b9654f90b26358cf89c480efab7aa7ef8e9b5ae876949d726f64c93459cd8b995b35ff5202bf2665be23656632340b64094
7
+ data.tar.gz: 30116a292e6d8e36894b2da56638bda87a817be19355f4c7ffe0d70a243d3a11c9cc13e913705c4eec067f3a95c75badd62b42279c469874764adef23e20097e
@@ -1,21 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agent (0.9.1)
4
+ agent (0.10.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.3)
10
- rake (0.9.2.2)
11
- rspec (2.9.0)
12
- rspec-core (~> 2.9.0)
13
- rspec-expectations (~> 2.9.0)
14
- rspec-mocks (~> 2.9.0)
15
- rspec-core (2.9.0)
16
- rspec-expectations (2.9.0)
17
- diff-lcs (~> 1.1.3)
18
- rspec-mocks (2.9.0)
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.2.0)
12
+ rspec-core (~> 3.2.0)
13
+ rspec-expectations (~> 3.2.0)
14
+ rspec-mocks (~> 3.2.0)
15
+ rspec-core (3.2.0)
16
+ rspec-support (~> 3.2.0)
17
+ rspec-expectations (3.2.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.2.0)
20
+ rspec-mocks (3.2.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.2.0)
23
+ rspec-support (3.2.1)
19
24
 
20
25
  PLATFORMS
21
26
  java
@@ -61,8 +61,10 @@ module Agent
61
61
  def receive(options={})
62
62
  check_direction(:receive)
63
63
  q = queue
64
- return [nil, false] unless q
65
- q.pop(options)
64
+ return q.pop(options) if q
65
+ pop = Pop.new(options)
66
+ pop.close
67
+ [pop.object, false]
66
68
  end
67
69
  alias :pop :receive
68
70
 
@@ -1,3 +1,3 @@
1
1
  module Agent
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -13,8 +13,8 @@ describe Agent::BlockingOnce do
13
13
  r << 1
14
14
  end
15
15
 
16
- r.size.should == 1
17
- r.first.should == 1
16
+ expect(r.size).to eq(1)
17
+ expect(r.first).to eq(1)
18
18
  end
19
19
 
20
20
  it "should only execute the first block passed to it" do
@@ -28,8 +28,8 @@ describe Agent::BlockingOnce do
28
28
  r << 2
29
29
  end
30
30
 
31
- r.size.should == 1
32
- r.first.should == 1
31
+ expect(r.size).to eq(1)
32
+ expect(r.first).to eq(1)
33
33
  end
34
34
 
35
35
  it "should return the value returned from the block" do
@@ -37,18 +37,18 @@ describe Agent::BlockingOnce do
37
37
  1
38
38
  end
39
39
 
40
- value.should == 1
40
+ expect(value).to eq(1)
41
41
  end
42
42
 
43
43
  it "should return nil for value and an error if it has already been used" do
44
44
  value, error = @blocking_once.perform{ 1 }
45
- value.should == 1
46
- error.should be_nil
45
+ expect(value).to eq(1)
46
+ expect(error).to be_nil
47
47
 
48
48
  value, error = @blocking_once.perform{ 2 }
49
- value.should be_nil
50
- error.should_not be_nil
51
- error.should be_message("already performed")
49
+ expect(value).to be_nil
50
+ expect(error).not_to be_nil
51
+ expect(error).to be_message("already performed")
52
52
  end
53
53
 
54
54
  it "should roll back and allow the block to be executed again" do
@@ -78,7 +78,7 @@ describe Agent::BlockingOnce do
78
78
  finished_channel.close
79
79
 
80
80
  # Three sleeps at 0.1 == 0.3, so if it's less than 0.3...
81
- (Time.now.to_f - s).should < 0.3
81
+ expect(Time.now.to_f - s).to be < 0.3
82
82
  end
83
83
 
84
84
  it "should have minimal contention between threads when they contend for position" do
@@ -111,9 +111,9 @@ describe Agent::BlockingOnce do
111
111
  # wait for the finished channel to be completed
112
112
  2.times{ finished_channel.receive }
113
113
 
114
- r.size.should == 1
114
+ expect(r.size).to eq(1)
115
115
  # Onlt the first sleep should be performed, so things should quickly
116
- (Time.now.to_f - s).should be_within(0.05).of(0.15)
116
+ expect(Time.now.to_f - s).to be_within(0.05).of(0.15)
117
117
 
118
118
  waiting_channel.close
119
119
  finished_channel.close
@@ -5,13 +5,13 @@ describe Agent::Channel do
5
5
  context "naming" do
6
6
  it "should not be required" do
7
7
  c = nil
8
- lambda { c = channel!(String) }.should_not raise_error
8
+ expect { c = channel!(String) }.not_to raise_error
9
9
  c.close
10
10
  end
11
11
 
12
12
  it "be able to be set" do
13
13
  c = channel!(String, :name => "gibberish")
14
- c.name.should == "gibberish"
14
+ expect(c.name).to eq("gibberish")
15
15
  c.close
16
16
  end
17
17
  end
@@ -24,14 +24,14 @@ describe Agent::Channel do
24
24
  it "should support send only" do
25
25
  c = channel!(String, 3, :direction => :send)
26
26
 
27
- lambda { c << "hello" }.should_not raise_error
28
- lambda { c.push "hello" }.should_not raise_error
29
- lambda { c.send "hello" }.should_not raise_error
27
+ expect { c << "hello" }.not_to raise_error
28
+ expect { c.push "hello" }.not_to raise_error
29
+ expect { c.send "hello" }.not_to raise_error
30
30
 
31
- c.direction.should == :send
31
+ expect(c.direction).to eq(:send)
32
32
 
33
- lambda { c.pop }.should raise_error Agent::Errors::InvalidDirection
34
- lambda { c.receive }.should raise_error Agent::Errors::InvalidDirection
33
+ expect { c.pop }.to raise_error Agent::Errors::InvalidDirection
34
+ expect { c.receive }.to raise_error Agent::Errors::InvalidDirection
35
35
 
36
36
  c.close
37
37
  end
@@ -39,11 +39,11 @@ describe Agent::Channel do
39
39
  it "should support receive only" do
40
40
  c = channel!(String, :direction => :receive)
41
41
 
42
- lambda { c << "hello" }.should raise_error Agent::Errors::InvalidDirection
43
- lambda { c.push "hello" }.should raise_error Agent::Errors::InvalidDirection
44
- lambda { c.send "hello" }.should raise_error Agent::Errors::InvalidDirection
42
+ expect { c << "hello" }.to raise_error Agent::Errors::InvalidDirection
43
+ expect { c.push "hello" }.to raise_error Agent::Errors::InvalidDirection
44
+ expect { c.send "hello" }.to raise_error Agent::Errors::InvalidDirection
45
45
 
46
- c.direction.should == :receive
46
+ expect(c.direction).to eq(:receive)
47
47
 
48
48
  # timeout blocking receive calls
49
49
  timed_out = false
@@ -51,29 +51,29 @@ describe Agent::Channel do
51
51
  s.case(c, :receive)
52
52
  s.timeout(0.1){ timed_out = true }
53
53
  end
54
- timed_out.should == true
54
+ expect(timed_out).to eq(true)
55
55
  c.close
56
56
  end
57
57
 
58
58
  it "should default to bi-directional communication" do
59
59
  c = channel!(String, 1)
60
- lambda { c.send "hello" }.should_not raise_error
61
- lambda { c.receive }.should_not raise_error
60
+ expect { c.send "hello" }.not_to raise_error
61
+ expect { c.receive }.not_to raise_error
62
62
 
63
- c.direction.should == :bidirectional
63
+ expect(c.direction).to eq(:bidirectional)
64
64
  end
65
65
 
66
66
  it "should be able to be dup'd as a uni-directional channel" do
67
67
  c = channel!(String, 1)
68
68
 
69
69
  send_only = c.as_send_only
70
- send_only.direction.should == :send
70
+ expect(send_only.direction).to eq(:send)
71
71
 
72
72
  receive_only = c.as_receive_only
73
- receive_only.direction.should == :receive
73
+ expect(receive_only.direction).to eq(:receive)
74
74
 
75
75
  send_only.send("nifty")
76
- receive_only.receive[0].should == "nifty"
76
+ expect(receive_only.receive[0]).to eq("nifty")
77
77
  end
78
78
  end
79
79
 
@@ -83,35 +83,35 @@ describe Agent::Channel do
83
83
  end
84
84
 
85
85
  it "not raise an error the first time it is called" do
86
- lambda { @c.close }.should_not raise_error
87
- @c.closed?.should be_true
86
+ expect { @c.close }.not_to raise_error
87
+ expect(@c).to be_closed
88
88
  end
89
89
 
90
90
  it "should raise an error the second time it is called" do
91
91
  @c.close
92
- lambda { @c.close }.should raise_error(Agent::Errors::ChannelClosed)
92
+ expect { @c.close }.to raise_error(Agent::Errors::ChannelClosed)
93
93
  end
94
94
 
95
95
  it "should respond to closed?" do
96
- @c.closed?.should be_false
96
+ expect(@c).not_to be_closed
97
97
  @c.close
98
- @c.closed?.should be_true
98
+ expect(@c).to be_closed
99
99
  end
100
100
 
101
101
  it "should return that a receive was a failure when a channel is closed while being read from" do
102
102
  go!{ sleep 0.01; @c.close }
103
103
  _, ok = @c.receive
104
- ok.should be_false
104
+ expect(ok).to eq(false)
105
105
  end
106
106
 
107
107
  it "should raise an error when sending to a channel that has already been closed" do
108
108
  @c.close
109
- lambda { @c.send("a") }.should raise_error(Agent::Errors::ChannelClosed)
109
+ expect { @c.send("a") }.to raise_error(Agent::Errors::ChannelClosed)
110
110
  end
111
111
 
112
112
  it "should return [nil, false] when receiving from a channel that has already been closed" do
113
113
  @c.close
114
- @c.receive.should == [nil, false]
114
+ expect(@c.receive).to eq([nil, false])
115
115
  end
116
116
  end
117
117
 
@@ -121,28 +121,28 @@ describe Agent::Channel do
121
121
  end
122
122
 
123
123
  it "should deadlock on single thread", :vm => :ruby do
124
- lambda { @c.receive }.should raise_error
124
+ expect { @c.receive }.to raise_error
125
125
  end
126
126
 
127
127
  it "should not deadlock with multiple threads" do
128
128
  go!{ sleep(0.1); @c.push "hi" }
129
- lambda { @c.receive }.should_not raise_error
129
+ expect { @c.receive }.not_to raise_error
130
130
  end
131
131
  end
132
132
 
133
133
  context "typed" do
134
134
  it "should create a typed channel" do
135
- lambda { channel! }.should raise_error Agent::Errors::Untyped
135
+ expect { channel! }.to raise_error Agent::Errors::Untyped
136
136
  c = nil
137
- lambda { c = channel!(Integer) }.should_not raise_error
137
+ expect { c = channel!(Integer) }.not_to raise_error
138
138
  c.close
139
139
  end
140
140
 
141
141
  it "should reject messages of invalid type" do
142
142
  c = channel!(String)
143
143
  go!{ c.receive }
144
- lambda { c.send 1 }.should raise_error(Agent::Errors::InvalidType)
145
- lambda { c.send "hello" }.should_not raise_error
144
+ expect { c.send 1 }.to raise_error(Agent::Errors::InvalidType)
145
+ expect { c.send "hello" }.not_to raise_error
146
146
  c.close
147
147
  end
148
148
  end
@@ -158,9 +158,9 @@ describe Agent::Channel do
158
158
  c = channel!(String)
159
159
 
160
160
  go!{ sleep(0.15); c.send("hello") }
161
- c.receive[0].should == "hello"
161
+ expect(c.receive[0]).to eq("hello")
162
162
 
163
- (Time.now - n).should be_within(0.05).of(0.15)
163
+ expect(Time.now - n).to be_within(0.05).of(0.15)
164
164
  end
165
165
 
166
166
  it "should support buffered" do
@@ -175,8 +175,8 @@ describe Agent::Channel do
175
175
  s.timeout(0.1)
176
176
  end
177
177
 
178
- c.receive[0].should == "hello 1"
179
- c.receive[0].should == "hello 2"
178
+ expect(c.receive[0]).to eq("hello 1")
179
+ expect(c.receive[0]).to eq("hello 2")
180
180
  select! do |s|
181
181
  s.case(c, :receive){|v| r.push(v) }
182
182
  s.timeout(0.1)
@@ -201,15 +201,15 @@ describe Agent::Channel do
201
201
  # - http://golang.org/doc/effective_go.html#chan_of_chan
202
202
 
203
203
  it "should be a first class, serializable value" do
204
- lambda { Marshal.dump(@c) }.should_not raise_error
205
- lambda { Marshal.load(Marshal.dump(@c)).is_a?(Agent::Channel) }.should_not raise_error
204
+ expect { Marshal.dump(@c) }.not_to raise_error
205
+ expect { Marshal.load(Marshal.dump(@c)).is_a?(Agent::Channel) }.not_to raise_error
206
206
  end
207
207
 
208
208
  it "should be able to pass as a value on a different channel" do
209
209
  @c.send "hello"
210
210
 
211
211
  cm = Marshal.load(Marshal.dump(@c))
212
- cm.receive[0].should == "hello"
212
+ expect(cm.receive[0]).to eq("hello")
213
213
  end
214
214
  end
215
215
 
@@ -219,21 +219,21 @@ describe Agent::Channel do
219
219
  string = "foo"
220
220
  c.send(string)
221
221
  string_copy = c.receive[0]
222
- string_copy.should == string
223
- string_copy.object_id.should_not == string.object_id
222
+ expect(string_copy).to eq(string)
223
+ expect(string_copy.object_id).not_to eq(string.object_id)
224
224
  end
225
225
 
226
226
  it "skips marshaling when configured to" do
227
227
  c = channel!(String, 1, :skip_marshal => true)
228
228
  string = "foo"
229
229
  c.send(string)
230
- c.receive[0].object_id.should == string.object_id
230
+ expect(c.receive[0].object_id).to eq(string.object_id)
231
231
  end
232
232
 
233
233
  it "skips marshaling for channels by default" do
234
234
  c = channel!(Agent::Channel, 1)
235
235
  c.send(c)
236
- c.receive[0].object_id.should == c.object_id
236
+ expect(c.receive[0].object_id).to eq(c.object_id)
237
237
  end
238
238
  end
239
239
  end
@@ -6,10 +6,10 @@ describe Agent::Error do
6
6
  end
7
7
 
8
8
  it "should create an error" do
9
- @error.to_s.should == "msg"
9
+ expect(@error.to_s).to eq("msg")
10
10
  end
11
11
 
12
12
  it "should match the error's message" do
13
- @error.should be_message("msg")
13
+ expect(@error).to be_message("msg")
14
14
  end
15
15
  end
@@ -10,7 +10,7 @@ describe "Channel of Channels" do
10
10
  res = Request.new(n, channel!(Integer))
11
11
 
12
12
  reqs << res
13
- res.resultChan.receive[0].should == n+1
13
+ expect(res.resultChan.receive[0]).to eq(n+1)
14
14
  res.resultChan.close
15
15
  end
16
16
  end
@@ -52,7 +52,7 @@ describe "Channel of Channels" do
52
52
  res = Request.new(n, channel!(Integer))
53
53
 
54
54
  reqs << res
55
- res.resultChan.receive[0].should == n+1
55
+ expect(res.resultChan.receive[0]).to eq(n+1)
56
56
  res.resultChan.close
57
57
  end
58
58
  end
@@ -66,8 +66,8 @@ describe "Producer-Consumer" do
66
66
  go!(c, 3, s, &consumer)
67
67
 
68
68
  messages = [s.pop[0], s.pop[0]]
69
- messages.should include("producer finished")
70
- messages.should include("consumer finished")
69
+ expect(messages).to include("producer finished")
70
+ expect(messages).to include("consumer finished")
71
71
 
72
72
  c.close
73
73
  s.close
@@ -85,9 +85,9 @@ describe "Producer-Consumer" do
85
85
 
86
86
  go!(g, &producer)
87
87
 
88
- c.receive[0].should == 1
89
- c.receive[0].should == 2
90
- c.receive[0].should == 3
88
+ expect(c.receive[0]).to eq(1)
89
+ expect(c.receive[0]).to eq(2)
90
+ expect(c.receive[0]).to eq(3)
91
91
  c.close
92
92
  end
93
93
  end
@@ -69,7 +69,7 @@ describe "sieve of Eratosthenes" do
69
69
  end
70
70
  end
71
71
 
72
- result.should == [2,3,5,7,11,13,17,19]
72
+ expect(result).to eq([2,3,5,7,11,13,17,19])
73
73
  channels.each(&:close)
74
74
  end
75
75
 
@@ -143,7 +143,7 @@ describe "sieve of Eratosthenes" do
143
143
  end
144
144
  end
145
145
 
146
- result.should == [2,3,5,7,11,13,17,19]
146
+ expect(result).to eq([2,3,5,7,11,13,17,19])
147
147
  channels.each(&:close)
148
148
  end
149
149
  end
@@ -2,16 +2,16 @@ require "spec_helper"
2
2
 
3
3
  describe "Agent.go!" do
4
4
  it "should launch a 'goroutine' that is actually a thread" do
5
- Agent.go!{}.should be_a(Thread)
5
+ expect(Agent.go!{}).to be_a(Thread)
6
6
  end
7
7
 
8
8
  it "should pass into the thread any arguments passed to it" do
9
9
  b = nil
10
10
  Agent.go!(1){|a| b = a }.join
11
- b.should == 1
11
+ expect(b).to eq(1)
12
12
  end
13
13
 
14
14
  it "should raise an error if no block is passed" do
15
- lambda{ Agent.go! }.should raise_error(Agent::Errors::BlockMissing)
15
+ expect{ Agent.go! }.to raise_error(Agent::Errors::BlockMissing)
16
16
  end
17
17
  end