Sha256: e05c6aa8238d897842cb0d762f49698d0c0c1bf72eaa4d55419cc756a094b693
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require File.dirname(__FILE__) + '/../lib/stalker' require 'contest' require 'mocha' module Stalker def log(msg); end def log_error(msg); end end class StalkerTest < Test::Unit::TestCase setup do Stalker.clear! $result = -1 $handled = false end test "enqueue and work a job" do val = rand(999999) Stalker.job('my.job') { |args| $result = args['val'] } Stalker.enqueue('my.job', :val => val) Stalker.prep Stalker.work_one_job assert_equal val, $result end test "invoke error handler when defined" do Stalker.error { |e| $handled = true } Stalker.job('my.job') { fail } Stalker.enqueue('my.job') Stalker.prep Stalker.work_one_job assert_equal true, $handled end test "continue working when error handler not defined" do Stalker.job('my.job') { fail } Stalker.enqueue('my.job') Stalker.prep Stalker.work_one_job assert_equal false, $handled end test "exception raised one second before beanstalk ttr reached" do Stalker.error { |e| $handled = e.class } Stalker.job('my.job') { sleep(3); $handled = "didn't time out" } Stalker.enqueue('my.job', {}, :ttr => 2) Stalker.prep Stalker.work_one_job assert_equal Stalker::JobTimeout, $handled end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stalker-0.5.0 | test/stalker_test.rb |