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

Remove bash unit tests #324

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
41 changes: 0 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,46 +63,6 @@ jobs:
- name: Run Hatchet integration tests
run: bundle exec parallel_split_test test/spec/

buildpack-testrunner:
runs-on: ubuntu-22.04
needs: lint
env:
SHUNIT_HOME: /tmp/shunit2-2.1.6
# Note the missing STACK environment variable here. This works since there is a default value in the buildpack
# source. I ported this as-is from the Travis config. Given we're trying to get rid of testrunner entirely,
# it will stay like this. If we, for some reason, decide to keep testrunner, we should look into a fixed STACK env var.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
- name: Download and unpack shunit 2.1.6
run: curl -sSf --retry 3 --retry-connrefused --connect-timeout 5 https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz | tar xz -C /tmp/
- name: Clone heroku-buildpack-testrunner
run: git clone https://github.com/heroku/heroku-buildpack-testrunner.git /tmp/testrunner
- name: Apply heroku-buildpack-testrunner patches to enforce bash shell
run: |
cd /tmp/testrunner
git apply <<'EOF'
diff --git a/bin/run b/bin/run
index 0d5b790..a0ff25c 100755
--- a/bin/run
+++ b/bin/run
@@ -101,7 +101,7 @@ for bp in ${@}; do
suite_start_time="$(date +%s)"

echo " TEST SUITE: $(basename ${f})"
- ${SHUNIT_HOME?"'SHUNIT_HOME' environment variable must be set"}/src/shunit2 ${f} | indent
+ /bin/bash ${SHUNIT_HOME?"'SHUNIT_HOME' environment variable must be set"}/src/shunit2 ${f} | indent
exit_code=$(max ${exit_code} ${PIPESTATUS[0]})

suite_end_time="$(date +%s)"

EOF
- name: Execute buildpack-testrunner
run: /tmp/testrunner/bin/run .

unit-tests:
name: "Unit Tests (${{ matrix.stack }})"
runs-on: ubuntu-22.04
Expand All @@ -117,7 +77,6 @@ jobs:
stack: ["heroku-20", "heroku-22", "heroku-24"]
steps:
- uses: actions/checkout@v4
- run: test/v2
- run: test/jdbc.sh

container-test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.swp
.DS_Store
heroku-buildpack-jvm-common.tgz
.rspec_status
79 changes: 0 additions & 79 deletions test/compile_test.sh

This file was deleted.

Empty file.
206 changes: 65 additions & 141 deletions test/spec/java_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,151 +2,75 @@

require_relative 'spec_helper'

describe 'Java' do
%w[1.8 8 11 17 23 11.0.23 openjdk-11.0.23 zulu-11.0.23 heroku-17 zulu-17 heroku-21 zulu-21].each do |jdk_version|
context "when a simple java app on jdk-#{jdk_version}" do
it 'deploys' do
new_default_hatchet_runner('java-servlets-sample').tap do |app|
EXPECTED_JAVA_VERSIONS = {
'heroku-20': {
'1.8': 'OpenJDK Runtime Environment (build 1.8.0_432-heroku-b06)',
'8': 'OpenJDK Runtime Environment (build 1.8.0_432-heroku-b06)',
'11': 'OpenJDK Runtime Environment (build 11.0.25+9)',
'17': 'OpenJDK Runtime Environment (build 17.0.13+11)',
'21': 'OpenJDK Runtime Environment (build 21.0.5+11)',
'23': 'OpenJDK Runtime Environment (build 23.0.1+11)',
'heroku-21': 'OpenJDK Runtime Environment (build 21.0.5+11)',
'zulu-21': 'OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)',
},
'heroku-22': {
'1.8': 'OpenJDK 64-Bit Server VM (Zulu 8.82.0.21-CA-linux64) (build 25.432-b06, mixed mode)',
'8': 'OpenJDK 64-Bit Server VM (Zulu 8.82.0.21-CA-linux64) (build 25.432-b06, mixed mode)',
'11': 'OpenJDK Runtime Environment Zulu11.76+21-CA (build 11.0.25+9-LTS)',
'17': 'OpenJDK Runtime Environment Zulu17.54+21-CA (build 17.0.13+11-LTS)',
'21': 'OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)',
'23': 'OpenJDK Runtime Environment Zulu23.30+13-CA (build 23.0.1+11)',
'heroku-21': 'OpenJDK Runtime Environment (build 21.0.5+11)',
'zulu-21': 'OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)',
},
'heroku-24': {
'1.8': 'OpenJDK 64-Bit Server VM (Zulu 8.82.0.21-CA-linux64) (build 25.432-b06, mixed mode)',
'8': 'OpenJDK 64-Bit Server VM (Zulu 8.82.0.21-CA-linux64) (build 25.432-b06, mixed mode)',
'11': 'OpenJDK Runtime Environment Zulu11.76+21-CA (build 11.0.25+9-LTS)',
'17': 'OpenJDK Runtime Environment Zulu17.54+21-CA (build 17.0.13+11-LTS)',
'21': 'OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)',
'23': 'OpenJDK Runtime Environment Zulu23.30+13-CA (build 23.0.1+11)',
'heroku-21': 'OpenJDK Runtime Environment (build 21.0.5+11)',
'zulu-21': 'OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)',
},
}.freeze

FILE_MD5_HASHES = {
'.profile.d/jvmcommon.sh': 'f4727529254d7e5bd9f7de2ec110bffe',
'.profile.d/default-proc-warning.sh': 'ad34c4eb52bb81556a9ad77753ee25ed',
'.profile.d/heroku-jvm-metrics.sh': '9f48b384bc3d9161e45e15906793b191',
'.profile.d/jdbc.sh': '7a5ce665af22b057c027b1080d2df3d3',
'.profile.d/jvm-redis.sh': '7873896b3392a91b35af7dcfad115d6b',
'.heroku/with_jmap/bin/java': '95d6c4e98ff173e6c9bcb460d8935f14',
'.heroku/with_jmap_and_jstack/bin/java': 'f00aa96dbb004805131979bb88eb1a8e',
'.heroku/with_jstack/bin/java': 'ef435bf082921e7f32801795c2a85434',
'.heroku/bin/heroku-metrics-agent.jar': '050e7e5b418d0fccd020fa825e915f58',
'.heroku/bin/with_jmap': '6674c0a0be0ac28ac34767da39e8d2ec',
'.heroku/bin/with_jmap_and_jstack': '4e3d7b42abfb20502a4e47f963286625',
'.heroku/bin/with_jstack': '31eb167b16d3dcc2450983964aa57ee7',
}.freeze

RSpec.describe 'Java installation' do
EXPECTED_JAVA_VERSIONS.each do |stack, expected_java_versions|
expected_java_versions.each do |openjdk_selection_string, java_version|
# Skip any tests where the Hatchet stack does not match the stack to test.
# We're not using the tagging approach with "stacks" as it does not work with dynamically
# generated tests.
next if ENV.fetch('HATCHET_DEFAULT_STACK') != stack.to_s

context "when stack is '#{stack}' and selection string is '#{openjdk_selection_string}'" do
let(:app) { Hatchet::Runner.new('empty') }

it 'installs the correct OpenJDK version, metrics agent, tools and profile.d scripts' do
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
set_java_version(Dir.pwd, openjdk_selection_string)
end
app.deploy do
if jdk_version.start_with?('zulu')
expect(app.output).to include("Installing Azul Zulu OpenJDK #{jdk_version.gsub('zulu-', '')}")
elsif jdk_version.start_with?('openjdk')
expect(app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('openjdk-', '')}")
elsif jdk_version.start_with?('heroku')
expect(app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('heroku-', '')}")
else
expect(app.output).to include("Installing OpenJDK #{jdk_version}")
end

expect(app.output).not_to include('WARNING: No OpenJDK version specified')
expect(app.output).to include('BUILD SUCCESS')
expect(successful_body(app)).to eq('Hello from Java!')
end
end
end
end
end

context 'when a system.properties file with no java.runtime.version' do
it 'deploys' do
new_default_hatchet_runner('java-servlets-sample').tap do |app|
app.before_deploy do
write_sys_props(Dir.pwd, 'maven.version=3.3.9')
end
app.deploy do
expect(app.output).to include('WARNING: No OpenJDK version specified')

if app.stack == 'heroku-24'
expect(app.output).to include('Installing OpenJDK 21')
else
expect(app.output).to include('Installing OpenJDK 1.8')
end

expect(app.output).to include('BUILD SUCCESS')
expect(successful_body(app)).to eq('Hello from Java!')
end
end
end
end

%w[1.8 8 11 17 21 23].each do |jdk_version|
context "when jdk-overlay on #{jdk_version}" do
it 'deploys' do
new_default_hatchet_runner('java-overlay-test').tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
end
app.deploy do
if jdk_version.start_with?('zulu')
expect(app.output).to include("Installing Azul Zulu OpenJDK #{jdk_version.gsub('zulu-', '')}")
elsif jdk_version.start_with?('openjdk')
expect(app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('openjdk-', '')}")
elsif jdk_version.start_with?('heroku')
expect(app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('heroku-', '')}")
else
expect(app.output).to include("Installing OpenJDK #{jdk_version}")
end

expect(app.output).not_to include('WARNING: No OpenJDK version specified')
expect(app.output).to include('BUILD SUCCESS')

# Workaround (August 2020):
# When running on CircleCI (and only there), the first app.run command of the test suite will have ^@^@
# prepended to the result string. It looks like caret encoding for two null bytes and the cause is still
# unknown.
cacerts_md5_jdk = app.run('md5sum .jdk/jre/lib/security/cacerts').split[0].delete('^@^@')
sleep 5
cacerts_md5_overlay = app.run('md5sum .jdk-overlay/jre/lib/security/cacerts').split[0].delete('^@^@')

expect(cacerts_md5_jdk).to eq(cacerts_md5_overlay)
end
end
end
end

context "when korvan on jdk-#{jdk_version}" do
it 'runs commands' do
new_default_hatchet_runner('korvan').tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
end

app.deploy do |deployed_app|
if jdk_version.start_with?('zulu')
expect(deployed_app.output).to include("Installing Azul Zulu OpenJDK #{jdk_version.gsub('zulu-', '')}")
elsif jdk_version.start_with?('openjdk')
expect(deployed_app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('openjdk-', '')}")
elsif jdk_version.start_with?('heroku')
expect(deployed_app.output).to include("Installing Heroku OpenJDK #{jdk_version.gsub('heroku-', '')}")
else
expect(deployed_app.output).to include("Installing OpenJDK #{jdk_version}")
end

sleep 1
expect(deployed_app.run('echo $JAVA_TOOL_OPTIONS'))
.not_to include('-Xmx300m -Xss512k')

sleep 1
expect(deployed_app.run('echo $JAVA_OPTS'))
.to include('-Xmx300m -Xss512k')

sleep 1
if jdk_version.start_with?('zulu-1.')
# Skip exit-code default option, required to execute a process from Procfile instead of a command in bash.
expect(deployed_app.run('jce', { heroku: { 'exit-code' => Hatchet::App::SkipDefaultOption } }))
.to include('Illegal key size or default parameters')
else
# Skip exit-code default option, required to execute a process from Procfile instead of a command in bash.
expect(deployed_app.run('jce', { heroku: { 'exit-code' => Hatchet::App::SkipDefaultOption } }))
.to include('Encrypting, "Test"')
.and include('Decrypted: Test')
end

sleep 1
# Skip exit-code default option, required to execute a process from Procfile instead of a command in bash.
expect(deployed_app.run('netpatch', { heroku: { 'exit-code' => Hatchet::App::SkipDefaultOption } }))
.to include('name:eth0 (eth0)')
.and include('name:lo (lo)')

sleep 1
# Skip exit-code default option, required to execute a process from Procfile instead of a command in bash.
expect(deployed_app.run('https', { heroku: { 'exit-code' => Hatchet::App::SkipDefaultOption } }))
.to include('Successfully invoked HTTPS service.')
.and match(/"X-Forwarded-Proto(col)?":\s?"https"/)

if !jdk_version.match(/^9/) &&
!jdk_version.match(/^openjdk-9/) &&
!jdk_version.match(/^zulu-9/) &&
!jdk_version.match(/^[12][0-9]/) &&
!jdk_version.match(/^openjdk-[12][0-9]/)
app.deploy do |app|
expect(app.run('java -version')).to include(java_version)

sleep 1
# Skip exit-code default option, required to execute a process from Procfile instead of a command in bash.
expect(deployed_app.run('pgssl', { heroku: { 'exit-code' => Hatchet::App::SkipDefaultOption } }))
.to match(/sslmode: require/)
FILE_MD5_HASHES.each do |file_path, md5_hash|
expect(app.run("md5sum #{file_path}")).to start_with md5_hash
end
end
end
Expand Down
22 changes: 12 additions & 10 deletions test/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
require 'date'

ENV['RACK_ENV'] = 'test'
ENV['HATCHET_BUILDPACK_BASE'] ||= 'https://github.com/heroku/heroku-buildpack-jvm-common.git'

RSpec.configure do |config|
config.filter_run focused: true unless ENV['CI']
config.run_all_when_everything_filtered = true
config.alias_example_to :fit, focused: true
config.full_backtrace = true
config.verbose_retry = true # show retry status in spec process
config.default_retry_count = 2 if ENV['CI'] # retry all tests that fail again

config.expect_with :rspec do |c|
c.syntax = :expect
end
# Disables the legacy rspec globals and monkey-patched `should` syntax.
config.disable_monkey_patching!
# Enable flags like --only-failures and --next-failure.
config.example_status_persistence_file_path = '.rspec_status'
# Allows limiting a spec run to individual examples or groups by tagging them
# with `:focus` metadata via the `fit`, `fcontext` and `fdescribe` aliases.
config.filter_run_when_matching :focus
# Allows declaring on which stacks a test/group should run by tagging it with `stacks`.
config.filter_run_excluding stacks: ->(stacks) { !stacks.include?(ENV.fetch('HATCHET_DEFAULT_STACK')) }
# Make rspec-retry output a retry message when its had to retry a test.
config.verbose_retry = true
end

def new_default_hatchet_runner(*, **kwargs)
Expand Down
Loading
Loading