Skip to content

Commit 9cc2790

Browse files
committed
Add timeouts to the spec tests and integration tests
1 parent 76283cf commit 9cc2790

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
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: 100
22+
Max: 200
2323
Severity: warning
2424

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

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

4040
Metrics/PerceivedComplexity:

spec/octocatalog-diff/integration/integration_helper.rb

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

1213
module OctocatalogDiff
1314
class Integration
@@ -124,7 +125,12 @@ def self.integration(options = {})
124125
$stdout = stdout_strio
125126

126127
# Run the OctocatalogDiff::Cli.cli and validate output format.
127-
result = OctocatalogDiff::Cli.cli(argv, logger, options)
128+
result = begin
129+
timeout(30, Timeout::Error) { OctocatalogDiff::Cli.cli(argv, logger, options) }
130+
rescue Timeout::Error => e
131+
OpenStruct.new(exitcode: 255, exception: e, diffs: [], to: nil, from: nil)
132+
end
133+
128134
if result.is_a?(Integer)
129135
result = OpenStruct.new(exitcode: result, exception: nil, diffs: [], to: nil, from: nil)
130136
elsif result.is_a?(Hash)

spec/octocatalog-diff/tests/spec_helper.rb

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

78
# Enable SimpleCov coverage testing?
89
if ENV['COVERAGE']
@@ -31,6 +32,23 @@
3132
config.display_try_failure_messages = true
3233
end
3334

35+
# We should not have any individual tests that take more than 10 seconds, so
36+
# set the timeout here to reap any that get stuck. Hopefully this will prevent
37+
# jobs from intermittently timing out on travis CI.
38+
# Inspired by https://github.com/basho/innertube/blob/master/spec/support/timeout.rb
39+
RSpec.configure do |config|
40+
config.around(:each) do |example|
41+
time = example.metadata[:timeout] || 10
42+
begin
43+
timeout(time, Timeout::Error) do
44+
example.run
45+
end
46+
rescue Timeout::Error => e
47+
example.send :set_exception, e
48+
end
49+
end
50+
end
51+
3452
module OctocatalogDiff
3553
class Spec
3654
# Set up a logger that is usable across parent and child forks.

0 commit comments

Comments
 (0)