oflow 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,7 @@ module OFlow
35
35
  end
36
36
 
37
37
  def links()
38
- lnk = Link.new(@name, nil)
38
+ lnk = Link.new(@name, nil, nil)
39
39
  lnk.instance_variable_set(:@target, self)
40
40
  { nil => lnk }
41
41
  end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module OFlow
3
3
  # Current version of the module.
4
- VERSION = '0.6.0'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -1,12 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
9
- require 'test/unit'
6
+ require 'helper'
10
7
  require 'oflow'
11
8
  require 'oflow/test'
12
9
 
@@ -33,12 +30,13 @@ class Busy < ::OFlow::Actor
33
30
 
34
31
  end # Busy
35
32
 
36
- class BalancerTest < ::Test::Unit::TestCase
33
+ class BalancerTest < ::MiniTest::Test
37
34
 
38
35
  def test_balancer_fair
36
+ env = ::OFlow::Env.new('')
39
37
  balancer = nil
40
38
  collector = nil
41
- ::OFlow::Env.flow('fair') { |f|
39
+ env.flow('fair') { |f|
42
40
  f.task('balance', ::OFlow::Actors::Balancer) { |t|
43
41
  balancer = t
44
42
  t.link(:one, :one, nil)
@@ -58,21 +56,25 @@ class BalancerTest < ::Test::Unit::TestCase
58
56
  collector = t.actor
59
57
  }
60
58
  }
59
+ env.prepare()
60
+ env.start()
61
+
61
62
  9.times { |i| balancer.receive(nil, ::OFlow::Box.new(i)) }
62
- ::OFlow::Env.flush()
63
+ env.flush()
63
64
  counts = {}
64
65
  collector.collection.each { |a| counts[a[0]] = counts.fetch(a[0], 0) + 1 }
65
66
 
66
67
  assert_equal(counts[:one], counts[:two], 'all counts should be the same')
67
68
  assert_equal(counts[:two], counts[:three], 'all counts should be the same')
68
69
 
69
- ::OFlow::Env.clear()
70
+ env.clear()
70
71
  end
71
72
 
72
73
  def test_balancer_less_busy
74
+ env = ::OFlow::Env.new('')
73
75
  balancer = nil
74
76
  collector = nil
75
- ::OFlow::Env.flow('less-busy') { |f|
77
+ env.flow('less-busy') { |f|
76
78
  f.task('balance', ::OFlow::Actors::Balancer) { |t|
77
79
  balancer = t
78
80
  t.link(:one, :one, nil)
@@ -92,8 +94,11 @@ class BalancerTest < ::Test::Unit::TestCase
92
94
  collector = t.actor
93
95
  }
94
96
  }
97
+ env.prepare()
98
+ env.start()
99
+
95
100
  40.times { |i| balancer.receive(nil, ::OFlow::Box.new(i)); sleep(0.005) }
96
- ::OFlow::Env.flush()
101
+ env.flush()
97
102
  counts = {}
98
103
  collector.collection.each { |a| counts[a[0]] = counts.fetch(a[0], 0) + 1 }
99
104
  #puts "*** #{counts}"
@@ -101,7 +106,7 @@ class BalancerTest < ::Test::Unit::TestCase
101
106
  assert(counts[:one] > counts[:two], 'one is faster and should have processed more than two')
102
107
  assert(counts[:two] > counts[:three], 'two is faster and should have processed more than three')
103
108
 
104
- ::OFlow::Env.clear()
109
+ env.clear()
105
110
  end
106
111
 
107
112
  end # BalancerTest
@@ -1,13 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
6
+ require 'helper'
9
7
  require 'net/http'
10
- require 'test/unit'
11
8
  require 'oflow'
12
9
  require 'oflow/test'
13
10
 
@@ -25,17 +22,21 @@ class Reply < ::OFlow::Actor
25
22
 
26
23
  end # Reply
27
24
 
28
- class HttpServerTest < ::Test::Unit::TestCase
25
+ class HttpServerTest < ::MiniTest::Test
29
26
 
30
27
  def test_httpserver
31
- ::OFlow::Env.flow('http-server', port: 6060) { |f|
32
- f.task('server', ::OFlow::Actors::HttpServer) { |t|
28
+ env = ::OFlow::Env.new('')
29
+ env.flow('http-server') { |f|
30
+ f.task('server', ::OFlow::Actors::HttpServer, port: 6060) { |t|
33
31
  t.link(nil, :reply, nil)
34
32
  }
35
33
  f.task(:reply, Reply) { |t|
36
34
  t.link(nil, :server, :reply)
37
35
  }
38
36
  }
37
+ env.prepare()
38
+ env.start()
39
+
39
40
  # GET
40
41
  uri = URI('http://localhost:6060/test?a=1&b=two')
41
42
  reply = Net::HTTP.get(uri)
@@ -50,8 +51,8 @@ class HttpServerTest < ::Test::Unit::TestCase
50
51
  assert_equal(%|{:id=>2, :method=>\"POST\", :protocol=>\"HTTP/1.1\", :path=>\"/test\", :args=>nil, \"Accept-Encoding\"=>\"gzip;q=1.0,deflate;q=0.6,identity;q=0.3\", \"Accept\"=>\"*/*\", \"User-Agent\"=>\"Ruby\", \"Host\"=>\"localhost:6060\", \"Content-Type\"=>\"application/x-www-form-urlencoded\", \"Content-Length\"=>9, :body=>\"a=1&b=two\"}|,
51
52
  reply, 'expected reply from POST')
52
53
 
53
- ::OFlow::Env.flush()
54
- ::OFlow::Env.clear()
54
+ env.flush()
55
+ env.clear()
55
56
  end
56
57
 
57
58
  end # HttpServerTest
@@ -1,16 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
9
- require 'test/unit'
6
+ require 'helper'
10
7
  require 'stringio'
11
8
  require 'oflow'
12
9
 
13
- class LogTest < ::Test::Unit::TestCase
10
+ class LogTest < ::MiniTest::Test
14
11
 
15
12
  def test_log
16
13
  stream = StringIO.new()
@@ -1,12 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
9
- require 'test/unit'
6
+ require 'helper'
10
7
  require 'oflow'
11
8
  require 'oflow/test'
12
9
 
@@ -39,12 +36,13 @@ class Multiplier < ::OFlow::Actor
39
36
 
40
37
  end # Multiplier
41
38
 
42
- class MergerTest < ::Test::Unit::TestCase
39
+ class MergerTest < ::MiniTest::Test
43
40
 
44
41
  def test_merger_any
42
+ env = ::OFlow::Env.new('')
45
43
  start = nil
46
44
  collector = nil
47
- ::OFlow::Env.flow('merge') { |f|
45
+ env.flow('merge') { |f|
48
46
  f.task(:split, Splitter) { |t|
49
47
  start = t
50
48
  t.link(:left, :one, nil)
@@ -63,21 +61,25 @@ class MergerTest < ::Test::Unit::TestCase
63
61
  collector = t.actor
64
62
  }
65
63
  }
64
+ env.prepare()
65
+ env.start()
66
+
66
67
  start.receive(nil, ::OFlow::Box.new(1))
67
- ::OFlow::Env.flush()
68
+ env.flush()
68
69
 
69
70
  result = collector.collection[0]
70
71
  assert_equal(2, result.size, 'should be 2 values in the box')
71
72
  assert(result.include?(2), 'box should include 2')
72
73
  assert(result.include?(3), 'box should include 3')
73
74
 
74
- ::OFlow::Env.clear()
75
+ env.clear()
75
76
  end
76
77
 
77
78
  def test_merger_tracker
79
+ env = ::OFlow::Env.new('')
78
80
  start = nil
79
81
  collector = nil
80
- ::OFlow::Env.flow('merge') { |f|
82
+ env.flow('merge') { |f|
81
83
  f.task(:split, Splitter) { |t|
82
84
  start = t
83
85
  t.link(:left, :one, nil)
@@ -96,11 +98,14 @@ class MergerTest < ::Test::Unit::TestCase
96
98
  collector = t.actor
97
99
  }
98
100
  }
101
+ env.prepare()
102
+ env.start()
103
+
99
104
  tracker = ::OFlow::Tracker.create('start')
100
105
  start.receive(nil, ::OFlow::Box.new(1, tracker))
101
106
  tracker2 = ::OFlow::Tracker.create('start2')
102
107
  start.receive(nil, ::OFlow::Box.new(10, tracker2))
103
- ::OFlow::Env.flush()
108
+ env.flush()
104
109
 
105
110
  box = collector.collection[0]
106
111
  result = box.contents
@@ -109,19 +114,19 @@ class MergerTest < ::Test::Unit::TestCase
109
114
  assert(result.include?(3), 'box should include 3')
110
115
 
111
116
  t = box.tracker()
112
- assert_not_nil(t, 'should have a tracker')
117
+ refute_nil(t, 'should have a tracker')
113
118
  assert_equal(t.id, tracker.id, 'tracker id should be carried through')
114
119
  track = t.track
115
120
 
116
121
  assert_equal('start', track[0].location)
117
- assert_equal(':merge:split', track[1].location)
122
+ assert_equal('merge:split', track[1].location)
118
123
  split = track[2].map { |a| a.map { |stamp| stamp.location } }
119
124
 
120
125
  assert_equal(2, split.size, 'should be 2 values in the split')
121
- assert(split.include?([':merge:one']), 'split should include [merge:one]')
122
- assert(split.include?([':merge:two']), 'split should include [merge:two]')
123
- assert_equal(':merge:merge', track[3].location)
124
- assert_equal(':merge:collector', track[4].location)
126
+ assert(split.include?(['merge:one']), 'split should include [merge:one]')
127
+ assert(split.include?(['merge:two']), 'split should include [merge:two]')
128
+ assert_equal('merge:merge', track[3].location)
129
+ assert_equal('merge:collector', track[4].location)
125
130
 
126
131
  box = collector.collection[1]
127
132
  result = box.contents
@@ -129,7 +134,7 @@ class MergerTest < ::Test::Unit::TestCase
129
134
  assert(result.include?(20), 'box should include 20')
130
135
  assert(result.include?(30), 'box should include 30')
131
136
 
132
- ::OFlow::Env.clear()
137
+ env.clear()
133
138
  end
134
139
 
135
140
  end # MergerTest
@@ -1,18 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
9
- require 'test/unit'
6
+ require 'helper'
10
7
  require 'oflow'
11
8
  require 'oflow/test'
12
9
 
13
- class PersisterTest < ::Test::Unit::TestCase
10
+ class PersisterTest < ::MiniTest::Test
14
11
 
15
12
  def test_persister_config
13
+ root_dir = File.dirname(File.dirname(__FILE__))
16
14
  t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Persister, state: ::OFlow::Task::BLOCKED,
17
15
  dir: 'db/something',
18
16
  key_path: 'key',
@@ -22,7 +20,7 @@ class PersisterTest < ::Test::Unit::TestCase
22
20
  with_seq_num: true,
23
21
  historic: true,
24
22
  seq_path: 'seq')
25
- assert_equal('db/something', t.actor.dir, 'dir set from options')
23
+ assert_equal(File.join(root_dir, 'db/something'), t.actor.dir, 'dir set from options')
26
24
  assert_equal('key', t.actor.key_path, 'key_path set from options')
27
25
  assert_equal('seq', t.actor.seq_path, 'seq_path set from options')
28
26
  assert_equal('data', t.actor.data_path, 'data_path set from options')
@@ -32,7 +30,7 @@ class PersisterTest < ::Test::Unit::TestCase
32
30
  `rm -r #{t.actor.dir}`
33
31
 
34
32
  t = ::OFlow::Test::ActorWrap.new('persist', ::OFlow::Actors::Persister, state: ::OFlow::Task::BLOCKED)
35
- assert_equal('db/test/persist', t.actor.dir, 'dir set from options')
33
+ assert_equal(File.join(root_dir, 'db/test/persist'), t.actor.dir, 'dir set from options')
36
34
  assert_equal('key', t.actor.key_path, 'key_path set from options')
37
35
  assert_equal('seq', t.actor.seq_path, 'seq_path set from options')
38
36
  assert_equal(true, t.actor.caching?, 'cache set from options')
@@ -1,24 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- [ File.dirname(__FILE__),
5
- File.join(File.dirname(__FILE__), "../../lib"),
6
- File.join(File.dirname(__FILE__), "..")
7
- ].each { |path| $: << path unless $:.include?(path) }
4
+ $: << File.dirname(File.dirname(__FILE__)) unless $:.include? File.dirname(File.dirname(__FILE__))
8
5
 
9
- require 'test/unit'
6
+ require 'helper'
10
7
  require 'oflow'
11
8
  require 'oflow/test'
12
9
 
13
10
  require 'collector'
14
11
 
15
- class TimerTest < ::Test::Unit::TestCase
12
+ class TimerTest < ::MiniTest::Test
16
13
 
17
14
  def test_timer_period_repeat
15
+ env = ::OFlow::Env.new('')
18
16
  period = 0.1
19
17
  timer = nil
20
18
  collector = nil
21
- ::OFlow::Env.flow('one-time') { |f|
19
+ env.flow('one-time') { |f|
22
20
  f.task('once', ::OFlow::Actors::Timer, repeat: 4, period: period) { |t|
23
21
  timer = t
24
22
  t.link(:ping, :collector, :tick)
@@ -27,7 +25,10 @@ class TimerTest < ::Test::Unit::TestCase
27
25
  collector = t.actor
28
26
  }
29
27
  }
30
- ::OFlow::Env.flush()
28
+ env.prepare()
29
+ env.start()
30
+
31
+ env.flush()
31
32
  prev = nil
32
33
  ticks = collector.collection.map do |t|
33
34
  tf = t[2].to_f
@@ -49,7 +50,7 @@ class TimerTest < ::Test::Unit::TestCase
49
50
  assert(-limit < dif && dif < limit, "Verify timer fires are within 10% of expected. (dif: #{dif}, limit: #{limit})")
50
51
  end
51
52
 
52
- ::OFlow::Env.clear()
53
+ env.clear()
53
54
  end
54
55
 
55
56
  def test_timer_options_start
@@ -65,7 +66,7 @@ class TimerTest < ::Test::Unit::TestCase
65
66
  assert_equal(Time, t.actor.start.class, 'is the start time a Time?')
66
67
  assert(0.1 > (Time.now() + 2 - t.actor.start), 'is the start time now + 2?')
67
68
 
68
- assert_raise(::OFlow::ConfigError) do
69
+ assert_raises(::OFlow::ConfigError) do
69
70
  ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, start: 'now')
70
71
  end
71
72
  end
@@ -82,22 +83,25 @@ class TimerTest < ::Test::Unit::TestCase
82
83
  assert_equal(Time, t.actor.stop.class, 'is the stop time a Time?')
83
84
  assert(0.1 > (Time.now() + 2 - t.actor.stop), 'is the stop time now + 2?')
84
85
 
85
- assert_raise(::OFlow::ConfigError) do
86
+ assert_raises(::OFlow::ConfigError) do
86
87
  ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, stop: 'now')
87
88
  end
88
89
  end
89
90
 
90
91
  def test_timer_options_period
91
- t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: nil, state: ::OFlow::Task::BLOCKED)
92
- assert_equal(nil, t.actor.period, 'is the period nil?')
93
-
92
+ assert_raises(::OFlow::ConfigError) do
93
+ ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: nil, state: ::OFlow::Task::BLOCKED)
94
+ end
94
95
  t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: 2, state: ::OFlow::Task::BLOCKED)
95
96
  assert_equal(2, t.actor.period, 'is the period 2?')
96
97
 
97
98
  t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: 2.0, state: ::OFlow::Task::BLOCKED)
98
99
  assert_equal(2.0, t.actor.period, 'is the period 2.0?')
99
100
 
100
- assert_raise(::OFlow::ConfigError) do
101
+ t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: "2.5", state: ::OFlow::Task::BLOCKED)
102
+ assert_equal(2.5, t.actor.period, 'is the period 2.5?')
103
+
104
+ assert_raises(::OFlow::ConfigError) do
101
105
  ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, period: 'now')
102
106
  end
103
107
  end
@@ -109,7 +113,7 @@ class TimerTest < ::Test::Unit::TestCase
109
113
  t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, repeat: 2, state: ::OFlow::Task::BLOCKED)
110
114
  assert_equal(2, t.actor.repeat, 'is the repeat 2?')
111
115
 
112
- assert_raise(::OFlow::ConfigError) do
116
+ assert_raises(::OFlow::ConfigError) do
113
117
  ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, repeat: 2.0)
114
118
  end
115
119
  end
@@ -124,7 +128,7 @@ class TimerTest < ::Test::Unit::TestCase
124
128
  t = ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, with_tracker: true, state: ::OFlow::Task::BLOCKED)
125
129
  assert_equal(true, t.actor.with_tracker, 'is the with_tracker true?')
126
130
 
127
- assert_raise(::OFlow::ConfigError) do
131
+ assert_raises(::OFlow::ConfigError) do
128
132
  ::OFlow::Test::ActorWrap.new('test', ::OFlow::Actors::Timer, with_tracker: 'now')
129
133
  end
130
134
 
@@ -144,10 +148,11 @@ class TimerTest < ::Test::Unit::TestCase
144
148
  end
145
149
 
146
150
  def test_timer_perform_period
151
+ env = ::OFlow::Env.new('')
147
152
  period = 0.1
148
153
  timer = nil
149
154
  collector = nil
150
- ::OFlow::Env.flow('one-time') { |f|
155
+ env.flow('one-time') { |f|
151
156
  f.task('once', ::OFlow::Actors::Timer, repeat: 2, period: 2) { |t|
152
157
  timer = t
153
158
  t.link(:ping, :collector, :tick)
@@ -156,8 +161,11 @@ class TimerTest < ::Test::Unit::TestCase
156
161
  collector = t.actor
157
162
  }
158
163
  }
164
+ env.prepare()
165
+ env.start()
166
+
159
167
  timer.receive(:period, ::OFlow::Box.new(period))
160
- ::OFlow::Env.flush()
168
+ env.flush()
161
169
  prev = nil
162
170
  ticks = collector.collection.map do |t|
163
171
  tf = t[2].to_f
@@ -179,14 +187,15 @@ class TimerTest < ::Test::Unit::TestCase
179
187
  assert(-limit < dif && dif < limit, "Verify timer fires are within 10% of expected. (dif: #{dif}, limit: #{limit})")
180
188
  end
181
189
 
182
- ::OFlow::Env.clear()
190
+ env.clear()
183
191
  end
184
192
 
185
193
  def test_timer_perform_repeat
194
+ env = ::OFlow::Env.new('')
186
195
  repeat = 2
187
196
  timer = nil
188
197
  collector = nil
189
- ::OFlow::Env.flow('one-time') { |f|
198
+ env.flow('one-time') { |f|
190
199
  f.task('once', ::OFlow::Actors::Timer, repeat: 4, period: 0.1) { |t|
191
200
  timer = t
192
201
  t.link(:ping, :collector, :tick)
@@ -195,18 +204,22 @@ class TimerTest < ::Test::Unit::TestCase
195
204
  collector = t.actor
196
205
  }
197
206
  }
207
+ env.prepare()
208
+ env.start()
209
+
198
210
  timer.receive(:repeat, ::OFlow::Box.new(repeat))
199
- ::OFlow::Env.flush()
211
+ env.flush()
200
212
  assert_equal(2, collector.collection.size)
201
213
 
202
- ::OFlow::Env.clear()
214
+ env.clear()
203
215
  end
204
216
 
205
217
  def test_timer_perform_start
218
+ env = ::OFlow::Env.new('')
206
219
  now = Time.now()
207
220
  timer = nil
208
221
  collector = nil
209
- ::OFlow::Env.flow('one-time') { |f|
222
+ env.flow('one-time') { |f|
210
223
  f.task('once', ::OFlow::Actors::Timer, repeat: 1, period: 0.1, start: 2) { |t|
211
224
  timer = t
212
225
  t.link(:ping, :collector, :tick)
@@ -215,18 +228,22 @@ class TimerTest < ::Test::Unit::TestCase
215
228
  collector = t.actor
216
229
  }
217
230
  }
231
+ env.prepare()
232
+ env.start()
233
+
218
234
  timer.receive(:start, ::OFlow::Box.new(nil))
219
- ::OFlow::Env.flush()
235
+ env.flush()
220
236
  first_fire = collector.collection[0][2] - now
221
237
  assert(0.01 > first_fire, "first fire was at #{first_fire}, expected less than 0.01 msecs?")
222
238
 
223
- ::OFlow::Env.clear()
239
+ env.clear()
224
240
  end
225
241
 
226
242
  def test_timer_perform_stop
243
+ env = ::OFlow::Env.new('')
227
244
  timer = nil
228
245
  collector = nil
229
- ::OFlow::Env.flow('one-time') { |f|
246
+ env.flow('one-time') { |f|
230
247
  f.task('once', ::OFlow::Actors::Timer, repeat: 10, period: 0.1, stop: 2) { |t|
231
248
  timer = t
232
249
  t.link(:ping, :collector, :tick)
@@ -235,17 +252,21 @@ class TimerTest < ::Test::Unit::TestCase
235
252
  collector = t.actor
236
253
  }
237
254
  }
255
+ env.prepare()
256
+ env.start()
257
+
238
258
  timer.receive(:stop, ::OFlow::Box.new(0.25))
239
- ::OFlow::Env.flush()
259
+ env.flush()
240
260
  assert_equal(3, collector.collection.size)
241
261
 
242
- ::OFlow::Env.clear()
262
+ env.clear()
243
263
  end
244
264
 
245
265
  def test_timer_perform_label
266
+ env = ::OFlow::Env.new('')
246
267
  timer = nil
247
268
  collector = nil
248
- ::OFlow::Env.flow('one-time') { |f|
269
+ env.flow('one-time') { |f|
249
270
  f.task('once', ::OFlow::Actors::Timer, repeat: 2, period: 0.1, label: 'first') { |t|
250
271
  timer = t
251
272
  t.link(:ping, :collector, :tick)
@@ -254,17 +275,21 @@ class TimerTest < ::Test::Unit::TestCase
254
275
  collector = t.actor
255
276
  }
256
277
  }
278
+ env.prepare()
279
+ env.start()
280
+
257
281
  timer.receive(:label, ::OFlow::Box.new('second'))
258
- ::OFlow::Env.flush()
282
+ env.flush()
259
283
  assert_equal(['first', 'second'], collector.collection.map { |x| x[0] })
260
284
 
261
- ::OFlow::Env.clear()
285
+ env.clear()
262
286
  end
263
287
 
264
288
  def test_timer_perform_tracker
289
+ env = ::OFlow::Env.new('')
265
290
  timer = nil
266
291
  collector = nil
267
- ::OFlow::Env.flow('one-time') { |f|
292
+ env.flow('one-time') { |f|
268
293
  f.task('once', ::OFlow::Actors::Timer, repeat: 2, period: 0.1, with_tracker: false) { |t|
269
294
  timer = t
270
295
  t.link(:ping, :collector, :tick)
@@ -273,11 +298,14 @@ class TimerTest < ::Test::Unit::TestCase
273
298
  collector = t.actor
274
299
  }
275
300
  }
301
+ env.prepare()
302
+ env.start()
303
+
276
304
  timer.receive(:with_tracker, ::OFlow::Box.new(true))
277
- ::OFlow::Env.flush()
305
+ env.flush()
278
306
  assert_equal([false, true], collector.collection.map { |x| !x.tracker.nil? })
279
307
 
280
- ::OFlow::Env.clear()
308
+ env.clear()
281
309
  end
282
310
 
283
311
  end # TimerTest