Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: test/test_puma_server.rb - fixup auto_trim tests #3561

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions test/test_puma_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2102,35 +2102,12 @@ def test_cl_and_te_smuggle
end

def test_auto_trim_with_variable_pool_size
auto_trim_time = 3
server_run(min_threads: 1, max_threads: 2, auto_trim_time: auto_trim_time)
sleep 1 # wait for possible initial trim on run
thread_pool_expect true, :trim, nil, after: auto_trim_time
server_run(min_threads: 1, max_threads: 2, auto_trim_time: 1)
assert @pool.instance_variable_get(:@auto_trim)
end

def test_auto_trim_with_fixed_pool_size
auto_trim_time = 3
server_run(min_threads: 2, max_threads: 2, auto_trim_time: auto_trim_time)
sleep 1 # wait for possible initial trim on run
thread_pool_expect false, :trim, nil, after: auto_trim_time
end

private

def thread_pool_expect(should_expect, expect_method, *expect_args, after: nil)
mock_pool = Minitest::Mock.new
mock_pool.expect(expect_method, *expect_args) if should_expect

@pool.singleton_class.class_eval do
define_method(expect_method) do |*args, **kwargs|
raise "unexpected #{expect_method} called on Puma::Threadpool" unless should_expect

mock_pool.public_send(expect_method, *args, **kwargs)
end
end

sleep after if after

assert mock_pool.verify # assert to satisfy proveit
server_run(min_threads: 2, max_threads: 2, auto_trim_time: 1)
refute @pool.instance_variable_get(:@auto_trim)
end
end
Loading