-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathplugin_testing.rb
More file actions
60 lines (47 loc) · 1.55 KB
/
plugin_testing.rb
File metadata and controls
60 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true
require "test_helper"
module PluginTesting
extend ActiveSupport::Concern
extend ActiveSupport::Testing::Declarative
included do
self.use_transactional_tests = false
setup do
FileUtils.mkdir_p Rails.root.join("tmp", "pids")
Dir.chdir("test/dummy") do
cmd = %W[
bundle exec puma
-b tcp://127.0.0.1:9222
-C config/puma_#{solid_queue_mode}.rb
-s
config.ru
]
@pid = fork do
exec(*cmd)
end
end
wait_for_registered_processes(5, timeout: 5.second)
end
teardown do
terminate_process(@pid, signal: :INT) if process_exists?(@pid)
wait_for_registered_processes(0, timeout: 5.seconds)
end
end
test "perform jobs inside puma's process" do
StoreResultJob.perform_later(:puma_plugin)
wait_for_jobs_to_finish_for(5.seconds)
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
end
test "stop the queue on puma's restart" do
signal_process(@pid, :SIGUSR2)
# Ensure the restart finishes before we try to continue with the test
wait_for_registered_processes(0, timeout: 5.second)
wait_for_registered_processes(5, timeout: 5.second)
StoreResultJob.perform_later(:puma_plugin)
wait_for_jobs_to_finish_for(2.seconds)
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
end
private
def solid_queue_mode
raise NotImplementedError
end
end