2015-12-31 23:33:35 +00:00
|
|
|
# frozen_string_literal: true
|
2018-12-30 20:15:21 +00:00
|
|
|
|
2022-03-03 20:50:03 +00:00
|
|
|
require_relative "helper"
|
|
|
|
require "sidekiq/launcher"
|
2015-10-06 19:43:01 +00:00
|
|
|
|
2019-03-01 21:25:56 +00:00
|
|
|
describe Sidekiq::Launcher do
|
|
|
|
before do
|
2022-08-25 17:15:11 +00:00
|
|
|
@config = reset!
|
2022-09-01 22:47:24 +00:00
|
|
|
@config.default_capsule.concurrency = 3
|
2022-05-31 20:37:31 +00:00
|
|
|
@config[:tag] = "myapp"
|
2019-03-01 21:25:56 +00:00
|
|
|
end
|
2015-10-06 19:43:01 +00:00
|
|
|
|
2022-03-03 20:50:03 +00:00
|
|
|
describe "memory collection" do
|
|
|
|
it "works in any test environment" do
|
2020-10-14 22:09:50 +00:00
|
|
|
kb = Sidekiq::Launcher::MEMORY_GRABBER.call($$)
|
|
|
|
refute_nil kb
|
|
|
|
assert kb > 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-01 22:47:24 +00:00
|
|
|
it "starts and stops" do
|
2022-11-01 19:32:31 +00:00
|
|
|
l = Sidekiq::Launcher.new(@config)
|
|
|
|
l.run(async_beat: false)
|
|
|
|
l.stop
|
2022-09-01 22:47:24 +00:00
|
|
|
end
|
|
|
|
|
2022-03-03 20:50:03 +00:00
|
|
|
describe "heartbeat" do
|
2015-10-06 19:43:01 +00:00
|
|
|
before do
|
2022-11-01 19:32:31 +00:00
|
|
|
@launcher = Sidekiq::Launcher.new(@config)
|
|
|
|
@id = @launcher.identity
|
2019-03-01 21:25:56 +00:00
|
|
|
|
2022-03-03 20:50:03 +00:00
|
|
|
Sidekiq::Processor::WORK_STATE.set("a", {"b" => 1})
|
2019-03-01 21:25:56 +00:00
|
|
|
|
2018-12-30 20:15:21 +00:00
|
|
|
@proctitle = $0
|
2015-10-06 19:43:01 +00:00
|
|
|
end
|
|
|
|
|
2018-12-30 20:15:21 +00:00
|
|
|
after do
|
2022-03-03 20:37:25 +00:00
|
|
|
Sidekiq::Processor::WORK_STATE.clear
|
2018-12-30 20:15:21 +00:00
|
|
|
$0 = @proctitle
|
2015-10-06 19:43:01 +00:00
|
|
|
end
|
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
it "stores process info in redis" do
|
|
|
|
@launcher.beat
|
2016-08-12 19:34:41 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy]", $0
|
|
|
|
workers, rtt = @config.redis { |c| c.hmget(@id, "busy", "rtt_us") }
|
2015-10-06 19:43:01 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
assert_equal "1", workers
|
|
|
|
refute_nil rtt
|
|
|
|
assert_in_delta 1000, rtt.to_i, 1000
|
2015-10-06 19:43:01 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
expires = @config.redis { |c| c.pttl(@id) }
|
|
|
|
assert_in_delta 60000, expires, 500
|
|
|
|
end
|
2018-12-30 20:15:21 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
it "fires start heartbeat event only once" do
|
|
|
|
cnt = 0
|
2018-12-30 20:15:21 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
@config.on(:heartbeat) do
|
|
|
|
cnt += 1
|
2015-10-06 19:43:01 +00:00
|
|
|
end
|
2022-11-01 19:32:31 +00:00
|
|
|
assert_equal 0, cnt
|
|
|
|
@launcher.heartbeat
|
|
|
|
assert_equal 1, cnt
|
|
|
|
@launcher.heartbeat
|
|
|
|
assert_equal 1, cnt
|
|
|
|
end
|
2015-10-06 19:43:01 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
it "quiets" do
|
|
|
|
@launcher.quiet
|
|
|
|
@launcher.beat
|
2018-12-30 20:15:21 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] stopping", $0
|
2019-03-01 21:25:56 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
@launcher.beat
|
|
|
|
info = @config.redis { |c| c.hmget(@id, "busy") }
|
|
|
|
assert_equal ["1"], info
|
2019-03-01 21:25:56 +00:00
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
expires = @config.redis { |c| c.pttl(@id) }
|
|
|
|
assert_in_delta 60000, expires, 50
|
2019-03-01 21:25:56 +00:00
|
|
|
end
|
|
|
|
|
2022-11-01 19:32:31 +00:00
|
|
|
it "allows arbitrary proctitle extensions" do
|
|
|
|
Sidekiq::Launcher::PROCTITLES << proc { "xyz" }
|
|
|
|
@launcher.beat
|
|
|
|
Sidekiq::Launcher::PROCTITLES.pop
|
|
|
|
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] xyz", $0
|
2019-03-01 21:25:56 +00:00
|
|
|
end
|
|
|
|
end
|
2015-10-06 19:43:01 +00:00
|
|
|
end
|