From 50b8398dd7bcd5d5c187da51b23a939c5f3de210 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Wed, 22 Feb 2023 15:12:12 -0600 Subject: [PATCH] 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 --- .gitignore | 2 ++ test/integration/app.rb | 2 +- test/integration_helper.rb | 1 + test/integration_test.rb | 10 ++++++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f37e0f56..efc495ac 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ /coverage .yardoc /doc +.bundle +vendor diff --git a/test/integration/app.rb b/test/integration/app.rb index abbe7009..dbc9e3a2 100644 --- a/test/integration/app.rb +++ b/test/integration/app.rb @@ -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 diff --git a/test/integration_helper.rb b/test/integration_helper.rb index 7cdbe879..997fa701 100644 --- a/test/integration_helper.rb +++ b/test/integration_helper.rb @@ -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 diff --git a/test/integration_test.rb b/test/integration_test.rb index 57c4a6d3..74b21cf5 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -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