Skip to content

Commit ccc4d5e

Browse files
authored
Fix intermittent profile.d/ scripts test failure from extra trailing newline (#2102)
The `profile.d/` scripts test asserts on captured `run_multi` command output using an exact match against a heredoc. The platform log stream that captures the output occasionally appends an extra trailing newline, which intermittently breaks these exact assertions. For example: https://github.com/heroku/heroku-buildpack-python/actions/runs/27144980449/job/80156740097?pr=2099#step:5:628 ``` Failures: 1) .profile.d/ scripts sets the required run-time env vars Failure/Error: expect(output).to eq(<<~OUTPUT) Python buildpack: Detected 512 MB available memory and 8 CPU cores. Python buildpack: Skipping automatic configuration of WEB_CONCURRENCY since it's already set. DYNO_RAM=512 WEB_CONCURRENCY=999 OUTPUT expected: "Python buildpack: Detected 512 MB available memory and 8 CPU cores.\nPython buildpack: Skipping auto...matic configuration of WEB_CONCURRENCY since it's already set.\nDYNO_RAM=512\nWEB_CONCURRENCY=999\n" got: "Python buildpack: Detected 512 MB available memory and 8 CPU cores.\nPython buildpack: Skipping auto...tic configuration of WEB_CONCURRENCY since it's already set.\nDYNO_RAM=512\nWEB_CONCURRENCY=999\n\n" (compared using ==) # ./spec/hatchet/profile_d_scripts_spec.rb:128:in 'block (4 levels) in <top (required)>' # ./vendor/bundle/ruby/4.0.0/gems/heroku_hatchet-8.0.6/lib/hatchet/app.rb:255:in 'block in Hatchet::App#run_multi' ``` Adds a `normalize_trailing_newlines` spec helper that collapses any trailing newlines down to a single one, and applies it to the exact-match assertions in the test. This absorbs the spurious trailing newline whilst still asserting on the rest of the output exactly. GUS-W-22900269.
1 parent 689b417 commit ccc4d5e

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

spec/hatchet/profile_d_scripts_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'WEB_CONCURRENCY=this-should-be-preserved',
2828
]
2929
app.run_multi(list_envs_cmd, heroku: { env: user_env_vars.join(';'), type: 'example-worker' }) do |output, _|
30-
expect(output).to eq(<<~OUTPUT)
30+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
3131
DYNO_RAM=512
3232
FORWARDED_ALLOW_IPS=*
3333
GUNICORN_CMD_ARGS=this-should-be-preserved
@@ -48,7 +48,7 @@
4848
# Check WEB_CONCURRENCY support when using a Standard-1X dyno.
4949
# We set the process type to `web` so that we can test the web-dyno-only log output.
5050
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'standard-1x', type: 'web' }) do |output, _|
51-
expect(output).to eq(<<~OUTPUT)
51+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
5252
Python buildpack: Detected 512 MB available memory and 8 CPU cores.
5353
Python buildpack: Defaulting WEB_CONCURRENCY to 2 based on the available memory.
5454
DYNO_RAM=512
@@ -59,7 +59,7 @@
5959

6060
# Standard-2X
6161
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'standard-2x', type: 'web' }) do |output, _|
62-
expect(output).to eq(<<~OUTPUT)
62+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
6363
Python buildpack: Detected 1024 MB available memory and 8 CPU cores.
6464
Python buildpack: Defaulting WEB_CONCURRENCY to 4 based on the available memory.
6565
DYNO_RAM=1024
@@ -70,7 +70,7 @@
7070

7171
# Performance-M
7272
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'performance-m', type: 'web' }) do |output, _|
73-
expect(output).to eq(<<~OUTPUT)
73+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
7474
Python buildpack: Detected 2560 MB available memory and 2 CPU cores.
7575
Python buildpack: Defaulting WEB_CONCURRENCY to 5 based on the number of CPU cores.
7676
DYNO_RAM=2560
@@ -81,7 +81,7 @@
8181

8282
# Performance-L
8383
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'performance-l', type: 'web' }) do |output, _|
84-
expect(output).to eq(<<~OUTPUT)
84+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
8585
Python buildpack: Detected 14336 MB available memory and 8 CPU cores.
8686
Python buildpack: Defaulting WEB_CONCURRENCY to 17 based on the number of CPU cores.
8787
DYNO_RAM=14336
@@ -92,7 +92,7 @@
9292

9393
# Performance-L-RAM
9494
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'performance-l-ram', type: 'web' }) do |output, _|
95-
expect(output).to eq(<<~OUTPUT)
95+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
9696
Python buildpack: Detected 30720 MB available memory and 4 CPU cores.
9797
Python buildpack: Defaulting WEB_CONCURRENCY to 9 based on the number of CPU cores.
9898
DYNO_RAM=30720
@@ -103,7 +103,7 @@
103103

104104
# Performance-XL
105105
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'performance-xl', type: 'web' }) do |output, _|
106-
expect(output).to eq(<<~OUTPUT)
106+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
107107
Python buildpack: Detected 63488 MB available memory and 8 CPU cores.
108108
Python buildpack: Defaulting WEB_CONCURRENCY to 17 based on the number of CPU cores.
109109
DYNO_RAM=63488
@@ -114,7 +114,7 @@
114114

115115
# Performance-2XL
116116
app.run_multi(list_concurrency_envs_cmd, heroku: { size: 'performance-2xl', type: 'web' }) do |output, _|
117-
expect(output).to eq(<<~OUTPUT)
117+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
118118
Python buildpack: Detected 129024 MB available memory and 16 CPU cores.
119119
Python buildpack: Defaulting WEB_CONCURRENCY to 33 based on the number of CPU cores.
120120
DYNO_RAM=129024
@@ -125,7 +125,7 @@
125125

126126
# Check that WEB_CONCURRENCY is preserved if set, but that we still set DYNO_RAM.
127127
app.run_multi(list_concurrency_envs_cmd, heroku: { env: 'WEB_CONCURRENCY=999', type: 'web' }) do |output, _|
128-
expect(output).to eq(<<~OUTPUT)
128+
expect(normalize_trailing_newlines(output)).to eq(<<~OUTPUT)
129129
Python buildpack: Detected 512 MB available memory and 8 CPU cores.
130130
Python buildpack: Skipping automatic configuration of WEB_CONCURRENCY since it's already set.
131131
DYNO_RAM=512

spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def clean_output(output)
6262
.gsub(/\e\[[0-9;]+m/, '')
6363
end
6464

65+
def normalize_trailing_newlines(output)
66+
# The platform log stream that captures `run`/`run_multi` command output occasionally appends
67+
# an extra trailing newline, which otherwise intermittently breaks exact output assertions.
68+
output.sub(/\n+\z/, "\n")
69+
end
70+
6571
def update_buildpacks(app, buildpacks)
6672
# Updates the list of buildpacks for an existing app, until Hatchet supports this natively:
6773
# https://github.com/heroku/hatchet/issues/166

0 commit comments

Comments
 (0)