rufus-scheduler 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,78 +16,73 @@ require 'openwfe/util/scheduler'
16
16
 
17
17
  class Scheduler1Test < Test::Unit::TestCase
18
18
 
19
- #def setup
20
- #end
19
+ #def setup
20
+ #end
21
21
 
22
- #def teardown
23
- #end
22
+ #def teardown
23
+ #end
24
24
 
25
- def test_0
25
+ def test_0
26
26
 
27
- scheduler = OpenWFE::Scheduler.new
28
- scheduler.sstart
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.sstart
29
29
 
30
- job_id = scheduler.schedule_every "500", :tags => "Avery" do
31
- # don't do a thing
32
- end
33
-
34
- sleep 0.300
35
-
36
- successful = true
30
+ job_id = scheduler.schedule_every "500", :tags => "Avery" do
31
+ # don't do a thing
32
+ end
37
33
 
38
- 200000.times do
39
- #assert_not_nil scheduler.get_job(job_id)
40
- if scheduler.get_job(job_id) == nil
41
- successful = false
42
- break
43
- end
44
- end
34
+ sleep 0.300
45
35
 
46
- scheduler.sstop
36
+ count = nil
47
37
 
48
- assert successful
38
+ 200_000.times do |i|
39
+ break if scheduler.get_job(job_id) == nil
40
+ count = i + 1
49
41
  end
50
42
 
51
- def test_1
43
+ scheduler.sstop
52
44
 
53
- scheduler = OpenWFE::Scheduler.new
54
- scheduler.sstart
45
+ assert_equal 200_000, count
46
+ end
55
47
 
56
- job_id = scheduler.schedule_every "500", :tags => "Avery" do
57
- # don't do a thing
58
- end
48
+ def test_1
59
49
 
60
- sleep 0.300
50
+ scheduler = OpenWFE::Scheduler.new
51
+ scheduler.sstart
61
52
 
62
- successful = true
53
+ job_id = scheduler.schedule_every "500", :tags => "Avery" do
54
+ # don't do a thing
55
+ end
63
56
 
64
- 200000.times do
65
- #assert_equal 1, scheduler.find_jobs("Avery").size
66
- if scheduler.find_jobs("Avery").size != 1
67
- successful = false
68
- break
69
- end
70
- end
57
+ sleep 0.300
71
58
 
72
- scheduler.sstop
59
+ count = 1
73
60
 
74
- assert successful
61
+ 200_000.times do
62
+ #assert_equal 1, scheduler.find_jobs("Avery").size
63
+ count = scheduler.find_jobs("Avery").size
64
+ break if count != 1
75
65
  end
76
66
 
77
- #
78
- # testing "deviation", if I may call it like that...
79
- #
80
- def _test_2
81
-
82
- scheduler = OpenWFE::Scheduler.new
83
- scheduler.sstart
84
- last = nil
85
- job_id = scheduler.schedule_every "1s" do
86
- t = Time.now
87
- puts t.to_f
88
- end
89
- sleep 4 * 60
90
- scheduler.sstop
67
+ scheduler.sstop
68
+
69
+ assert_equal 1, count
70
+ end
71
+
72
+ #
73
+ # testing "deviation", if I may call it like that...
74
+ #
75
+ def _test_2
76
+
77
+ scheduler = OpenWFE::Scheduler.new
78
+ scheduler.sstart
79
+ last = nil
80
+ job_id = scheduler.schedule_every "1s" do
81
+ t = Time.now
82
+ puts t.to_f
91
83
  end
84
+ sleep 4 * 60
85
+ scheduler.sstop
86
+ end
92
87
 
93
88
  end
@@ -16,108 +16,108 @@ require 'openwfe/util/scheduler'
16
16
 
17
17
  class Scheduler2Test < Test::Unit::TestCase
18
18
 
19
- #def setup
20
- #end
19
+ #def setup
20
+ #end
21
21
 
22
- #def teardown
23
- #end
22
+ #def teardown
23
+ #end
24
24
 
25
- def test_0
25
+ def test_0
26
26
 
27
- scheduler = OpenWFE::Scheduler.new
28
- scheduler.sstart
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.sstart
29
29
 
30
- counter = 0
31
- $error_counter = 0
30
+ counter = 0
31
+ $error_counter = 0
32
32
 
33
- def scheduler.lwarn (&block)
34
- #puts block.call
35
- $error_counter += 1
36
- end
37
-
38
- job_id = scheduler.schedule_every "500" do
39
- counter += 1
40
- raise "exception!"
41
- end
42
-
43
- sleep 2.300
44
-
45
- scheduler.sstop
33
+ def scheduler.lwarn (&block)
34
+ #puts block.call
35
+ $error_counter += 1
36
+ end
46
37
 
47
- assert_equal 4, counter, "execution count wrong"
48
- assert_equal 4, $error_counter, "error count wrong"
38
+ job_id = scheduler.schedule_every "500" do
39
+ counter += 1
40
+ raise "exception!"
49
41
  end
50
42
 
51
- def test_1
43
+ sleep 2.300
52
44
 
53
- # repeating myself
45
+ scheduler.sstop
54
46
 
55
- scheduler = OpenWFE::Scheduler.new
56
- scheduler.sstart
47
+ assert_equal 4, counter, "execution count wrong"
48
+ assert_equal 4, $error_counter, "error count wrong"
49
+ end
57
50
 
58
- counter = 0
59
- $error_counter = 0
51
+ def test_1
60
52
 
61
- def scheduler.lwarn (&block)
62
- #puts block.call
63
- $error_counter += 1
64
- end
53
+ # repeating myself
65
54
 
66
- job_id = scheduler.schedule_every "500", :try_again => false do
67
- counter += 1
68
- raise "exception?"
69
- end
55
+ scheduler = OpenWFE::Scheduler.new
56
+ scheduler.sstart
70
57
 
71
- sleep 2.300
58
+ counter = 0
59
+ $error_counter = 0
72
60
 
73
- scheduler.sstop
61
+ def scheduler.lwarn (&block)
62
+ #puts block.call
63
+ $error_counter += 1
64
+ end
74
65
 
75
- assert_equal 1, counter, "execution count wrong"
76
- assert_equal 1, $error_counter, "error count wrong"
66
+ job_id = scheduler.schedule_every "500", :try_again => false do
67
+ counter += 1
68
+ raise "exception?"
77
69
  end
78
70
 
79
- def test_2
71
+ sleep 2.300
80
72
 
81
- scheduler = OpenWFE::Scheduler.new
82
- scheduler.sstart
73
+ scheduler.sstop
83
74
 
84
- def scheduler.lwarn (&block)
85
- puts block.call
86
- end
75
+ assert_equal 1, counter, "execution count wrong"
76
+ assert_equal 1, $error_counter, "error count wrong"
77
+ end
87
78
 
88
- counter = 0
79
+ def test_2
89
80
 
90
- job_id = scheduler.schedule_every "500" do |job_id, at, params|
91
- counter += 1
92
- params[:dont_reschedule] = true if counter == 2
93
- end
81
+ scheduler = OpenWFE::Scheduler.new
82
+ scheduler.sstart
94
83
 
95
- sleep 3.000
84
+ def scheduler.lwarn (&block)
85
+ puts block.call
86
+ end
87
+
88
+ counter = 0
96
89
 
97
- assert_equal 2, counter
90
+ job_id = scheduler.schedule_every "500" do |job_id, at, params|
91
+ counter += 1
92
+ params[:dont_reschedule] = true if counter == 2
98
93
  end
99
94
 
100
- def test_3
95
+ sleep 3.000
101
96
 
102
- # repeating myself ...
97
+ assert_equal 2, counter
98
+ end
103
99
 
104
- scheduler = OpenWFE::Scheduler.new
105
- scheduler.sstart
100
+ def test_3
106
101
 
107
- def scheduler.lwarn (&block)
108
- puts block.call
109
- end
102
+ # repeating myself ...
110
103
 
111
- counter = 0
104
+ scheduler = OpenWFE::Scheduler.new
105
+ scheduler.sstart
112
106
 
113
- job_id = scheduler.schedule_every "500" do |job_id, at, params|
114
- counter += 1
115
- params[:every] = "1s" if counter == 2
116
- end
107
+ def scheduler.lwarn (&block)
108
+ puts block.call
109
+ end
117
110
 
118
- sleep 5.000
111
+ counter = 0
119
112
 
120
- assert_equal 2 + 3, counter
113
+ job_id = scheduler.schedule_every "500" do |job_id, at, params|
114
+ counter += 1
115
+ params[:every] = "1s" if counter == 2
121
116
  end
122
117
 
118
+ sleep 5.000
119
+
120
+ assert_equal 2 + 3, counter
121
+ end
122
+
123
123
  end
@@ -13,57 +13,57 @@ require 'openwfe/util/scheduler'
13
13
 
14
14
  class Scheduler3Test < Test::Unit::TestCase
15
15
 
16
- #def setup
17
- #end
16
+ #def setup
17
+ #end
18
18
 
19
- #def teardown
20
- #end
19
+ #def teardown
20
+ #end
21
21
 
22
- #
23
- # Testing tags
24
- #
25
- def test_0
22
+ #
23
+ # Testing tags
24
+ #
25
+ def test_0
26
26
 
27
- scheduler = OpenWFE::Scheduler.new
28
- scheduler.start
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.start
29
29
 
30
- value = nil
30
+ value = nil
31
31
 
32
- scheduler.schedule_in "3s", :tags => "fish" do
33
- value = "fish"
34
- end
32
+ scheduler.schedule_in "3s", :tags => "fish" do
33
+ value = "fish"
34
+ end
35
35
 
36
- sleep 0.300 # let the job get really scheduled
36
+ sleep 0.300 # let the job get really scheduled
37
37
 
38
- assert_equal [], scheduler.find_jobs('deer')
39
- assert_equal 1, scheduler.find_jobs('fish').size
38
+ assert_equal [], scheduler.find_jobs('deer')
39
+ assert_equal 1, scheduler.find_jobs('fish').size
40
40
 
41
- scheduler.schedule "* * * * *", :tags => "fish" do
42
- value = "cron-fish"
43
- end
44
- scheduler.schedule "* * * * *", :tags => "vegetable" do
45
- value = "daikon"
46
- end
41
+ scheduler.schedule "* * * * *", :tags => "fish" do
42
+ value = "cron-fish"
43
+ end
44
+ scheduler.schedule "* * * * *", :tags => "vegetable" do
45
+ value = "daikon"
46
+ end
47
47
 
48
- sleep 0.300 # let the jobs get really scheduled
48
+ sleep 0.300 # let the jobs get really scheduled
49
49
 
50
- assert_equal 2, scheduler.find_jobs('fish').size
51
- #puts scheduler.find_jobs('fish')
50
+ assert_equal 2, scheduler.find_jobs('fish').size
51
+ #puts scheduler.find_jobs('fish')
52
52
 
53
- scheduler.find_jobs('fish').each do |job|
54
- scheduler.unschedule(job.job_id)
55
- end
53
+ scheduler.find_jobs('fish').each do |job|
54
+ scheduler.unschedule(job.job_id)
55
+ end
56
56
 
57
- sleep 0.300 # give it some time to unschedule
57
+ sleep 0.300 # give it some time to unschedule
58
58
 
59
- assert_equal [], scheduler.find_jobs('fish')
60
- assert_equal 1, scheduler.find_jobs('vegetable').size
59
+ assert_equal [], scheduler.find_jobs('fish')
60
+ assert_equal 1, scheduler.find_jobs('vegetable').size
61
61
 
62
- scheduler.find_jobs('vegetable')[0].unschedule
62
+ scheduler.find_jobs('vegetable')[0].unschedule
63
63
 
64
- sleep 0.300 # give it some time to unschedule
64
+ sleep 0.300 # give it some time to unschedule
65
65
 
66
- assert_equal 0, scheduler.find_jobs('vegetable').size
67
- end
66
+ assert_equal 0, scheduler.find_jobs('vegetable').size
67
+ end
68
68
 
69
69
  end
@@ -13,69 +13,69 @@ require 'rufus/scheduler'
13
13
 
14
14
  class Scheduler4Test < Test::Unit::TestCase
15
15
 
16
- #def setup
17
- #end
18
-
19
- #def teardown
20
- #end
21
-
22
- #
23
- # Checking that a sleep in a schedule won't raise any exception
24
- #
25
- def test_0
26
-
27
- s = Rufus::Scheduler.new
28
- s.start
29
-
30
- $exception = nil
31
-
32
- class << s
33
- def lwarn (&block)
34
- $exception = block.call
35
- end
36
- end
37
-
38
- counters = Counters.new
39
-
40
- s.schedule_every "2s" do
41
- counters.inc :a
42
- sleep 4
43
- counters.inc :b
44
- end
45
- s.schedule_every "3s" do
46
- counters.inc :c
47
- end
48
- #p Time.now.to_f
49
-
50
- sleep 10.300
51
-
52
- s.stop
53
-
54
- assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
55
- assert_nil $exception
16
+ #def setup
17
+ #end
18
+
19
+ #def teardown
20
+ #end
21
+
22
+ #
23
+ # Checking that a sleep in a schedule won't raise any exception
24
+ #
25
+ def test_0
26
+
27
+ s = Rufus::Scheduler.new
28
+ s.start
29
+
30
+ $exception = nil
31
+
32
+ class << s
33
+ def lwarn (&block)
34
+ $exception = block.call
35
+ end
56
36
  end
57
37
 
58
- protected
38
+ counters = Counters.new
59
39
 
60
- class Counters
40
+ s.schedule_every "2s" do
41
+ counters.inc :a
42
+ sleep 4
43
+ counters.inc :b
44
+ end
45
+ s.schedule_every "3s" do
46
+ counters.inc :c
47
+ end
48
+ #p Time.now.to_f
61
49
 
62
- attr_reader :counters
50
+ sleep 10.300
63
51
 
64
- def initialize
52
+ s.stop
65
53
 
66
- @counters = {}
67
- end
54
+ assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
55
+ assert_nil $exception
56
+ end
68
57
 
69
- def inc (counter)
58
+ protected
70
59
 
71
- @counters[counter] ||= 0
72
- @counters[counter] += 1
60
+ class Counters
73
61
 
74
- #puts(
75
- # "#{counter} _ " +
76
- # "#{Time.now.to_f} #{@counters.inspect} " +
77
- # "(#{Thread.current.object_id})")
78
- end
79
- end
62
+ attr_reader :counters
63
+
64
+ def initialize
65
+
66
+ @counters = {}
67
+ end
68
+
69
+ def inc (counter)
70
+
71
+ @counters[counter] ||= 0
72
+ @counters[counter] += 1
73
+
74
+ #puts(
75
+ # "#{counter} _ " +
76
+ # "#{Time.now.to_f} #{@counters.inspect} " +
77
+ # "(#{Thread.current.object_id})")
78
+ end
79
+ end
80
80
 
81
81
  end