Skip to content

Commit

Permalink
purge to purge! and added engine#purge! (teardown)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Oct 6, 2009
1 parent f19f653 commit 8dd054c
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 9 deletions.
2 changes: 2 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ restart tests :

[ ] implement kill_process! (kill_expression! ?)

[ ] engine.force_reply_to_parent(fei) ?

14 changes: 14 additions & 0 deletions lib/ruote/engine/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ def shutdown
end
end

# Cleans the engine and its services. Used by the test framework.
#
def purge!

wqueue.purge!
# at first, try to make work stop

@context.values.each do |service|
next if service == self
next if service.is_a?(Ruote::Workqueue)
service.purge! if service.respond_to?(:purge!)
end
end

def add_service (key, o)

remove_service(key)
Expand Down
7 changes: 7 additions & 0 deletions lib/ruote/evt/fs_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def shutdown
@bucket.close
end

# Clears this tracker. Mostly used by the test framework.
#
def purge!

@bucket.save(Set.new)
end

protected

def listeners
Expand Down
7 changes: 7 additions & 0 deletions lib/ruote/evt/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def unregister (fei)
save(listeners.delete(fei))
end

# Clears this tracker. Mostly used by the test framework.
#
def purge!

@listeners = Set.new
end

protected

def listeners
Expand Down
7 changes: 7 additions & 0 deletions lib/ruote/queue/thread_workqueue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def shutdown

while @queue.size > 0; Thread.pass; end
end

# Basically, it returns when there are no more jobs... It's like #shutdown.
#
def purge!

shutdown
end
end
end

6 changes: 4 additions & 2 deletions lib/ruote/storage/cache_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ def to_s
r << real_storage.to_s
end

def purge
# Clears this storage. Mostly used by the test framework.
#
def purge!

@cache.clear
real_storage.purge if real_storage.respond_to?(:purge)
real_storage.purge! if real_storage.respond_to?(:purge!)
end

protected
Expand Down
9 changes: 8 additions & 1 deletion lib/ruote/storage/fs_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,18 @@ def discard_all_tickets (fei)
# nothing to do
end

# Clears this storage. Mostly used by the test framework.
#
def purge!

Dir[File.join(@path, '*')].each { |d| FileUtils.rm_rf(d) }
end

protected

def all_filenames

Dir["#{@path}/**/*.ruote"]
Dir[File.join(@path, '**', '*.ruote')]
end

def dir_for (wfid)
Expand Down
7 changes: 7 additions & 0 deletions lib/ruote/storage/hash_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def [] (fei)

exp
end

# Clears this storage. Mostly used by the test framework.
#
def purge!

clear
end
end
end

13 changes: 13 additions & 0 deletions lib/ruote/time/fs_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def to_h
operate { |jobs| jobs.inject({}) { |h, j| h[j.job_id] = j; h } }
end

def purge!

operate { |jobs| jobs.clear }
end

protected

def operate (skip=false, &block)
Expand Down Expand Up @@ -167,6 +172,14 @@ def shutdown
@jq.shutdown
@cjq.shutdown
end

# Clears all jobs. Mostly used by the test framework.
#
def purge!

@jq.purge!
@cjq.purge!
end
end
end

7 changes: 7 additions & 0 deletions lib/ruote/time/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ def jobs
@scheduler.jobs
end

# Clears all jobs. Mostly used by the test framework.
#
def purge!

@scheduler.all_jobs { |j| @scheduler.unschedule(j.job_id) }
end

protected

def reload
Expand Down
8 changes: 3 additions & 5 deletions test/functional/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def setup

def teardown

@engine.shutdown

purge_engine
@engine.shutdown
end

def assert_log_count (count, &block)
Expand Down Expand Up @@ -180,9 +179,8 @@ def assert_no_remaining_expressions (wfid, opts)

def purge_engine

@engine.context.values.each do |s|
s.purge if s.respond_to?(:purge)
end
@engine.purge!

FileUtils.rm_rf('work')
end

Expand Down
2 changes: 1 addition & 1 deletion test/functional/eft_18_concurrent_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_cancel

wfid = @engine.launch(pdef)

sleep n.to_f/80
sleep n.to_f/50

assert_equal n, acount

Expand Down
4 changes: 4 additions & 0 deletions test/functional/ft_32_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def test_launch
wfid0 = assert_trace(pdef, "done.")
wfid1 = assert_trace(pdef, "done.\ndone.")

sleep 0.010

lines = File.readlines(Dir['work/log/*'].first)

assert_equal 8, lines.size
Expand Down Expand Up @@ -93,6 +95,8 @@ def test_errors
wfid = @engine.launch(pdef)
wait_for(wfid)

sleep 0.010

#dump_history

h = @engine.history.process_history(wfid)
Expand Down

0 comments on commit 8dd054c

Please sign in to comment.