Skip to content

Commit 6c11f6e

Browse files
committed
Implement timeout on each integration rspec test
1 parent a93eb55 commit 6c11f6e

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Style/HashSyntax:
1919

2020
# We are setting absurdly high limits but should work to tighten these up.
2121
Metrics/AbcSize:
22-
Max: 200
22+
Max: 100
2323
Severity: warning
2424

2525
Metrics/BlockLength:
@@ -34,7 +34,7 @@ Metrics/CyclomaticComplexity:
3434
Severity: warning
3535

3636
Metrics/MethodLength:
37-
Max: 200
37+
Max: 100
3838
Severity: warning
3939

4040
Metrics/PerceivedComplexity:

script/cibuild

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,30 @@ if [ "$RSPEC_TEST" = "true" ]; then
106106
cat "$OUTPUT_FILE"
107107
echo ""
108108

109+
# To avoid travis getting hung if it gets confused, we'll run each of these
110+
# scripts individually with a timeout. This will hopefully address the problem
111+
# of hung builds.
109112
echo "Running rspec integration tests"
110-
time bundle exec rake spec:integration
111-
exitcode=$?
112-
if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi
113-
cat "$OUTPUT_FILE"
114-
echo ""
113+
for file in "${DIR}"/spec/octocatalog-diff/integration/*_spec.rb; do
114+
retry=1
115+
exitcode=255
116+
for try in 1 2 3 ; do
117+
if [ $retry -eq 1 ]; then
118+
retry=0
119+
echo "$(basename "$file") try ${try}"
120+
"$DIR/script/timeout" 120 bundle exec rspec "$file"
121+
exitcode=$?
122+
if [ $exitcode -eq 124 ] && [ $try -eq 3 ]; then
123+
RSPEC_EXITCODE="255"
124+
elif [ $exitcode -eq 124 ] && [ $try -lt 3 ]; then
125+
retry=1
126+
fi
127+
fi
128+
done
129+
130+
if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi
131+
cat "$OUTPUT_FILE"
132+
done
115133
done
116134
export PATH="$SAVED_PATH"
117135
unset PUPPET_VERSION

script/timeout

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'shellwords'
4+
require 'timeout'
5+
6+
seconds = ARGV.shift
7+
raise "Usage: #{__FILE__} <seconds> <command>" unless seconds
8+
begin
9+
Timeout::timeout(seconds.to_i) do
10+
system ARGV.map { |i| Shellwords.escape(i) }.join(" ")
11+
exit $?.exitstatus
12+
end
13+
rescue Timeout::Error
14+
STDERR.puts "Timed out after #{seconds} seconds"
15+
exit 255
16+
end

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require 'shellwords'
99
require 'stringio'
1010
require 'tempfile'
11-
require 'timeout'
1211

1312
module OctocatalogDiff
1413
class Integration
@@ -125,16 +124,7 @@ def self.integration(options = {})
125124
$stdout = stdout_strio
126125

127126
# Run the OctocatalogDiff::Cli.cli and validate output format.
128-
result = nil
129-
3.times do
130-
begin
131-
result = timeout(120, Timeout::Error) { OctocatalogDiff::Cli.cli(argv, logger, options) }
132-
rescue Timeout::Error => e
133-
warn "Warning: #{e.class} #{e.message}"
134-
end
135-
break if result
136-
end
137-
127+
result = OctocatalogDiff::Cli.cli(argv, logger, options)
138128
if result.is_a?(Integer)
139129
result = OpenStruct.new(exitcode: result, exception: nil, diffs: [], to: nil, from: nil)
140130
elsif result.is_a?(Hash)

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'rspec'
44
require 'rspec/retry'
55
require 'tempfile'
6-
require 'timeout'
76

87
# Enable SimpleCov coverage testing?
98
if ENV['COVERAGE']

0 commit comments

Comments
 (0)