diff --git a/lib/titan/thread.rb b/lib/titan/thread.rb index b9c4929..ac5553c 100644 --- a/lib/titan/thread.rb +++ b/lib/titan/thread.rb @@ -103,6 +103,8 @@ def save_threads # def remove_dead_threads @@threads.delete_if { |thread_id,thread| !thread.alive? } + save_threads + @@threads end end end diff --git a/spec/titan/thread_spec.rb b/spec/titan/thread_spec.rb index 340ea20..f819df6 100644 --- a/spec/titan/thread_spec.rb +++ b/spec/titan/thread_spec.rb @@ -207,4 +207,18 @@ def new_thread(id=nil) Titan::Thread.save_threads end end + + describe ".remove_dead_threads" do + it "should synchronize the threads" do + Titan::Thread.should_receive(:save_threads) + Titan::Thread.remove_dead_threads + end + + it "should return all threads" do + # avoid initializing a new Hash object + Titan::Thread.stub!(:load_threads) + new_thread + Titan::Thread.remove_dead_threads.should equal(Titan::Thread.all) + end + end end