CI: Fix up integration stream test for Puma (#1887)

Fixes timing issue with Puma, adds 0.05 second to sleep, small changes to
asserts and time calc.

Ensure Puma creates its request serving thread at server boot: If min_threads is
zero, the thread is created when the first request is received, which would
increase the time for the test assert that failed. For CI, if min_threads is
one, the thread is created as the server boots.

Close https://github.com/puma/puma/issues/3085
This commit is contained in:
MSP-Greg 2023-02-22 15:12:12 -06:00 committed by GitHub
parent 0a424f01ee
commit 50b8398dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 5 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@
/coverage
.yardoc
/doc
.bundle
vendor

View File

@ -20,7 +20,7 @@ get '/stream' do
stream do |out|
sleep 0.1
out << "a"
sleep 1.2
sleep 1.25
out << "b"
end
end

View File

@ -35,6 +35,7 @@ module IntegrationHelper
def initialize(server, port, async)
@installed, @pipe, @server, @port = nil, nil, server, port
ENV['PUMA_MIN_THREADS'] = '1' if server == 'puma'
if async
Server.all_async << self
else

View File

@ -28,15 +28,17 @@ class IntegrationTest < Minitest::Test
it 'streams' do
next if server.webrick? or server.trinidad?
times, chunks = [Time.now], []
times, chunks = [Process.clock_gettime(Process::CLOCK_MONOTONIC)], []
server.get_stream do |chunk|
next if chunk.empty?
chunks << chunk
times << Time.now
times << Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
assert_equal ["a", "b"], chunks
assert times[1] - times[0] < 1
assert times[2] - times[1] > 1
int1 = (times[1] - times[0]).round 2
int2 = (times[2] - times[1]).round 2
assert_operator 1, :>, int1
assert_operator 1, :<, int2
end
it 'starts the correct server' do