Skip to content

Commit 2e94eda

Browse files
authored
Merge pull request #178 from github/kpaulisse-split-tests
Split the puppet versions in hopes the tests don't timeout
2 parents a4f7b42 + 30fc3c7 commit 2e94eda

File tree

5 files changed

+118
-12
lines changed

5 files changed

+118
-12
lines changed

.travis.yml

+14-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ script: "script/cibuild"
77
matrix:
88
include:
99
# Build with latest ruby
10-
- rvm: 2.4
11-
env: RUBOCOP_TEST="true" RSPEC_TEST="true"
10+
- rvm: 2.5
11+
env: RUBOCOP_TEST="true" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
12+
- rvm: 2.5
13+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.8"
14+
- rvm: 2.5
15+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"
1216
# Build with older ruby versions
17+
- rvm: 2.4
18+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
1319
- rvm: 2.3.2
14-
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
20+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.8"
1521
- rvm: 2.2.3
16-
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
22+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"
1723
- rvm: 2.1
18-
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
24+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
25+
- rvm: 2.0
26+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
1927
- rvm: 2.0
20-
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
28+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"

lib/octocatalog-diff/util/util.rb

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def self.object_is_any_of?(object, classes)
2727
def self.safe_dup(object)
2828
object.dup
2929
rescue TypeError
30+
# :nocov:
3031
object
32+
# :nocov:
3133
end
3234

3335
# Utility Method!

script/cibuild

+35-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
# with one or more Puppet versions, with PUPPET_VERSIONS set to a space-separated list
77
# of versions to test.
88

9-
[ -z "$PUPPET_VERSIONS" ] && export PUPPET_VERSIONS='3.8.7 4.10.8 5.0.0'
9+
if [ -z "$PUPPET_VERSIONS" ]; then
10+
echo "Required PUPPET_VERSIONS!"
11+
exit 255
12+
fi
13+
1014
[ -z "$RUBOCOP_TEST" ] && export RUBOCOP_TEST='true'
1115
[ -z "$RSPEC_TEST" ] && export RSPEC_TEST='true'
1216

@@ -19,9 +23,7 @@ env
1923
echo "travis_fold:end:cibuild-environment-dump"
2024

2125
# Create a temporary file to capture output of various steps.
22-
export OUTPUT_FILE="$(mktemp)"
2326
function cleanup() {
24-
rm -rf "$OUTPUT_FILE"
2527
rm -f "${DIR}/.ruby-version"
2628
}
2729
trap cleanup EXIT
@@ -95,12 +97,39 @@ if [ "$RSPEC_TEST" = "true" ]; then
9597
fi
9698

9799
# Run the tests
98-
echo "Running tests"
99-
time bundle exec rake test
100+
echo "Running rspec unit tests"
101+
export COVERAGE=true
102+
time bundle exec rspec "${DIR}/spec/octocatalog-diff/tests"
100103
exitcode=$?
104+
unset COVERAGE
101105
if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi
102-
cat "$OUTPUT_FILE"
106+
107+
# Quick coverage report
108+
"$DIR/script/display-coverage-report" "$DIR/coverage/coverage.json"
103109
echo ""
110+
111+
# To avoid travis getting hung if it gets confused, we'll run each of these
112+
# scripts individually with a timeout. This will hopefully address the problem
113+
# of hung builds.
114+
echo "Running rspec integration tests"
115+
for file in "${DIR}"/spec/octocatalog-diff/integration/*_spec.rb; do
116+
retry=1
117+
for try in 1 2 3 ; do
118+
if [ $retry -eq 1 ]; then
119+
retry=0
120+
echo "$(basename "$file") try ${try}"
121+
"$DIR/script/timeout" 180 bundle exec rspec "$file"
122+
exitcode=$?
123+
if [ $exitcode -eq 124 ] && [ $try -eq 3 ]; then
124+
RSPEC_EXITCODE="255"
125+
elif [ $exitcode -eq 124 ] && [ $try -lt 3 ]; then
126+
retry=1
127+
elif [ $exitcode -ne 0 ]; then
128+
RSPEC_EXITCODE="$exitcode"
129+
fi
130+
fi
131+
done
132+
done
104133
done
105134
export PATH="$SAVED_PATH"
106135
unset PUPPET_VERSION

script/display-coverage-report

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env ruby
2+
3+
# Quick hacky script to parse the coverage JSON report and display it in human-readable terms.
4+
# Usage: display-coverage-report <JSON_FILE>
5+
6+
require 'json'
7+
require 'pathname'
8+
9+
# Arg handling and validation
10+
json_file = ARGV.first
11+
unless json_file
12+
raise "Usage: #{__FILE__} <json_coverage_file>"
13+
end
14+
15+
unless File.file?(json_file)
16+
raise "Error: Provided file #{json_file} does not exist"
17+
end
18+
19+
# Find files with < 100% coverage
20+
result = {}
21+
data = JSON.parse(File.read(json_file))
22+
data['files'].each do |data|
23+
next if data['covered_percent'] == 100
24+
25+
result[data['filename']] = { covered: data['covered_percent'], lines: [] }
26+
data['coverage'].each_with_index do |cov, index|
27+
next if cov.nil?
28+
result[data['filename']][:lines] << (index + 1) if cov == 0
29+
end
30+
end
31+
32+
# Display results
33+
if result.empty?
34+
puts "100% Coverage - You're all set, friend! :sparkles:"
35+
exit 0
36+
end
37+
38+
puts ""
39+
puts "-------------------------------------------------------------"
40+
puts "Test coverage report"
41+
puts "-------------------------------------------------------------"
42+
43+
basedir = Pathname.new(File.expand_path('..', File.dirname(__FILE__)))
44+
result.keys.sort.each do |filename|
45+
data = result[filename]
46+
relative_path = Pathname.new(filename).relative_path_from(basedir).to_s
47+
printf "* %s: %0.02f%% (missed: %s)", relative_path, data[:covered], data[:lines].join(",")
48+
end
49+
50+
puts ""
51+
exit 1

script/timeout

+16
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 124
16+
end

0 commit comments

Comments
 (0)