heroku_hatchet 7.2.0 → 7.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -5
- data/CHANGELOG.md +46 -2
- data/README.md +22 -3
- data/bin/hatchet +1 -1
- data/etc/ci_setup.rb +2 -0
- data/etc/setup_heroku.sh +1 -1
- data/hatchet.gemspec +2 -2
- data/lib/hatchet.rb +20 -0
- data/lib/hatchet/app.rb +102 -72
- data/lib/hatchet/config.rb +2 -2
- data/lib/hatchet/git_app.rb +14 -10
- data/lib/hatchet/heroku_run.rb +96 -0
- data/lib/hatchet/reaper.rb +4 -4
- data/lib/hatchet/templates/dependabot.erb +1 -1
- data/lib/hatchet/test_run.rb +17 -12
- data/lib/hatchet/version.rb +1 -1
- data/spec/hatchet/allow_failure_git_spec.rb +1 -1
- data/spec/hatchet/app_spec.rb +97 -33
- data/spec/hatchet/ci_spec.rb +2 -2
- data/spec/hatchet/config_spec.rb +4 -0
- data/spec/hatchet/local_repo_spec.rb +9 -0
- data/spec/hatchet/lock_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/unit/heroku_run_spec.rb +115 -0
- data/spec/unit/shell_throttle_spec.rb +142 -0
- metadata +11 -22
- data/spec/unit/shell_throttle.rb +0 -28
data/spec/hatchet/config_spec.rb
CHANGED
@@ -6,6 +6,10 @@ describe "ConfigTest" do
|
|
6
6
|
expect(@config.path_for_name("rails3_mri_193")).to(eq("repo_fixtures/repos/rails3/rails3_mri_193"))
|
7
7
|
end
|
8
8
|
|
9
|
+
it("config path for name with full repo name") do
|
10
|
+
expect(@config.path_for_name("rails3/rails3_mri_193")).to(eq("repo_fixtures/repos/rails3/rails3_mri_193"))
|
11
|
+
end
|
12
|
+
|
9
13
|
it("config dirs") do
|
10
14
|
{ "repo_fixtures/repos/bundler/no_lockfile" => "https://github.com/sharpstone/no_lockfile.git", "repo_fixtures/repos/default/default_ruby" => "https://github.com/sharpstone/default_ruby.git", "repo_fixtures/repos/rails2/rails2blog" => "https://github.com/sharpstone/rails2blog.git", "repo_fixtures/repos/rails3/rails3_mri_193" => "https://github.com/sharpstone/rails3_mri_193.git" }.each do |key, value|
|
11
15
|
assert_include(key, value, @config.dirs)
|
@@ -11,6 +11,15 @@ describe "LocalRepoTest" do
|
|
11
11
|
expect(ENV[env_name]).to eq(env_name)
|
12
12
|
end
|
13
13
|
|
14
|
+
it "in directory fork captures stdout even when there is an error" do
|
15
|
+
expect {
|
16
|
+
Hatchet::App.new("default_ruby").in_directory_fork do
|
17
|
+
puts "hello_there"
|
18
|
+
raise "error"
|
19
|
+
end
|
20
|
+
}.to raise_error(/hello_there/)
|
21
|
+
end
|
22
|
+
|
14
23
|
it "repos checked into git" do
|
15
24
|
begin
|
16
25
|
fixture_dir = "repo_fixtures/different-folder-for-checked-in-repos/default_ruby"
|
data/spec/hatchet/lock_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,8 @@ RSpec.configure do |config|
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
ENV['
|
17
|
+
ENV['HATCHET_BUILDPACK_BASE'] = "https://github.com/heroku/heroku-buildpack-ruby.git"
|
18
|
+
ENV['HATCHET_BUILDPACK_BRANCH'] = "main"
|
18
19
|
|
19
20
|
require 'parallel_tests/test/runtime_logger' if ENV['RECORD_RUNTIME']
|
20
21
|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "HerokuRun" do
|
4
|
+
def fake_app
|
5
|
+
app = Object.new
|
6
|
+
def app.name; "fake_app"; end
|
7
|
+
app
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "options" do
|
11
|
+
it "escapes by default" do
|
12
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: fake_app)
|
13
|
+
expect(run_obj.command).to eq("heroku run --app=fake_app --exit-code -- ruby\\ -v")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "escapes by default" do
|
17
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: fake_app, heroku: { "exit-code" => Hatchet::App::SkipDefaultOption })
|
18
|
+
expect(run_obj.command).to eq("heroku run --app=fake_app -- ruby\\ -v")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "allows setting switch values by default" do
|
22
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: fake_app, heroku: { "no-tty" => nil })
|
23
|
+
expect(run_obj.command).to eq("heroku run --app=fake_app --exit-code --no-tty -- ruby\\ -v")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can be used to pass env vars" do
|
27
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: fake_app, heroku: { "env" => "HELLO=ohai;NAME=world" })
|
28
|
+
expect(run_obj.command).to eq("heroku run --app=fake_app --exit-code --env=HELLO\\=ohai\\;NAME\\=world -- ruby\\ -v")
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it "lets me use raw values" do
|
33
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: fake_app, raw: true )
|
34
|
+
expect(run_obj.command).to eq("heroku run --app=fake_app --exit-code -- ruby -v")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "retry on empty" do
|
39
|
+
before(:all) do
|
40
|
+
@app = Hatchet::Runner.new("default_ruby")
|
41
|
+
@app.setup!
|
42
|
+
end
|
43
|
+
|
44
|
+
after(:all) do
|
45
|
+
@app.teardown!
|
46
|
+
end
|
47
|
+
|
48
|
+
it "retries 3 times on empty result" do
|
49
|
+
stderr = StringIO.new
|
50
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: @app, stderr: stderr)
|
51
|
+
|
52
|
+
def run_obj.run_shell!
|
53
|
+
@output = ""
|
54
|
+
@status = Object.new
|
55
|
+
end
|
56
|
+
|
57
|
+
run_obj.call
|
58
|
+
|
59
|
+
expect(run_obj.instance_variable_get(:@empty_fail_count)).to eq(3)
|
60
|
+
expect(stderr.string).to include("retrying the command.")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "retries 0 times on NON empty result" do
|
64
|
+
stderr = StringIO.new
|
65
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: @app, stderr: stderr)
|
66
|
+
|
67
|
+
def run_obj.run_shell!
|
68
|
+
@output = "not empty"
|
69
|
+
@status = Object.new
|
70
|
+
end
|
71
|
+
|
72
|
+
run_obj.call
|
73
|
+
|
74
|
+
expect(run_obj.instance_variable_get(:@empty_fail_count)).to eq(0)
|
75
|
+
expect(run_obj.output).to eq("not empty")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "retries 0 times on empty result when disabled" do
|
79
|
+
stderr = StringIO.new
|
80
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: @app, stderr: stderr, retry_on_empty: false)
|
81
|
+
|
82
|
+
def run_obj.run_shell!
|
83
|
+
@output = ""
|
84
|
+
@status = Object.new
|
85
|
+
end
|
86
|
+
|
87
|
+
run_obj.call
|
88
|
+
|
89
|
+
expect(run_obj.instance_variable_get(:@empty_fail_count)).to eq(0)
|
90
|
+
expect(stderr.string).to_not include("retrying the command.")
|
91
|
+
end
|
92
|
+
|
93
|
+
it "retries 0 times on empty result when disabled via ENV var" do
|
94
|
+
begin
|
95
|
+
original_env = ENV["HATCHET_DISABLE_EMPTY_RUN_RETRY"]
|
96
|
+
ENV["HATCHET_DISABLE_EMPTY_RUN_RETRY"] = "1"
|
97
|
+
stderr = StringIO.new
|
98
|
+
run_obj = Hatchet::HerokuRun.new("ruby -v", app: @app, stderr: stderr)
|
99
|
+
|
100
|
+
def run_obj.run_shell!
|
101
|
+
@output = ""
|
102
|
+
@status = Object.new
|
103
|
+
end
|
104
|
+
|
105
|
+
run_obj.call
|
106
|
+
|
107
|
+
expect(run_obj.instance_variable_get(:@empty_fail_count)).to eq(0)
|
108
|
+
expect(stderr.string).to_not include("retrying the command.")
|
109
|
+
ensure
|
110
|
+
ENV["HATCHET_DISABLE_EMPTY_RUN_RETRY"] = original_env
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "ShellThrottle" do
|
4
|
+
before(:each) do
|
5
|
+
throttle = PlatformAPI.rate_throttle
|
6
|
+
def throttle.sleep(value)
|
7
|
+
# No sleep, faster tests
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
throttle = PlatformAPI.rate_throttle
|
13
|
+
def throttle.sleep(value)
|
14
|
+
super # Unstub
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "class unit test" do
|
19
|
+
before(:all) do
|
20
|
+
@platform_api = Hatchet::Runner.new("default_ruby").platform_api
|
21
|
+
end
|
22
|
+
|
23
|
+
it "throttles when throw is called" do
|
24
|
+
@count = 0
|
25
|
+
Hatchet::ShellThrottle.new(platform_api: @platform_api).call do
|
26
|
+
@count += 1
|
27
|
+
if @count >= 2
|
28
|
+
# No throttle
|
29
|
+
else
|
30
|
+
throw(:throttle)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
expect(@count).to eq(2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not throttle when throw is NOT called" do
|
37
|
+
@count = 0
|
38
|
+
Hatchet::ShellThrottle.new(platform_api: @platform_api).call do
|
39
|
+
@count += 1
|
40
|
+
end
|
41
|
+
expect(@count).to eq(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "git push throttle" do
|
46
|
+
it "rate throttles `git push` with output variation 1" do
|
47
|
+
app = Hatchet::GitApp.new("default_ruby")
|
48
|
+
def app.git_push_heroku_yall
|
49
|
+
@_git_push_heroku_yall_call_count ||= 0
|
50
|
+
@_git_push_heroku_yall_call_count += 1
|
51
|
+
if @_git_push_heroku_yall_call_count >= 2
|
52
|
+
"Success"
|
53
|
+
else
|
54
|
+
raise Hatchet::App::FailedDeployError.new(
|
55
|
+
self,
|
56
|
+
"message",
|
57
|
+
output: "Your account reached the API rate limit Please wait a few minutes before making new requests"
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def app.sleep_called?; @sleep_called; end
|
63
|
+
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end
|
64
|
+
|
65
|
+
app.push_without_retry!
|
66
|
+
|
67
|
+
expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "rate throttles `git push` with output variation 2" do
|
71
|
+
app = Hatchet::GitApp.new("default_ruby")
|
72
|
+
def app.git_push_heroku_yall
|
73
|
+
@_git_push_heroku_yall_call_count ||= 0
|
74
|
+
@_git_push_heroku_yall_call_count += 1
|
75
|
+
if @_git_push_heroku_yall_call_count >= 2
|
76
|
+
"Success"
|
77
|
+
else
|
78
|
+
raise Hatchet::App::FailedDeployError.new(
|
79
|
+
self,
|
80
|
+
"message",
|
81
|
+
output: "RPC failed; HTTP 429 curl 22 The requested URL returned error: 429 Too Many Requests"
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def app.sleep_called?; @sleep_called; end
|
87
|
+
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end
|
88
|
+
|
89
|
+
app.push_without_retry!
|
90
|
+
|
91
|
+
expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "rate throttles `git push` with output variation 3" do
|
95
|
+
app = Hatchet::GitApp.new("default_ruby")
|
96
|
+
def app.git_push_heroku_yall
|
97
|
+
@_git_push_heroku_yall_call_count ||= 0
|
98
|
+
@_git_push_heroku_yall_call_count += 1
|
99
|
+
if @_git_push_heroku_yall_call_count >= 2
|
100
|
+
"Success"
|
101
|
+
else
|
102
|
+
raise Hatchet::App::FailedDeployError.new(
|
103
|
+
self,
|
104
|
+
"message",
|
105
|
+
output: "error: RPC failed; HTTP 429 curl 22 The requested URL returned error: 429"
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def app.sleep_called?; @sleep_called; end
|
111
|
+
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end
|
112
|
+
|
113
|
+
app.push_without_retry!
|
114
|
+
|
115
|
+
expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "rate throttles `git push` with output variation 4" do
|
119
|
+
app = Hatchet::GitApp.new("default_ruby")
|
120
|
+
def app.git_push_heroku_yall
|
121
|
+
@_git_push_heroku_yall_call_count ||= 0
|
122
|
+
@_git_push_heroku_yall_call_count += 1
|
123
|
+
if @_git_push_heroku_yall_call_count >= 2
|
124
|
+
"Success"
|
125
|
+
else
|
126
|
+
raise Hatchet::App::FailedDeployError.new(
|
127
|
+
self,
|
128
|
+
"message",
|
129
|
+
output: "error: RPC failed; result=22, HTTP code = 429"
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def app.sleep_called?; @sleep_called; end
|
135
|
+
def app.what_is_git_push_heroku_yall_call_count; @_git_push_heroku_yall_call_count; end
|
136
|
+
|
137
|
+
app.push_without_retry!
|
138
|
+
|
139
|
+
expect(app.what_is_git_push_heroku_yall_call_count).to be(2)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku_hatchet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: platform-api
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: threaded
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,20 +136,6 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: travis
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '1'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '1'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rspec-retry
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +178,7 @@ files:
|
|
192
178
|
- lib/hatchet/app.rb
|
193
179
|
- lib/hatchet/config.rb
|
194
180
|
- lib/hatchet/git_app.rb
|
181
|
+
- lib/hatchet/heroku_run.rb
|
195
182
|
- lib/hatchet/init_project.rb
|
196
183
|
- lib/hatchet/reaper.rb
|
197
184
|
- lib/hatchet/reaper/app_age.rb
|
@@ -219,9 +206,10 @@ files:
|
|
219
206
|
- spec/hatchet/local_repo_spec.rb
|
220
207
|
- spec/hatchet/lock_spec.rb
|
221
208
|
- spec/spec_helper.rb
|
209
|
+
- spec/unit/heroku_run_spec.rb
|
222
210
|
- spec/unit/init_spec.rb
|
223
211
|
- spec/unit/reaper_spec.rb
|
224
|
-
- spec/unit/
|
212
|
+
- spec/unit/shell_throttle_spec.rb
|
225
213
|
- tmp/parallel_runtime_test.log
|
226
214
|
homepage: https://github.com/heroku/hatchet
|
227
215
|
licenses:
|
@@ -235,14 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
223
|
requirements:
|
236
224
|
- - ">="
|
237
225
|
- !ruby/object:Gem::Version
|
238
|
-
version:
|
226
|
+
version: 2.2.0
|
239
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
228
|
requirements:
|
241
229
|
- - ">="
|
242
230
|
- !ruby/object:Gem::Version
|
243
231
|
version: '0'
|
244
232
|
requirements: []
|
245
|
-
rubygems_version: 3.
|
233
|
+
rubygems_version: 3.2.3
|
246
234
|
signing_key:
|
247
235
|
specification_version: 4
|
248
236
|
summary: Hatchet is a an integration testing library for developing Heroku buildpacks.
|
@@ -257,6 +245,7 @@ test_files:
|
|
257
245
|
- spec/hatchet/local_repo_spec.rb
|
258
246
|
- spec/hatchet/lock_spec.rb
|
259
247
|
- spec/spec_helper.rb
|
248
|
+
- spec/unit/heroku_run_spec.rb
|
260
249
|
- spec/unit/init_spec.rb
|
261
250
|
- spec/unit/reaper_spec.rb
|
262
|
-
- spec/unit/
|
251
|
+
- spec/unit/shell_throttle_spec.rb
|
data/spec/unit/shell_throttle.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "ShellThrottle" do
|
4
|
-
it "throttles when throw is called" do
|
5
|
-
platform_api = Hatchet::Runner.new("default_ruby").platform_api
|
6
|
-
|
7
|
-
@count = 0
|
8
|
-
Hatchet::ShellThrottle.new(platform_api: platform_api).call do
|
9
|
-
@count += 1
|
10
|
-
if @count >= 2
|
11
|
-
# No throttle
|
12
|
-
else
|
13
|
-
throw(:throttle)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
expect(@count).to eq(2)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "does not throttle when throw is NOT called" do
|
20
|
-
platform_api = Hatchet::Runner.new("default_ruby").platform_api
|
21
|
-
|
22
|
-
@count = 0
|
23
|
-
Hatchet::ShellThrottle.new(platform_api: platform_api).call do
|
24
|
-
@count += 1
|
25
|
-
end
|
26
|
-
expect(@count).to eq(1)
|
27
|
-
end
|
28
|
-
end
|