Handle a return() from a proc a bit more gracefully, add a test case
git-svn-id: file:///home/svn/framework3/trunk@8008 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
a414d5fc8f
commit
3f59ea2f95
|
@ -16,7 +16,6 @@ class TaskManager
|
||||||
attr_accessor :proc
|
attr_accessor :proc
|
||||||
attr_accessor :source
|
attr_accessor :source
|
||||||
attr_accessor :exception
|
attr_accessor :exception
|
||||||
attr_accessor :retval
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Create a new task
|
# Create a new task
|
||||||
|
@ -41,7 +40,7 @@ class TaskManager
|
||||||
# Run the associated proc
|
# Run the associated proc
|
||||||
#
|
#
|
||||||
def run(*args)
|
def run(*args)
|
||||||
self.retval = self.proc.call(*args) if self.proc
|
self.proc.call(*args) if self.proc
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -158,6 +157,8 @@ class TaskManager
|
||||||
else
|
else
|
||||||
task.run(self, task)
|
task.run(self, task)
|
||||||
end
|
end
|
||||||
|
rescue ::ThreadError
|
||||||
|
# Ignore these (caused by a return inside of the proc)
|
||||||
rescue ::Exception => e
|
rescue ::Exception => e
|
||||||
|
|
||||||
if(e.class == ::Timeout::Error)
|
if(e.class == ::Timeout::Error)
|
||||||
|
|
|
@ -86,5 +86,17 @@ describe Msf::TaskManager do
|
||||||
t.status.should == :dropped
|
t.status.should == :dropped
|
||||||
t.exception.class.should == ::NoMethodError
|
t.exception.class.should == ::NoMethodError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should handle a bad proc return" do
|
||||||
|
tm = Msf::TaskManager.new($msf)
|
||||||
|
t = Msf::TaskManager::Task.new(Proc.new { return 12345 })
|
||||||
|
|
||||||
|
tm.start
|
||||||
|
tm.queue_task(t)
|
||||||
|
sleep(0.5)
|
||||||
|
|
||||||
|
t.status.should == :done
|
||||||
|
t.exception.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue