Skip to content

Commit 2a90213

Browse files
p-schlickmannrosa
authored andcommitted
Minimizing flakiness of dispatcher_test.rb
1 parent c09de47 commit 2a90213

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

test/unit/dispatcher_test.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class DispatcherTest < ActiveSupport::TestCase
4040
log = StringIO.new
4141
with_active_record_logger(ActiveSupport::Logger.new(log)) do
4242
with_polling(silence: false) do
43+
rewind_io(log)
4344
@dispatcher.start
44-
sleep 0.2
45+
sleep 0.5.second
4546
end
4647
end
4748

@@ -52,8 +53,9 @@ class DispatcherTest < ActiveSupport::TestCase
5253
log = StringIO.new
5354
with_active_record_logger(ActiveSupport::Logger.new(log)) do
5455
with_polling(silence: true) do
56+
rewind_io(log)
5557
@dispatcher.start
56-
sleep 0.2
58+
sleep 0.5.second
5759
end
5860
end
5961

@@ -64,7 +66,7 @@ class DispatcherTest < ActiveSupport::TestCase
6466
with_active_record_logger(nil) do
6567
with_polling(silence: true) do
6668
@dispatcher.start
67-
sleep 0.2
69+
sleep 0.5.second
6870
end
6971
end
7072

@@ -75,8 +77,9 @@ class DispatcherTest < ActiveSupport::TestCase
7577

7678
test "run more than one instance of the dispatcher" do
7779
15.times do
78-
AddToBufferJob.set(wait: 0.2).perform_later("I'm scheduled")
80+
AddToBufferJob.set(wait: 0.5.second).perform_later("I'm scheduled")
7981
end
82+
sleep 0.5.second
8083
assert_equal 15, SolidQueue::ScheduledExecution.count
8184

8285
another_dispatcher = SolidQueue::Dispatcher.new(polling_interval: 0.1, batch_size: 10)
@@ -98,9 +101,9 @@ class DispatcherTest < ActiveSupport::TestCase
98101
dispatcher.expects(:interruptible_sleep).with(dispatcher.polling_interval).at_least_once
99102
dispatcher.expects(:handle_thread_error).never
100103

101-
3.times { AddToBufferJob.set(wait: 0.1).perform_later("I'm scheduled") }
104+
3.times { AddToBufferJob.set(wait: 0.5.second).perform_later("I'm scheduled") }
105+
sleep 0.5.second
102106
assert_equal 3, SolidQueue::ScheduledExecution.count
103-
sleep 0.1
104107

105108
dispatcher.start
106109
wait_while_with_timeout(1.second) { SolidQueue::ScheduledExecution.any? }
@@ -137,4 +140,9 @@ def with_active_record_logger(logger)
137140
ensure
138141
ActiveRecord::Base.logger = old_logger
139142
end
143+
144+
def rewind_io(log)
145+
log.truncate(0)
146+
log.rewind
147+
end
140148
end

0 commit comments

Comments
 (0)