Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1eb525b

Browse files
Avoid race condition during RSpec tests... Python takes a tick before grabbing port 8080 on Travis CI ;-)
Change-Id: I70c081476fdbc401f6709b05cdf87647b79f6cf2
1 parent d905da4 commit 1eb525b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

‎Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source "https://rubygems.org"
22

33
group :test do
44
gem 'rake'
5+
gem 'rspec-wait'
56
gem 'git'
67
gem 'docker-api'
78
gem 'serverspec', '~> 2.24' # Docker 1.8 support

‎spec/localhost/python_simplehttpserver_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def image
7979
end
8080

8181
describe port(8080) do
82-
it { should be_listening }
82+
# Avoid race condition when python is running but hasn't grabbed the port yet...
83+
it "grabs port 8080" do
84+
wait_for { port(8080) }.to be_listening
85+
end
86+
it { is_expected.to be_listening }
8387
end
8488

8589
context "when serving a test file" do
@@ -107,6 +111,14 @@ def image
107111
it { should be_file }
108112
end
109113

114+
describe port(8080) do
115+
# Avoid race condition when python is running but hasn't grabbed the port yet...
116+
it "grabs port 8080" do
117+
wait_for { port(8080) }.to be_listening
118+
end
119+
it { is_expected.to be_listening }
120+
end
121+
110122
describe command('wget -O - http://localhost:8080/helloworld.txt') do
111123
its(:stdout) { should match /^hello simple world$/ }
112124
its(:stderr) { is_expected.not_to match /can't connect/ }

‎spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'serverspec'
22
require 'docker'
3+
require 'rspec/wait'
34

45
set :backend, :docker
56

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /