rufus-scheduler 1.0.5 → 1.0.6
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.
- data/CHANGELOG.txt +8 -0
- data/CREDITS.txt +1 -0
- data/README.txt +7 -2
- data/lib/rufus/otime.rb +302 -302
- data/lib/rufus/scheduler.rb +1129 -1111
- data/test/cron_test.rb +81 -81
- data/test/cronline_test.rb +29 -23
- data/test/dev.rb +28 -0
- data/test/scheduler_0_test.rb +228 -228
- data/test/scheduler_1_test.rb +49 -54
- data/test/scheduler_2_test.rb +69 -69
- data/test/scheduler_3_test.rb +36 -36
- data/test/scheduler_4_test.rb +55 -55
- data/test/scheduler_5_test.rb +42 -42
- data/test/scheduler_6_test.rb +28 -26
- data/test/scheduler_name_test.rb +54 -0
- data/test/test.rb +2 -0
- data/test/time_0_test.rb +51 -51
- data/test/time_1_test.rb +44 -44
- metadata +5 -3
data/test/scheduler_5_test.rb
CHANGED
@@ -13,70 +13,70 @@ require 'rufus/scheduler'
|
|
13
13
|
|
14
14
|
class Scheduler5Test < Test::Unit::TestCase
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
#def setup
|
17
|
+
#end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
#def teardown
|
20
|
+
#end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
#
|
23
|
+
# Testing the :first_at parameter
|
24
|
+
#
|
25
|
+
def test_0
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
s = Rufus::Scheduler.new
|
28
|
+
s.start
|
29
29
|
|
30
|
-
|
30
|
+
$count = 0
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
s.schedule_every "1s", :first_at => fa do
|
35
|
-
$count += 1
|
36
|
-
end
|
32
|
+
fa = Time.now + 3
|
37
33
|
|
38
|
-
|
34
|
+
s.schedule_every "1s", :first_at => fa do
|
35
|
+
$count += 1
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
sleep 1
|
41
39
|
|
42
|
-
|
40
|
+
assert_equal 0, $count
|
43
41
|
|
44
|
-
|
42
|
+
sleep 3
|
45
43
|
|
46
|
-
|
44
|
+
assert_equal 1, $count
|
47
45
|
|
48
|
-
|
46
|
+
sleep 1
|
49
47
|
|
50
|
-
|
51
|
-
end
|
48
|
+
assert_equal 2, $count
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
def test_1
|
50
|
+
s.stop
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
53
|
+
#
|
54
|
+
# Testing the :first_in parameter
|
55
|
+
#
|
56
|
+
def test_1
|
60
57
|
|
61
|
-
|
58
|
+
s = Rufus::Scheduler.new
|
59
|
+
s.start
|
62
60
|
|
63
|
-
|
64
|
-
$count += 1
|
65
|
-
end
|
61
|
+
$count = 0
|
66
62
|
|
67
|
-
|
63
|
+
s.schedule_every "1s", :first_in => "3s" do
|
64
|
+
$count += 1
|
65
|
+
end
|
68
66
|
|
69
|
-
|
67
|
+
sleep 1
|
70
68
|
|
71
|
-
|
69
|
+
assert_equal 0, $count
|
72
70
|
|
73
|
-
|
71
|
+
sleep 3
|
74
72
|
|
75
|
-
|
73
|
+
assert_equal 1, $count
|
76
74
|
|
77
|
-
|
75
|
+
sleep 1
|
78
76
|
|
79
|
-
|
80
|
-
|
77
|
+
assert_equal 2, $count
|
78
|
+
|
79
|
+
s.stop
|
80
|
+
end
|
81
81
|
end
|
82
82
|
|
data/test/scheduler_6_test.rb
CHANGED
@@ -13,39 +13,41 @@ require 'rufus/scheduler'
|
|
13
13
|
|
14
14
|
class Scheduler6Test < Test::Unit::TestCase
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
#def setup
|
17
|
+
#end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
#def teardown
|
20
|
+
#end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
#
|
23
|
+
# just a small test
|
24
|
+
#
|
25
|
+
def test_0
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
s = Rufus::Scheduler.new
|
28
|
+
s.start
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
st = ""
|
31
|
+
s0 = -1
|
32
|
+
s1 = -2
|
33
33
|
|
34
|
-
|
34
|
+
t = Time.now + 2
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
s.schedule_at t do
|
37
|
+
st << "0"
|
38
|
+
s0 = Time.now.to_i % 60
|
39
|
+
end
|
40
|
+
s.schedule_at t do
|
41
|
+
st << "1"
|
42
|
+
s1 = Time.now.to_i % 60
|
43
|
+
end
|
44
44
|
|
45
|
-
|
45
|
+
sleep 2.5
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
assert_equal "01", st
|
48
|
+
assert_equal s0, s1
|
49
|
+
|
50
|
+
s.stop
|
51
|
+
end
|
50
52
|
end
|
51
53
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Testing OpenWFE
|
4
|
+
#
|
5
|
+
# John Mettraux at openwfe.org
|
6
|
+
#
|
7
|
+
# Fri Apr 18 11:29:18 JST 2008
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'openwfe/util/scheduler'
|
12
|
+
|
13
|
+
|
14
|
+
#
|
15
|
+
# testing otime and the scheduler
|
16
|
+
#
|
17
|
+
|
18
|
+
class SchedulerNameTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
#def setup
|
21
|
+
#end
|
22
|
+
|
23
|
+
#def teardown
|
24
|
+
#end
|
25
|
+
|
26
|
+
def test_0
|
27
|
+
|
28
|
+
scheduler = OpenWFE::Scheduler.new
|
29
|
+
scheduler.sstart
|
30
|
+
|
31
|
+
sleep 0.350 if defined?(JRUBY_VERSION)
|
32
|
+
|
33
|
+
t = scheduler.instance_variable_get(:@scheduler_thread)
|
34
|
+
|
35
|
+
assert_equal "rufus scheduler", t[:name]
|
36
|
+
|
37
|
+
scheduler.stop
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_1
|
41
|
+
|
42
|
+
scheduler = OpenWFE::Scheduler.new :thread_name => "genjiguruma"
|
43
|
+
scheduler.sstart
|
44
|
+
|
45
|
+
sleep 0.350 if defined?(JRUBY_VERSION)
|
46
|
+
|
47
|
+
t = scheduler.instance_variable_get(:@scheduler_thread)
|
48
|
+
|
49
|
+
assert_equal "genjiguruma", t[:name]
|
50
|
+
|
51
|
+
scheduler.stop
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/test/test.rb
CHANGED
data/test/time_0_test.rb
CHANGED
@@ -17,71 +17,71 @@ require 'rufus/otime'
|
|
17
17
|
|
18
18
|
class Time0Test < Test::Unit::TestCase
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
#def setup
|
21
|
+
#end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
#def teardown
|
24
|
+
#end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def _test_to_iso_date
|
27
|
+
#
|
28
|
+
# well... this test is not timezone friendly...
|
29
|
+
# commented out thus...
|
30
30
|
|
31
|
-
|
31
|
+
t = 1169019813.93468
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
s = Rufus.to_iso8601_date(t)
|
34
|
+
puts s
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
assert_equal(
|
37
|
+
"2007-01-17 02:43:33-0500",
|
38
|
+
Rufus.to_iso8601_date(t),
|
39
|
+
"conversion to iso8601 date failed")
|
40
40
|
|
41
|
-
|
41
|
+
d = Rufus.to_ruby_time(s)
|
42
42
|
|
43
|
-
|
43
|
+
#puts d.to_s
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
assert_equal(
|
46
|
+
"2007-01-17T02:43:33-0500",
|
47
|
+
d.to_s,
|
48
|
+
"iso8601 date parsing failed")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_is_digit
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Rufus::is_digit?(si),
|
57
|
-
"'#{si}' should be a digit"
|
58
|
-
end
|
59
|
-
|
60
|
-
assert \
|
61
|
-
(not Rufus::is_digit?(1)),
|
62
|
-
"the integer 1 is not a character digit"
|
63
|
-
assert \
|
64
|
-
(not Rufus::is_digit?("a")),
|
65
|
-
"the character 'a' is not a character digit"
|
53
|
+
for i in 0...9
|
54
|
+
si = "#{i}"
|
55
|
+
assert \
|
56
|
+
Rufus::is_digit?(si),
|
57
|
+
"'#{si}' should be a digit"
|
66
58
|
end
|
67
59
|
|
68
|
-
|
60
|
+
assert \
|
61
|
+
(not Rufus::is_digit?(1)),
|
62
|
+
"the integer 1 is not a character digit"
|
63
|
+
assert \
|
64
|
+
(not Rufus::is_digit?("a")),
|
65
|
+
"the character 'a' is not a character digit"
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
pts "1000", 1.0
|
72
|
-
pts "1h", 3600.0
|
73
|
-
pts "1h10s", 3610.0
|
74
|
-
pts "1w2d", 777600.0
|
75
|
-
end
|
68
|
+
def test_parse_time_string
|
76
69
|
|
77
|
-
|
70
|
+
pts "500", 0.5
|
71
|
+
pts "1000", 1.0
|
72
|
+
pts "1h", 3600.0
|
73
|
+
pts "1h10s", 3610.0
|
74
|
+
pts "1w2d", 777600.0
|
75
|
+
end
|
78
76
|
|
79
|
-
|
77
|
+
protected
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
def pts (time_string, seconds)
|
80
|
+
|
81
|
+
assert_equal(
|
82
|
+
seconds,
|
83
|
+
Rufus::parse_time_string(time_string),
|
84
|
+
"'#{time_string}' did not map to #{seconds} seconds")
|
85
|
+
end
|
86
86
|
|
87
87
|
end
|
data/test/time_1_test.rb
CHANGED
@@ -17,60 +17,60 @@ require 'rufus/otime'
|
|
17
17
|
|
18
18
|
class Time1Test < Test::Unit::TestCase
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#def teardown
|
24
|
-
#end
|
25
|
-
|
26
|
-
def test_0
|
27
|
-
|
28
|
-
tts 0, "0s"
|
29
|
-
tts 0, "0m", { :drop_seconds => true }
|
30
|
-
tts 60, "1m"
|
31
|
-
tts 61, "1m1s"
|
32
|
-
tts 3661, "1h1m1s"
|
33
|
-
tts 24 * 3600, "1d"
|
34
|
-
tts 7 * 24 * 3600 + 1, "1w1s"
|
35
|
-
tts 30 * 24 * 3600 + 1, "4w2d1s"
|
36
|
-
end
|
20
|
+
#def setup
|
21
|
+
#end
|
37
22
|
|
38
|
-
|
23
|
+
#def teardown
|
24
|
+
#end
|
39
25
|
|
40
|
-
|
41
|
-
end
|
26
|
+
def test_0
|
42
27
|
|
43
|
-
|
28
|
+
tts 0, "0s"
|
29
|
+
tts 0, "0m", { :drop_seconds => true }
|
30
|
+
tts 60, "1m"
|
31
|
+
tts 61, "1m1s"
|
32
|
+
tts 3661, "1h1m1s"
|
33
|
+
tts 24 * 3600, "1d"
|
34
|
+
tts 7 * 24 * 3600 + 1, "1w1s"
|
35
|
+
tts 30 * 24 * 3600 + 1, "4w2d1s"
|
36
|
+
end
|
44
37
|
|
45
|
-
|
46
|
-
tts 0.130, "130"
|
47
|
-
tts 61.127, "1m", { :drop_seconds => true }
|
48
|
-
end
|
38
|
+
def test_1
|
49
39
|
|
50
|
-
|
40
|
+
tts 30 * 24 * 3600 + 1, "1M1s", { :months => true }
|
41
|
+
end
|
51
42
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
43
|
+
def test_2
|
44
|
+
|
45
|
+
tts 0.120 + 30 * 24 * 3600 + 1, "4w2d1s120"
|
46
|
+
tts 0.130, "130"
|
47
|
+
tts 61.127, "1m", { :drop_seconds => true }
|
48
|
+
end
|
58
49
|
|
59
|
-
|
50
|
+
def test_3
|
60
51
|
|
61
|
-
|
52
|
+
tdh 0, {}
|
53
|
+
tdh 0.128, { :ms => 128 }
|
54
|
+
tdh 60.127, { :m => 1, :ms => 127 }
|
55
|
+
tdh 61.127, { :m => 1, :s => 1, :ms => 127 }
|
56
|
+
tdh 61.127, { :m => 1 }, { :drop_seconds => true }
|
57
|
+
end
|
62
58
|
|
63
|
-
|
64
|
-
time_string,
|
65
|
-
Rufus::to_time_string(seconds, options),
|
66
|
-
"#{seconds} seconds did not map to '#{time_string}'")
|
67
|
-
end
|
59
|
+
protected
|
68
60
|
|
69
|
-
|
61
|
+
def tts (seconds, time_string, options={})
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
63
|
+
assert_equal(
|
64
|
+
time_string,
|
65
|
+
Rufus::to_time_string(seconds, options),
|
66
|
+
"#{seconds} seconds did not map to '#{time_string}'")
|
67
|
+
end
|
68
|
+
|
69
|
+
def tdh (seconds, time_hash, options={})
|
70
|
+
|
71
|
+
assert_equal(
|
72
|
+
time_hash,
|
73
|
+
Rufus::to_duration_hash(seconds, options))
|
74
|
+
end
|
75
75
|
|
76
76
|
end
|