rufus-scheduler 3.0.8 → 3.2.0

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/spec/spec_helper.rb DELETED
@@ -1,126 +0,0 @@
1
-
2
- #
3
- # Specifying rufus-scheduler
4
- #
5
- # Wed Apr 17 06:00:59 JST 2013
6
- #
7
-
8
- puts "RUBY_VERSION: #{RUBY_VERSION}"
9
- puts "RUBY_PLATFORM: #{RUBY_PLATFORM}"
10
-
11
- Thread.abort_on_exception = true
12
-
13
- require 'stringio'
14
- require 'rufus-scheduler'
15
-
16
- #
17
- # misc helper methods
18
-
19
- def ruby18?
20
-
21
- !! RUBY_VERSION.match(/^1\.8\./)
22
- end
23
-
24
- def jruby?
25
-
26
- !! RUBY_PLATFORM.match(/java/)
27
- end
28
-
29
- def local(*args)
30
-
31
- Time.local(*args)
32
- end
33
- alias lo local
34
-
35
- def utc(*args)
36
-
37
- Time.utc(*args)
38
- end
39
-
40
- def ltz(tz, *args)
41
-
42
- in_zone(tz) { Time.local(*args) }
43
- end
44
-
45
- def ltu(tz, *args)
46
-
47
- in_zone(tz) { Time.local(*args) }.getutc
48
- end
49
-
50
- def sleep_until_next_minute
51
-
52
- min = Time.now.min
53
- while Time.now.min == min; sleep 2; end
54
- end
55
-
56
- def sleep_until_next_second
57
-
58
- sec = Time.now.sec
59
- while Time.now.sec == sec; sleep 0.2; end
60
- end
61
-
62
- def in_zone(zone_name, &block)
63
-
64
- prev_tz = ENV['TZ']
65
- ENV['TZ'] = zone_name
66
-
67
- block.call
68
-
69
- ensure
70
-
71
- ENV['TZ'] = prev_tz
72
- end
73
-
74
- def with_chronic(&block)
75
-
76
- require 'chronic'
77
-
78
- Object.const_set(:Khronic, Chronic) unless defined?(Khronic)
79
- Object.const_set(:Chronic, Khronic) unless defined?(Chronic)
80
-
81
- block.call
82
-
83
- ensure
84
-
85
- Object.send(:remove_const, :Chronic)
86
- end
87
-
88
- def without_chronic(&block) # for quick counter-tests ;-)
89
-
90
- block.call
91
- end
92
-
93
-
94
- #
95
- # matchers
96
-
97
- #require 'rspec/expectations'
98
-
99
- RSpec::Matchers.define :be_within_1s_of do |expected|
100
-
101
- match do |actual|
102
-
103
- if actual.respond_to?(:asctime)
104
- (actual.to_f - expected.to_f).abs <= 1.0
105
- else
106
- false
107
- end
108
- end
109
-
110
- failure_message_for_should do |actual|
111
-
112
- if actual.respond_to?(:asctime)
113
- "expected #{actual.inspect} to be within 1 second of #{expected}"
114
- else
115
- "expected Time instance, got a #{actual.inspect}"
116
- end
117
- end
118
- end
119
-
120
-
121
- #
122
- # configure
123
-
124
- #RSpec.configure do |config|
125
- #end
126
-
data/spec/threads_spec.rb DELETED
@@ -1,96 +0,0 @@
1
-
2
- #
3
- # Specifying rufus-scheduler
4
- #
5
- # Thu Jul 25 05:53:51 JST 2013
6
- #
7
-
8
- require 'spec_helper'
9
-
10
-
11
- describe Rufus::Scheduler do
12
-
13
- before :each do
14
- @scheduler = Rufus::Scheduler.new
15
- end
16
- after :each do
17
- @scheduler.shutdown
18
- end
19
-
20
- context 'thread pool' do
21
-
22
- it 'starts with an empty thread pool' do
23
-
24
- expect(@scheduler.work_threads.size).to eq(0)
25
- end
26
-
27
- it 'does not cross the max_work_threads threshold' do
28
-
29
- #@scheduler.min_work_threads = 2
30
- @scheduler.max_work_threads = 5
31
-
32
- 10.times do
33
- @scheduler.in '0s' do
34
- sleep 5
35
- end
36
- end
37
-
38
- sleep 0.5
39
-
40
- #@scheduler.job_threads.each do |t|
41
- # p t.keys
42
- # p t[:rufus_scheduler_job].class
43
- #end
44
-
45
- expect(@scheduler.work_threads.size).to eq(5)
46
- end
47
-
48
- it 'does not cross the max_work_threads threshold (overlap: false)' do
49
-
50
- #@scheduler.min_work_threads = 2
51
- @scheduler.max_work_threads = 5
52
-
53
- 10.times do
54
- @scheduler.in '0s', :overlap => false do
55
- sleep 5
56
- end
57
- end
58
-
59
- sleep 0.5
60
-
61
- #@scheduler.job_threads.each do |t|
62
- # p t.keys
63
- # p t[:rufus_scheduler_job].class
64
- #end
65
-
66
- expect(@scheduler.work_threads.size).to eq(5)
67
- end
68
-
69
- it 'does not execute unscheduled jobs' do
70
-
71
- @scheduler.max_work_threads = 1
72
-
73
- counter = 0
74
-
75
- job0 =
76
- @scheduler.schedule_in '0.3s' do
77
- counter += 1
78
- sleep 1
79
- end
80
- job1 =
81
- @scheduler.schedule_in '0.35s' do
82
- counter += 1
83
- sleep 1
84
- end
85
-
86
- sleep(0.1) while counter < 1
87
- sleep(0.1) while @scheduler.work_queue.size < 1
88
- job1.unschedule
89
-
90
- sleep(2)
91
-
92
- expect(counter).to eq(1)
93
- end
94
- end
95
- end
96
-