Skip to content

Commit

Permalink
centralize and re-use timeout/sigterm related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dzuelke committed Jan 23, 2024
1 parent f67c563 commit 9273bab
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 159 deletions.
31 changes: 0 additions & 31 deletions test/spec/php-7.4_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

describe "A basic PHP 7.4 application", :requires_php_on_stack => "7.4" do
include_examples "A basic PHP application", "7.4"

context "with an index.php that allows for different execution times" do
['apache2', 'nginx'].each do |server|
context "running the #{server} web server" do
let(:app) {
new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '7.4.*'") or raise "Failed to require PHP version" }
)
}

# FIXME: move to php_shared.rb once all PHPs are rebuilt with that tracing capability
it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
app.deploy do |app|
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
expect(output).to match(/exited on signal/)
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions test/spec/php-7.4_sigterm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "php_sigterm_shared"

describe "A PHP 7.4 application with long-running requests", :requires_php_on_stack => "7.4" do
include_examples "A PHP application with long-running requests", "7.4"
end
31 changes: 0 additions & 31 deletions test/spec/php-8.0_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

describe "A basic PHP 8.0 application", :requires_php_on_stack => "8.0" do
include_examples "A basic PHP application", "8.0"

context "with an index.php that allows for different execution times" do
['apache2', 'nginx'].each do |server|
context "running the #{server} web server" do
let(:app) {
new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '8.0.*'") or raise "Failed to require PHP version" }
)
}

# FIXME: move to php_shared.rb once all PHPs are rebuilt with that tracing capability
it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
app.deploy do |app|
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
expect(output).to match(/exited on signal/)
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions test/spec/php-8.0_sigterm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "php_sigterm_shared"

describe "A PHP 8.0 application with long-running requests", :requires_php_on_stack => "8.0" do
include_examples "A PHP application with long-running requests", "8.0"
end
31 changes: 0 additions & 31 deletions test/spec/php-8.1_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

describe "A basic PHP 8.1 application", :requires_php_on_stack => "8.1" do
include_examples "A basic PHP application", "8.1"

context "with an index.php that allows for different execution times" do
['apache2', 'nginx'].each do |server|
context "running the #{server} web server" do
let(:app) {
new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '8.1.*'") or raise "Failed to require PHP version" }
)
}

# FIXME: move to php_shared.rb once all PHPs are rebuilt with that tracing capability
it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
app.deploy do |app|
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
expect(output).to match(/exited on signal/)
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions test/spec/php-8.1_sigterm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "php_sigterm_shared"

describe "A PHP 8.1 application with long-running requests", :requires_php_on_stack => "8.1" do
include_examples "A PHP application with long-running requests", "8.1"
end
31 changes: 0 additions & 31 deletions test/spec/php-8.2_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

describe "A basic PHP 8.2 application", :requires_php_on_stack => "8.2" do
include_examples "A basic PHP application", "8.2"

context "with an index.php that allows for different execution times" do
['apache2', 'nginx'].each do |server|
context "running the #{server} web server" do
let(:app) {
new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '8.2.*'") or raise "Failed to require PHP version" }
)
}

# FIXME: move to php_shared.rb once all PHPs are rebuilt with that tracing capability
it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
app.deploy do |app|
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
expect(output).to match(/exited on signal/)
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions test/spec/php-8.2_sigterm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "php_sigterm_shared"

describe "A PHP 8.2 application with long-running requests", :requires_php_on_stack => "8.2" do
include_examples "A PHP application with long-running requests", "8.2"
end
31 changes: 0 additions & 31 deletions test/spec/php-8.3_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,4 @@

describe "A basic PHP 8.3 application", :requires_php_on_stack => "8.3" do
include_examples "A basic PHP application", "8.3"

context "with an index.php that allows for different execution times" do
['apache2', 'nginx'].each do |server|
context "running the #{server} web server" do
let(:app) {
new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '8.3.*'") or raise "Failed to require PHP version" }
)
}

# FIXME: move to php_shared.rb once all PHPs are rebuilt with that tracing capability
it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
app.deploy do |app|
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
expect(output).to match(/exited on signal/)
end
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions test/spec/php-8.3_sigterm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "php_sigterm_shared"

describe "A PHP 8.3 application with long-running requests", :requires_php_on_stack => "8.3" do
include_examples "A PHP application with long-running requests", "8.3"
end
26 changes: 22 additions & 4 deletions test/spec/sigterm_spec.rb → test/spec/php_sigterm_shared.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require_relative "spec_helper"

describe "A PHP application" do
context "with an index.php that allows for different execution times" do
shared_examples "A PHP application with long-running requests" do |series|
context "that uses #{series}" do
before(:all) do
@app = new_app_with_stack_and_platrepo('test/fixtures/sigterm', run_multi: true)
@app = new_app_with_stack_and_platrepo('test/fixtures/sigterm',
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs php '#{series}.*'") or raise "Failed to require PHP version" },
run_multi: true
)
@app.deploy
end

Expand All @@ -26,7 +29,7 @@
end
end

it "gracefully shuts down when all processes receives a SIGTERM because HEROKU_PHP_GRACEFUL_SIGTERM is on by default" do
it "gracefully shuts down when all processes receive a SIGTERM because HEROKU_PHP_GRACEFUL_SIGTERM is on by default" do
# first, launch in the background and get the pid
# then sleep five seconds to allow boot (semicolon before ! needs a space, Bash...)
# curl the sleep() script (and remember the curl pid)
Expand All @@ -40,6 +43,21 @@
expect(output).to match(/^request complete$/) # ensure a late log line is captured, meaning the logs tail process stays alive until the end
end
end

it "logs slowness after about 3 seconds, prints a trace, and terminates the process after about 30 seconds" do
# launch web server wrapped in a 40 second timeout
# once web server is ready, `read` unblocks and we curl the sleep() script which will take a few seconds to run
# after `curl` completes, `waitforit.sh` will shut down
cmd = "./waitforit.sh 40 'ready for connections' heroku-php-#{server} --verbose | { read && curl \"localhost:$PORT/index.php?wait=35\"; }"
retry_until retry: 3, sleep: 5 do
output = @app.run(cmd)
# ensure slowlog info and trace is there
expect(output).to include("executing too slow")
expect(output).to include("sleep() /app/index.php:5")
# ensure termination info is there
expect(output).to match(/execution timed out/)
end
end
end
end
end
Expand Down

0 comments on commit 9273bab

Please sign in to comment.