rufus-scheduler 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,152 +0,0 @@
1
-
2
- #
3
- # Testing the 'rufus-scheduler'
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Sat Jan 26 20:05:57 JST 2008
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'rufus/scheduler'
14
-
15
-
16
- class Scheduler5Test < Test::Unit::TestCase
17
-
18
- #
19
- # Testing the :first_at parameter
20
- #
21
- def test_0
22
-
23
- s = Rufus::Scheduler.new
24
- s.start
25
-
26
- $count = 0
27
-
28
- fa = Time.now + 3
29
-
30
- s.schedule_every '1s', :first_at => fa do
31
- $count += 1
32
- end
33
-
34
- sleep 1
35
-
36
- assert_equal 0, $count
37
-
38
- sleep 3
39
-
40
- assert_equal 1, $count
41
-
42
- sleep 1
43
-
44
- assert_equal 2, $count
45
-
46
- s.stop
47
- end
48
-
49
- #
50
- # Testing the :first_in parameter
51
- #
52
- def test_1
53
-
54
- s = Rufus::Scheduler.new
55
- s.start
56
-
57
- $count = 0
58
-
59
- s.schedule_every '1s', :first_in => '3s' do
60
- $count += 1
61
- end
62
-
63
- sleep 1
64
-
65
- assert_equal 0, $count
66
-
67
- sleep 3
68
-
69
- assert_equal 1, $count
70
-
71
- sleep 1
72
-
73
- assert_equal 2, $count
74
-
75
- s.stop
76
- end
77
-
78
- #
79
- # Testing the :timeout parameter
80
- #
81
- def test_2
82
-
83
- s = Rufus::Scheduler.start_new
84
-
85
- $count = 0
86
- $error = nil
87
-
88
- def s.log_exception (e)
89
- $error = e
90
- end
91
-
92
- s.in '3s', :timeout => '2s' do
93
- loop do
94
- $count += 1
95
- sleep 3
96
- end
97
- end
98
-
99
- sleep 6
100
-
101
- assert_kind_of Rufus::TimeOutError, $error
102
- assert_equal 1, $count
103
-
104
- s.stop
105
- end
106
-
107
- #
108
- # Testing the :first_in + :timeout parameters
109
- #
110
- def test_3
111
-
112
- s = Rufus::Scheduler.start_new
113
-
114
- $count = 0
115
- $error = nil
116
- $jobs = nil
117
- $status = :out
118
-
119
- def s.log_exception (e)
120
- $error = e
121
- $status = :timedout
122
- end
123
-
124
- s.every '5s', :first_in => '2s', :timeout => '1s' do
125
- $status = :in
126
- Thread.pass # let the timeout job get scheduled
127
- jobs = s.all_jobs
128
- $jobs = [ jobs.size, jobs.collect { |j| j.tags }.flatten ]
129
- $count += 1
130
- sleep 4
131
- $status = :out
132
- end
133
-
134
- sleep 4 # until after 1st timeout
135
-
136
- assert_kind_of Rufus::TimeOutError, $error
137
- assert_equal 1, $count
138
- assert_equal [ 2, [ 'timeout' ] ], $jobs
139
- assert_equal :timedout, $status
140
-
141
- assert_equal 1, s.all_jobs.size
142
-
143
- sleep 3.5 # right in the middle of the 2nd timeout
144
-
145
- assert_equal :in, $status
146
- assert_equal 2, s.all_jobs.size
147
- assert_equal [ 'timeout' ], s.all_jobs.collect { |j| j.tags }.flatten
148
-
149
- s.stop
150
- end
151
- end
152
-
@@ -1,49 +0,0 @@
1
-
2
- #
3
- # Testing the 'rufus-scheduler'
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Thu Feb 14 08:19:10 JST 2008
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'rufus/scheduler'
14
-
15
-
16
- class Scheduler6Test < Test::Unit::TestCase
17
-
18
- #
19
- # just a small test
20
- #
21
- def test_0
22
-
23
- s = Rufus::Scheduler.new
24
- s.start
25
-
26
- st = ""
27
- s0 = -1
28
- s1 = -2
29
-
30
- t = Time.now + 2
31
-
32
- s.schedule_at t do
33
- st << "0"
34
- s0 = Time.now.to_i % 60
35
- end
36
- s.schedule_at t do
37
- st << "1"
38
- s1 = Time.now.to_i % 60
39
- end
40
-
41
- sleep 2.5
42
-
43
- assert_equal "01", st
44
- assert_equal s0, s1
45
-
46
- s.stop
47
- end
48
- end
49
-
@@ -1,46 +0,0 @@
1
-
2
- #
3
- # Testing the 'rufus-scheduler'
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Sun Jul 13 19:20:27 JST 2008
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'rufus/scheduler'
14
-
15
-
16
- #
17
- # checking if bug #20893 got fixed
18
- #
19
- class Scheduler7Test < Test::Unit::TestCase
20
-
21
- def test_0
22
-
23
- count = 0
24
-
25
- s = Rufus::Scheduler.start_new
26
-
27
- job_id = s.schedule_every('5s') do |job_id, at, params|
28
- count += 1
29
- sleep 3
30
- end
31
-
32
- sleep 6
33
-
34
- assert_equal 1, s.every_job_count
35
-
36
- s.unschedule job_id
37
-
38
- sleep 6
39
-
40
- s.stop
41
-
42
- assert_equal 0, s.every_job_count
43
- assert_equal 1, count
44
- end
45
- end
46
-
@@ -1,49 +0,0 @@
1
-
2
- #
3
- # Testing Rufus
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Fri Apr 18 11:29:18 JST 2008
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'openwfe/util/scheduler'
14
-
15
-
16
- #
17
- # testing otime and the scheduler
18
- #
19
- class SchedulerNameTest < Test::Unit::TestCase
20
-
21
- def test_0
22
-
23
- scheduler = Rufus::Scheduler.new
24
- scheduler.start
25
-
26
- sleep 0.350 if defined?(JRUBY_VERSION)
27
-
28
- t = scheduler.instance_variable_get(:@scheduler_thread)
29
-
30
- assert_equal "rufus scheduler", t[:name]
31
-
32
- scheduler.stop
33
- end
34
-
35
- def test_1
36
-
37
- scheduler = Rufus::Scheduler.new :thread_name => "genjiguruma"
38
- scheduler.start
39
-
40
- sleep 0.350 if defined?(JRUBY_VERSION)
41
-
42
- t = scheduler.instance_variable_get(:@scheduler_thread)
43
-
44
- assert_equal "genjiguruma", t[:name]
45
-
46
- scheduler.stop
47
- end
48
-
49
- end
data/test/time_0_test.rb DELETED
@@ -1,83 +0,0 @@
1
-
2
- #
3
- # Testing Rufus
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Sun Oct 29 16:18:25 JST 2006
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'rufus/otime'
14
-
15
-
16
- #
17
- # testing otime
18
- #
19
- class Time0Test < Test::Unit::TestCase
20
-
21
- def _test_to_iso_date
22
- #
23
- # well... this test is not timezone friendly...
24
- # commented out thus...
25
-
26
- t = 1169019813.93468
27
-
28
- s = Rufus.to_iso8601_date(t)
29
- puts s
30
-
31
- assert_equal(
32
- "2007-01-17 02:43:33-0500",
33
- Rufus.to_iso8601_date(t),
34
- "conversion to iso8601 date failed")
35
-
36
- d = Rufus.to_ruby_time(s)
37
-
38
- #puts d.to_s
39
-
40
- assert_equal(
41
- "2007-01-17T02:43:33-0500",
42
- d.to_s,
43
- "iso8601 date parsing failed")
44
- end
45
-
46
- def test_is_digit
47
-
48
- for i in 0...9
49
- si = "#{i}"
50
- assert \
51
- Rufus::is_digit?(si),
52
- "'#{si}' should be a digit"
53
- end
54
-
55
- assert \
56
- (not Rufus::is_digit?(1)),
57
- "the integer 1 is not a character digit"
58
- assert \
59
- (not Rufus::is_digit?("a")),
60
- "the character 'a' is not a character digit"
61
- end
62
-
63
- def test_parse_time_string
64
-
65
- pts "500", 0.5
66
- pts "1000", 1.0
67
- pts "1h", 3600.0
68
- pts "1h10s", 3610.0
69
- pts "1w2d", 777600.0
70
- pts "1d1w1d", 777600.0
71
- end
72
-
73
- protected
74
-
75
- def pts (time_string, seconds)
76
-
77
- assert_equal(
78
- seconds,
79
- Rufus::parse_time_string(time_string),
80
- "'#{time_string}' did not map to #{seconds} seconds")
81
- end
82
-
83
- end
data/test/time_1_test.rb DELETED
@@ -1,71 +0,0 @@
1
-
2
- #
3
- # Testing Rufus
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Fri Feb 29 11:18:48 JST 2008
8
- #
9
-
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
-
12
- require 'test/unit'
13
- require 'rufus/otime'
14
-
15
-
16
- #
17
- # testing otime
18
- #
19
- class Time1Test < Test::Unit::TestCase
20
-
21
- def test_0
22
-
23
- tts 0, "0s"
24
- tts 0, "0m", { :drop_seconds => true }
25
- tts 60, "1m"
26
- tts 61, "1m1s"
27
- tts 3661, "1h1m1s"
28
- tts 24 * 3600, "1d"
29
- tts 7 * 24 * 3600 + 1, "1w1s"
30
- tts 30 * 24 * 3600 + 1, "4w2d1s"
31
- end
32
-
33
- def test_1
34
-
35
- tts 30 * 24 * 3600 + 1, "1M1s", { :months => true }
36
- end
37
-
38
- def test_2
39
-
40
- tts 0.120 + 30 * 24 * 3600 + 1, "4w2d1s120"
41
- tts 0.130, "130"
42
- tts 61.127, "1m", { :drop_seconds => true }
43
- end
44
-
45
- def test_3
46
-
47
- tdh 0, {}
48
- tdh 0.128, { :ms => 128 }
49
- tdh 60.127, { :m => 1, :ms => 127 }
50
- tdh 61.127, { :m => 1, :s => 1, :ms => 127 }
51
- tdh 61.127, { :m => 1 }, { :drop_seconds => true }
52
- end
53
-
54
- protected
55
-
56
- def tts (seconds, time_string, options={})
57
-
58
- assert_equal(
59
- time_string,
60
- Rufus::to_time_string(seconds, options),
61
- "#{seconds} seconds did not map to '#{time_string}'")
62
- end
63
-
64
- def tdh (seconds, time_hash, options={})
65
-
66
- assert_equal(
67
- time_hash,
68
- Rufus::to_duration_hash(seconds, options))
69
- end
70
-
71
- end