Skip to content

Commit 1183873

Browse files
author
Kevin Paulisse
committed
Add retries for starting SSL server
1 parent 60e51a6 commit 1183873

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ class Integration
1212
def self.integration_with_puppetdb(server_opts, opts)
1313
server_opts[:rsa_key] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.key'))
1414
server_opts[:cert] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.crt'))
15-
test_server = SSLTestServer.new(server_opts)
16-
test_server.start
17-
raise 'Unable to instantiate SSLTestServer' unless test_server.port > 0
15+
test_server = nil
16+
3.times do
17+
test_server = SSLTestServer.new(server_opts)
18+
test_server.start
19+
break if test_server.port > 0
20+
end
21+
raise OctocatalogDiff::Spec::FixtureError, 'Unable to instantiate SSLTestServer' unless test_server.port > 0
1822
puppetdb_url_save = ENV['PUPPETDB_URL']
1923
ENV['PUPPETDB_URL'] = "https://localhost:#{test_server.port}"
2024
integration(opts)

spec/octocatalog-diff/integration/pe_enc_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ def initialize(options = {})
1111
server_opts = options.dup
1212
server_opts[:rsa_key] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.key'))
1313
server_opts[:cert] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.crt'))
14-
@test_server = SSLTestServer.new(server_opts)
15-
@test_server.start
16-
raise 'Unable to instantiate SSLTestServer' unless @test_server.port > 0
14+
@test_server = nil
15+
3.times do
16+
@test_server = SSLTestServer.new(server_opts)
17+
@test_server.start
18+
break if @test_server.port > 0
19+
end
20+
raise OctocatalogDiff::Spec::FixtureError, 'Unable to instantiate SSLTestServer' unless @test_server.port > 0
1721
end
1822

1923
def stop

spec/octocatalog-diff/integration/puppetmaster_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ def initialize(options = {})
99
server_opts = options.dup
1010
server_opts[:rsa_key] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.key'))
1111
server_opts[:cert] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.crt'))
12-
@test_server = SSLTestServer.new(server_opts)
13-
@test_server.start
14-
raise 'Unable to instantiate SSLTestServer' unless @test_server.port > 0
12+
@test_server = nil
13+
3.times do
14+
@test_server = SSLTestServer.new(server_opts)
15+
@test_server.start
16+
break if @test_server.port > 0
17+
end
18+
raise OctocatalogDiff::Spec::FixtureError, 'Unable to instantiate SSLTestServer' unless @test_server.port > 0
1519
end
1620

1721
def stop

spec/octocatalog-diff/tests/puppetdb_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
def ssl_test(server_opts, opts = {})
1010
server_opts[:rsa_key] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.key'))
1111
server_opts[:cert] ||= File.read(OctocatalogDiff::Spec.fixture_path('ssl/generated/server.crt'))
12-
test_server = SSLTestServer.new(server_opts)
13-
test_server.start
14-
raise 'Unable to instantiate SSLTestServer' unless test_server.port > 0
12+
test_server = nil
13+
3.times do
14+
test_server = SSLTestServer.new(server_opts)
15+
test_server.start
16+
break if test_server.port > 0
17+
end
18+
raise OctocatalogDiff::Spec::FixtureError, 'Unable to instantiate SSLTestServer' unless test_server.port > 0
1519
testobj = OctocatalogDiff::PuppetDB.new(opts.merge(puppetdb_url: "https://localhost:#{test_server.port}"))
1620
return testobj.get('/foo')
1721
ensure

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class Spec
3737
PUPPET_BINARY = File.expand_path('../../../script/puppet', File.dirname(__FILE__)).freeze
3838
raise "Puppet binary (#{PUPPET_BINARY}) is missing" unless File.file?(PUPPET_BINARY)
3939

40+
# An error to raise if a fixture fails but code doesn't
41+
class FixtureError; end
42+
4043
# One 'require' to rule them all. Find the code relative to the directory
4144
# of this spec file, so we can easily update this to reflect packaging changes.
4245
def self.require_path(path)

0 commit comments

Comments
 (0)