abundance 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/garden.rb +9 -19
- data/lib/garden_cycles.rb +98 -46
- data/lib/rows.rb +1 -1
- data/lib/rows_paths.rb +1 -1
- data/lib/toolshed.rb +58 -23
- data/test/tc_burst.rb +1 -1
- data/test/tc_high_api.rb +44 -33
- data/test/tc_multi_gardener.rb +6 -4
- data/test/tc_robustness.rb +1 -1
- metadata +2 -2
data/lib/garden.rb
CHANGED
@@ -38,25 +38,15 @@ class Garden
|
|
38
38
|
set_my_socket_as_a(:garden)
|
39
39
|
|
40
40
|
loop do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
save_crop_for(message_block)
|
51
|
-
when :growth
|
52
|
-
report_growth(message_block)
|
53
|
-
when :harvest
|
54
|
-
harvest_some(message_block)
|
55
|
-
when :close
|
56
|
-
close_all(message_block)
|
57
|
-
else
|
58
|
-
message_block[2] = false
|
59
|
-
socket_send(message_block)
|
41
|
+
route_message_blocks
|
42
|
+
seed_available_rows
|
43
|
+
|
44
|
+
ready = select(@reader[:sockets],@writer[:sockets],nil,10)
|
45
|
+
unless ready.nil?
|
46
|
+
readable, writable = ready[0..1]
|
47
|
+
|
48
|
+
crop_writable(writable) if writable
|
49
|
+
sprout_readable(readable) if readable
|
60
50
|
end
|
61
51
|
end
|
62
52
|
end
|
data/lib/garden_cycles.rb
CHANGED
@@ -10,46 +10,98 @@ class Garden
|
|
10
10
|
def set_my_containers
|
11
11
|
@close_message_block = nil; @full_crop_message_block = nil
|
12
12
|
@init_message_block = nil; @seed_all_message_block = nil
|
13
|
-
@harvest_queue = []; @waiting_rows = []; @
|
14
|
-
@seeds = []; @sprouts = []; @crops = []
|
13
|
+
@harvest_queue = []; @waiting_rows = []; @message_block_queue = []
|
14
|
+
@seeds = []; @sprouts = []; @crops = []; @id = 0
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
17
|
+
def sprout_readable(readable)
|
18
|
+
readable.each do |i_socket|
|
19
|
+
if i_socket == @my_socket
|
20
|
+
add_readable(i_socket)
|
21
|
+
else
|
22
|
+
readable_main(i_socket)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def crop_writable(writable)
|
28
|
+
writable.each do |o_socket|
|
29
|
+
if @writer[:buffer][o_socket.to_s] == '' || @writer[:buffer][o_socket.to_s] == nil
|
30
|
+
remove_writable(o_socket)
|
31
|
+
else
|
32
|
+
write_raw(o_socket)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def route_message_blocks
|
38
|
+
until @message_block_queue.empty?
|
39
|
+
message_block = @message_block_queue.shift
|
40
|
+
case message_block[0]
|
41
|
+
when :seed
|
42
|
+
place_seed_in_queue(message_block)
|
43
|
+
when :row
|
44
|
+
this_row_is_available(message_block)
|
45
|
+
when :crop
|
46
|
+
save_crop_for(message_block)
|
47
|
+
when :growth
|
48
|
+
report_growth(message_block)
|
49
|
+
when :harvest
|
50
|
+
harvest_some(message_block)
|
51
|
+
when :close
|
52
|
+
close_all(message_block)
|
53
|
+
else
|
54
|
+
message_block[2] = false
|
55
|
+
add_writable(message_block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def seed_available_rows
|
61
|
+
catch :fill_rows do
|
62
|
+
loop do
|
63
|
+
throw :fill_rows if @waiting_rows.empty?
|
64
|
+
if @seed_all_message_block && @seed_all_message_block[4][:row_done].size != @seed_all_message_block[1]
|
65
|
+
row_socket_path = @waiting_rows.shift
|
66
|
+
unless @seed_all_message_block[4][:row_done].include?( row_socket_path )
|
67
|
+
add_writable([:seed,:all,@seed_all_message_block[2],row_socket_path])
|
68
|
+
@seed_all_message_block[4][:row_done] << row_socket_path
|
69
|
+
else
|
70
|
+
@waiting_rows << row_socket_path
|
71
|
+
end
|
72
|
+
elsif @init_message_block && @init_message_block[4][:row_done].size != @init_message_block[2]
|
73
|
+
row_socket_path = @waiting_rows.shift
|
74
|
+
unless @init_message_block[4][:row_done].include?( row_socket_path )
|
75
|
+
add_writable([:seed,:init,'init_status',row_socket_path])
|
76
|
+
@init_message_block[4][:row_done] << row_socket_path
|
77
|
+
else
|
78
|
+
@waiting_rows << row_socket_path
|
79
|
+
end
|
80
|
+
elsif ! @seeds.empty?
|
81
|
+
seed = @seeds.shift; @sprouts[seed[:id]] = seed
|
82
|
+
add_writable([:seed,:sprout,seed,@waiting_rows.shift])
|
83
|
+
elsif @close_message_block && ! @waiting_rows.empty?
|
84
|
+
add_writable([:seed,:quit,nil,@waiting_rows.shift])
|
85
|
+
else
|
86
|
+
throw :fill_rows
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def readable_main(i_socket)
|
95
|
+
message_block = read_message_block(i_socket)
|
96
|
+
@message_block_queue << message_block
|
97
|
+
@reader[:sockets].delete(i_socket) if @reader[:sockets].include?(i_socket)
|
46
98
|
end
|
47
99
|
|
48
100
|
def place_seed_in_queue(message_block)
|
49
101
|
case message_block[1]
|
50
102
|
when :one
|
51
103
|
@id += 1; @seeds << {:id => @id , :seed => message_block[2]}
|
52
|
-
message_block[2] = @id;
|
104
|
+
message_block[2] = @id; add_writable(message_block)
|
53
105
|
else
|
54
106
|
@seed_all_message_block = Array.new(message_block)
|
55
107
|
@seed_all_message_block[4] = {:row_done => [], :crops => []}
|
@@ -72,7 +124,7 @@ class Garden
|
|
72
124
|
seed = @seeds.shift; @sprouts[seed[:id]] = seed
|
73
125
|
message_block = [:row, :sprout, seed, message_block[3]]
|
74
126
|
end
|
75
|
-
|
127
|
+
add_writable(message_block)
|
76
128
|
end
|
77
129
|
|
78
130
|
def save_crop_for(message_block)
|
@@ -81,23 +133,23 @@ class Garden
|
|
81
133
|
@sprouts[message_block[2][:id]] = nil
|
82
134
|
@crops[message_block[2][:id]] = message_block[2]
|
83
135
|
if @harvest_queue[message_block[2][:id]]
|
84
|
-
|
136
|
+
add_writable(message_block[0..2]+[@harvest_queue[message_block[2][:id]]])
|
85
137
|
@crops[message_block[2][:id]] = @harvest_queue[message_block[2][:id]] = nil
|
86
138
|
elsif @full_crop_message_block && @seeds.compact.empty? && @sprouts.compact.empty?
|
87
|
-
|
139
|
+
add_writable(message_block[0..1]+[@crops.compact,@full_crop_message_block[3]])
|
88
140
|
@crops.clear; @full_crop_message_block = nil
|
89
141
|
end
|
90
142
|
when :seed_all
|
91
143
|
@seed_all_message_block[4][:crops] << message_block[2]
|
92
144
|
if @seed_all_message_block[4][:crops].size == @seed_all_message_block[1]
|
93
145
|
@seed_all_message_block[2] = @seed_all_message_block[4][:crops]; @seed_all_message_block[4] = nil
|
94
|
-
|
146
|
+
add_writable(@seed_all_message_block.compact); @seed_all_message_block = nil
|
95
147
|
end
|
96
148
|
when :init
|
97
149
|
@init_message_block[4][:crops] << message_block[2]
|
98
150
|
if @init_message_block[4][:crops].size == @init_message_block[2]
|
99
151
|
@init_message_block[2] = @init_message_block[4][:crops]; @init_message_block[4] = nil
|
100
|
-
|
152
|
+
add_writable(@init_message_block.compact); @init_message_block = nil
|
101
153
|
end
|
102
154
|
end
|
103
155
|
end
|
@@ -117,7 +169,7 @@ class Garden
|
|
117
169
|
else
|
118
170
|
message_block[2] = false
|
119
171
|
end
|
120
|
-
|
172
|
+
add_writable(message_block)
|
121
173
|
end
|
122
174
|
|
123
175
|
def harvest_some(message_block)
|
@@ -125,26 +177,26 @@ class Garden
|
|
125
177
|
when :one
|
126
178
|
unless message_block[2].nil?
|
127
179
|
if @crops[message_block[2]]
|
128
|
-
|
180
|
+
add_writable(message_block[0..1]+[@crops[message_block[2]],message_block[3]])
|
129
181
|
@crops[message_block[2]] = nil
|
130
182
|
else
|
131
183
|
@harvest_queue[message_block[2]] = message_block[3]
|
132
184
|
end
|
133
185
|
else
|
134
|
-
message_block[2] = false;
|
186
|
+
message_block[2] = false; add_writable(message_block)
|
135
187
|
end
|
136
188
|
when :all
|
137
189
|
message_block[2] = {:seeds => @seeds, :sprouts => @sprouts.compact, :crops => @crops.compact}
|
138
|
-
|
190
|
+
add_writable(message_block)
|
139
191
|
when :seed
|
140
|
-
message_block[2] = @seeds;
|
192
|
+
message_block[2] = @seeds; add_writable(message_block)
|
141
193
|
when :sprout
|
142
|
-
message_block[2] = @sprouts.compact;
|
194
|
+
message_block[2] = @sprouts.compact; add_writable(message_block)
|
143
195
|
when :crop
|
144
|
-
message_block[2] = @crops.compact;
|
196
|
+
message_block[2] = @crops.compact; add_writable(message_block); @crops.clear
|
145
197
|
when :full_crop
|
146
198
|
if @seeds.compact.empty? && @sprouts.compact.empty?
|
147
|
-
message_block[2] = @crops.compact;
|
199
|
+
message_block[2] = @crops.compact; add_writable(message_block); @crops.clear
|
148
200
|
else
|
149
201
|
@full_crop_message_block = Array.new(message_block)
|
150
202
|
end
|
@@ -152,7 +204,7 @@ class Garden
|
|
152
204
|
@init_message_block = Array.new(message_block)
|
153
205
|
@init_message_block[4] = {:row_done => [], :crops => []}
|
154
206
|
else
|
155
|
-
message_block[2] = false;
|
207
|
+
message_block[2] = false; add_writable(message_block)
|
156
208
|
end
|
157
209
|
end
|
158
210
|
|
data/lib/rows.rb
CHANGED
@@ -52,7 +52,7 @@ class Garden
|
|
52
52
|
t2 = Thread.new do
|
53
53
|
loop do
|
54
54
|
if $seed.nil?
|
55
|
-
message_block = socket_duplex([:row,:row
|
55
|
+
message_block = socket_duplex([:row,:row,@my_socket_path,@garden_path])
|
56
56
|
case message_block[1]
|
57
57
|
when :sprout
|
58
58
|
sprout(message_block)
|
data/lib/rows_paths.rb
CHANGED
@@ -22,7 +22,7 @@ class Garden
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def init
|
25
|
-
$init = {:seed => 'init_status', :message => 'No Init Message', :id => Process.pid} if $init.nil?
|
25
|
+
$init = {:seed => 'init_status', :success => false, :message => 'No Init Message', :id => Process.pid} if $init.nil?
|
26
26
|
socket_send([:crop,:init,$init,@garden_path])
|
27
27
|
end
|
28
28
|
|
data/lib/toolshed.rb
CHANGED
@@ -32,10 +32,12 @@ module Toolshed
|
|
32
32
|
case role
|
33
33
|
when :garden
|
34
34
|
set_my_socket(Process.pid.to_s)
|
35
|
+
@reader = {:sockets => [@my_socket], :buffer => {}}
|
36
|
+
@writer = {:sockets => [], :buffer => {}}
|
35
37
|
when :gardener
|
36
38
|
set_garden_path(garden_pid)
|
37
39
|
set_my_socket(Process.pid.to_s + Time.now.to_i.to_s + rand(10000).to_s)
|
38
|
-
|
40
|
+
when :row
|
39
41
|
set_garden_path(garden_pid)
|
40
42
|
set_my_socket(Process.pid.to_s)
|
41
43
|
end
|
@@ -63,12 +65,43 @@ module Toolshed
|
|
63
65
|
# * _server_socket_path_ = a UNIXServer socket path for the packets to be sent to
|
64
66
|
def socket_duplex(message_block)
|
65
67
|
send_block(message_block)
|
66
|
-
|
68
|
+
client = @my_socket.accept
|
69
|
+
recv_whole_block(client)
|
67
70
|
end
|
68
71
|
|
69
72
|
# The +socket_recv+ method calls _accept_ on a UNIXServer socket, receives all the packets from a UNIXSocket sender, join the packets back as the original block message.
|
70
73
|
def socket_recv
|
71
|
-
|
74
|
+
client = @my_socket.accept
|
75
|
+
recv_whole_block(client)
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_readable(socket)
|
79
|
+
client = socket.accept
|
80
|
+
@reader[:sockets] << client
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_writable(message_block)
|
84
|
+
client = UNIXSocket.open(message_block[3])
|
85
|
+
@writer[:sockets] << client
|
86
|
+
@writer[:buffer][client.to_s] = Marshal.dump(message_block)
|
87
|
+
end
|
88
|
+
|
89
|
+
def remove_writable(client)
|
90
|
+
@writer[:sockets].delete(client)
|
91
|
+
@writer[:buffer].delete(client.to_s)
|
92
|
+
client.close
|
93
|
+
end
|
94
|
+
|
95
|
+
def read_raw(client)
|
96
|
+
client.recvfrom(@@block_size)[0]
|
97
|
+
end
|
98
|
+
|
99
|
+
def write_raw(client)
|
100
|
+
client.send(@writer[:buffer][client.to_s].slice!(0..@@block_size-1),0)
|
101
|
+
end
|
102
|
+
|
103
|
+
def read_message_block(client)
|
104
|
+
recv_whole_block(client)
|
72
105
|
end
|
73
106
|
|
74
107
|
private
|
@@ -96,10 +129,28 @@ module Toolshed
|
|
96
129
|
@garden_path = socket_path(garden_pid.to_s)
|
97
130
|
end
|
98
131
|
|
132
|
+
# The +send_block+ method sends a block to a server socket.
|
133
|
+
# === Parameters
|
134
|
+
# * _command_ = command part of the sent packet
|
135
|
+
# * _data_ = data part of the sent packet
|
136
|
+
# * _server_socket_path_ = the UNIXServer socket path to send to
|
137
|
+
def send_block(message_block)
|
138
|
+
begin
|
139
|
+
client = UNIXSocket.open(message_block[3])
|
140
|
+
block = Marshal.dump(message_block[0..2] + [@my_socket_path])
|
141
|
+
client.send(block,0)
|
142
|
+
client.close
|
143
|
+
rescue Errno::EADDRINUSE
|
144
|
+
retry
|
145
|
+
rescue Errno::ECONNREFUSED
|
146
|
+
retry
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
99
150
|
# The +recv_whole_block+ method loops receiving a sent block as packets, rebuilding the whole block and joining it.
|
100
|
-
def recv_whole_block
|
151
|
+
def recv_whole_block(client)
|
152
|
+
block = String.new
|
101
153
|
begin
|
102
|
-
client = @my_socket.accept; block = []
|
103
154
|
catch :whole_block do
|
104
155
|
loop do
|
105
156
|
packet = client.recvfrom(@@block_size)[0]
|
@@ -110,26 +161,10 @@ module Toolshed
|
|
110
161
|
end
|
111
162
|
end
|
112
163
|
end
|
113
|
-
|
114
|
-
|
115
|
-
retry
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# The +send_block+ method sends a block to a server socket.
|
120
|
-
# === Parameters
|
121
|
-
# * _command_ = command part of the sent packet
|
122
|
-
# * _data_ = data part of the sent packet
|
123
|
-
# * _server_socket_path_ = the UNIXServer socket path to send to
|
124
|
-
def send_block(message_block)
|
125
|
-
begin
|
126
|
-
client = UNIXSocket.open(message_block[3])
|
127
|
-
client.send(Marshal.dump(message_block[0..2] + [@my_socket_path]),0)
|
128
|
-
client.close
|
164
|
+
message_block = Marshal.load(block)
|
165
|
+
return message_block
|
129
166
|
rescue Errno::EADDRINUSE
|
130
167
|
retry
|
131
|
-
rescue Errno::ECONNREFUSED
|
132
|
-
retry
|
133
168
|
end
|
134
169
|
end
|
135
170
|
|
data/test/tc_burst.rb
CHANGED
data/test/tc_high_api.rb
CHANGED
@@ -24,11 +24,11 @@ class TestHighAPI < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def teardown
|
26
26
|
final = @g.close
|
27
|
-
assert_kind_of(Hash,final)
|
28
|
-
assert_equal(3,final.size)
|
29
|
-
assert_not_nil(final[:seeds])
|
30
|
-
assert_not_nil(final[:sprouts])
|
31
|
-
assert_not_nil(final[:crops])
|
27
|
+
assert_kind_of(Hash,final,"close method didn't return a Hash, it returned: #{final.inspect}")
|
28
|
+
assert_equal(3,final.size,"Hash returned on close has wrong size, here it is: #{final.inspect}")
|
29
|
+
assert_not_nil(final[:seeds],"close Hash has Nil value for :seeds instead of an Array")
|
30
|
+
assert_not_nil(final[:sprouts],"close Hash has Nil value for :sprouts instead of an Array")
|
31
|
+
assert_not_nil(final[:crops],"close Hash has Nil value for :crops instead of an Array")
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
@@ -37,7 +37,11 @@ class TestHighAPI < Test::Unit::TestCase
|
|
37
37
|
@g = Abundance.gardener(:rows => @rows, :init_timeout => 3) do
|
38
38
|
Abundance.init_status(true,Process.pid)
|
39
39
|
Abundance.grow do |seed|
|
40
|
-
|
40
|
+
if seed.sprout.nil?
|
41
|
+
seed.crop(false, "gardener has no seed")
|
42
|
+
else
|
43
|
+
seed.crop(true, "gardener: #{seed.sprout}")
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -45,7 +49,8 @@ class TestHighAPI < Test::Unit::TestCase
|
|
45
49
|
def reality_check
|
46
50
|
assert_instance_of(Gardener,@g)
|
47
51
|
|
48
|
-
check_init
|
52
|
+
check_init
|
53
|
+
check_false
|
49
54
|
check_seed_harvest # leaves no crops in the queue
|
50
55
|
check_full_harvest # also leaves no crops in the queue
|
51
56
|
check_deep_harvest # may leave crap behind, so needs to come last of the harvest
|
@@ -56,25 +61,31 @@ class TestHighAPI < Test::Unit::TestCase
|
|
56
61
|
|
57
62
|
def check_init
|
58
63
|
@g.init_status.each do |init|
|
59
|
-
assert_not_nil(init[:message])
|
60
|
-
assert_not_nil(init[:success])
|
61
|
-
assert_not_nil(init[:pid])
|
64
|
+
assert_not_nil(init[:message],"init :message value is Nil instead of String")
|
65
|
+
assert_not_nil(init[:success],"init :success value is Nil instead of True || False")
|
66
|
+
assert_not_nil(init[:pid],"init :pid value is Nil instead of Numeric")
|
62
67
|
|
63
|
-
assert_not_equal(Process.pid,init[:message])
|
64
|
-
assert_equal(init[:message],init[:pid])
|
68
|
+
assert_not_equal(Process.pid,init[:message],"init has same pid than test process, something has gone wrong in the forking...")
|
69
|
+
assert_equal(init[:message],init[:pid],"init :pid should be the row pid, it isn't")
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
def check_false
|
74
|
+
id = @g.seed(nil)
|
75
|
+
answer = @g.harvest(:one,id)
|
76
|
+
assert_equal(false,answer[:success],"failed returning a seed for which :success value was false")
|
77
|
+
end
|
78
|
+
|
68
79
|
def check_seed_harvest
|
69
80
|
id = @g.seed(Process.pid)
|
70
|
-
assert_kind_of(Integer,id)
|
81
|
+
assert_kind_of(Integer,id,"seed method failed returning and Integer")
|
71
82
|
|
72
83
|
answer = @g.harvest(:one,id)
|
73
|
-
assert_kind_of(Hash,answer)
|
74
|
-
assert_equal(Process.pid,answer[:seed])
|
75
|
-
assert_equal(id,answer[:id])
|
76
|
-
assert_equal(true,answer[:success])
|
77
|
-
assert_equal("gardener: #{Process.pid}",answer[:message])
|
84
|
+
assert_kind_of(Hash,answer,"harvest :one method failed to return a seed Hash, got #{answer.inspect} instead.")
|
85
|
+
assert_equal(Process.pid,answer[:seed], "harvesting showed a problem with seeding flow, seed[:seed] had wrong return value")
|
86
|
+
assert_equal(id,answer[:id], "harvesting showed a problem with seeding flow, seed[:id] had wrong return value")
|
87
|
+
assert_equal(true,answer[:success], "harvesting showed a problem with seeding flow, seed[:success] had wrong return value")
|
88
|
+
assert_equal("gardener: #{Process.pid}",answer[:message], "harvesting showed a problem with seeding flow, seed[:message] had wrong return value")
|
78
89
|
end
|
79
90
|
|
80
91
|
def check_full_harvest
|
@@ -83,7 +94,7 @@ class TestHighAPI < Test::Unit::TestCase
|
|
83
94
|
queue_items[num] = @g.seed(num)
|
84
95
|
end
|
85
96
|
full_crop = @g.harvest(:full_crop)
|
86
|
-
assert_equal(25,full_crop.size)
|
97
|
+
assert_equal(25,full_crop.size, "a :full_crop harvest has shown some seeds were lost during processing")
|
87
98
|
results = []
|
88
99
|
queue_items.each do |num,id|
|
89
100
|
success = false
|
@@ -92,20 +103,20 @@ class TestHighAPI < Test::Unit::TestCase
|
|
92
103
|
end
|
93
104
|
results << success
|
94
105
|
end
|
95
|
-
assert(results[0] == true && results.uniq.size == 1)
|
106
|
+
assert(results[0] == true && results.uniq.size == 1, "a :full_crop harvest has shown processing to be inconsistent amongst rows")
|
96
107
|
end
|
97
108
|
|
98
109
|
def check_growth
|
99
110
|
progress = @g.growth(:progress)
|
100
|
-
assert_kind_of(String,progress)
|
101
|
-
assert(progress.to_f >= 0 && progress.to_f <= 1)
|
111
|
+
assert_kind_of(String,progress, "the growth :progress method doesn't return proper value")
|
112
|
+
assert(progress.to_f >= 0 && progress.to_f <= 1, "the growth :progress method doesn't return a value between 0 and 1")
|
102
113
|
|
103
114
|
seeds_growth = @g.growth(:seed)
|
104
|
-
assert_kind_of(Integer,seeds_growth)
|
115
|
+
assert_kind_of(Integer,seeds_growth, "the growth :seed method doesn't return proper value")
|
105
116
|
sprouts_growth = @g.growth(:sprout)
|
106
|
-
assert_kind_of(Integer,sprouts_growth)
|
117
|
+
assert_kind_of(Integer,sprouts_growth, "the growth :sprout method doesn't return proper value")
|
107
118
|
crops_growth = @g.growth(:crop)
|
108
|
-
assert_kind_of(Integer,crops_growth)
|
119
|
+
assert_kind_of(Integer,crops_growth, "the growth :crop method doesn't return proper value")
|
109
120
|
end
|
110
121
|
|
111
122
|
def check_deep_harvest
|
@@ -115,11 +126,11 @@ class TestHighAPI < Test::Unit::TestCase
|
|
115
126
|
end
|
116
127
|
|
117
128
|
all = @g.harvest(:all)
|
118
|
-
assert_kind_of(Hash,all)
|
119
|
-
assert_equal(25,all[:seeds].size + all[:sprouts].size + all[:crops].size)
|
120
|
-
seeds_harvest = @g.harvest(:seed); assert_kind_of(Array,seeds_harvest)
|
121
|
-
sprouts_harvest = @g.harvest(:sprout); assert_kind_of(Array,sprouts_harvest)
|
122
|
-
crops_harvest = @g.harvest(:crop); assert_kind_of(Array,crops_harvest)
|
129
|
+
assert_kind_of(Hash,all, "the harvest :all method doesn't return a Hash as supposed")
|
130
|
+
assert_equal(25,all[:seeds].size + all[:sprouts].size + all[:crops].size, "the harvest :all method returns a total of items not coherent with amount of seeded items")
|
131
|
+
seeds_harvest = @g.harvest(:seed); assert_kind_of(Array,seeds_harvest, "the harvest :seed method doesn't return an Array as supposed")
|
132
|
+
sprouts_harvest = @g.harvest(:sprout); assert_kind_of(Array,sprouts_harvest, "the harvest :sprout method doesn't return an Array as supposed")
|
133
|
+
crops_harvest = @g.harvest(:crop); assert_kind_of(Array,crops_harvest, "the harvest :crop method doesn't return an Array as supposed")
|
123
134
|
results = []
|
124
135
|
queue_items.each do |num,id|
|
125
136
|
success = false
|
@@ -134,14 +145,14 @@ class TestHighAPI < Test::Unit::TestCase
|
|
134
145
|
end
|
135
146
|
results << success
|
136
147
|
end
|
137
|
-
assert(results[0] == true && results.uniq.size == 1)
|
148
|
+
assert(results[0] == true && results.uniq.size == 1, "the harvest :all method has shown processing to be inconsistent amongst rows")
|
138
149
|
end
|
139
150
|
|
140
151
|
def check_seed_all
|
141
152
|
all = @g.seed_all("all")
|
142
|
-
assert_equal(@rows,all.size)
|
153
|
+
assert_equal(@rows,all.size, "the seed_all method has missed some rows in its seeding, harvesting, or both")
|
143
154
|
all.map! { |seed| seed[:message] == "gardener: all" }
|
144
|
-
assert( all.uniq.size == 1 && all[0] == true )
|
155
|
+
assert( all.uniq.size == 1 && all[0] == true, "the seed_all method shows an inconsistency amongst row processing")
|
145
156
|
end
|
146
157
|
|
147
158
|
end
|
data/test/tc_multi_gardener.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'abundance'
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestMultiGardener < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_two_gardeners
|
8
8
|
@rows = 2
|
@@ -43,9 +43,11 @@ class TestHighAPI < Test::Unit::TestCase
|
|
43
43
|
answer1 = @g1.harvest(:one,id1)
|
44
44
|
answer2 = @g2.harvest(:one,id2)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
assert_not_equal(answer1[:message],answer2[:message], "trouble getting two gardeners have their own answers... maybe it only one after all!")
|
47
|
+
assert_match(/gardener1.*/, answer1[:message], "looks like one of the gardener has got its answer wrong")
|
48
|
+
assert_match(/gardener2.*/, answer2[:message], "looks like one of the gardener has got its answer wrong")
|
49
|
+
assert_no_match(/gardener2.*/, answer1[:message], "looks like the gardeners are having trouble keeping their identities, one reference the other")
|
50
|
+
assert_no_match(/gardener1.*/, answer2[:message], "looks like the gardeners are having trouble keeping their identities, one reference the other")
|
49
51
|
end
|
50
52
|
|
51
53
|
end
|
data/test/tc_robustness.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abundance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis-Philippe Perron
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|