Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit f124150

Browse files
committed
Make BackgroundJobEnvironment specs work on linux
Also improve the test for the case without a readiness port. The previous test only tested that a single specific port was not opened, when any port may have been opened. The new test ensures that the same number of ports are open before and after running the method. This may cause problems when running tests in parallel, but we can address that problem when/if it occurs Authored-by: Matt Royal <mroyal@pivotal.io>
1 parent b912e5b commit f124150

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

spec/unit/lib/background_job_environment_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,23 @@
3939
background_job_environment.setup_environment
4040
end
4141

42+
def open_port_count
43+
`lsof -i -P -n | grep LISTEN | wc -l`.to_i
44+
end
45+
4246
it 'doesnt attempt to open a readiness port' do
43-
expect { TCPSocket.new('localhost', 9999).close }.to raise_error(Errno::ECONNREFUSED)
44-
background_job_environment.setup_environment
45-
expect { TCPSocket.new('localhost', 9999).close }.to raise_error(Errno::ECONNREFUSED)
47+
expect {
48+
background_job_environment.setup_environment
49+
}.not_to change { open_port_count }
4650
end
4751

4852
context 'readiness_port provided' do
4953
it 'opens the readiness port' do
50-
expect { TCPSocket.new('localhost', 9999).close }.to raise_error(Errno::ECONNREFUSED)
51-
background_job_environment.setup_environment(9999)
52-
expect { TCPSocket.new('localhost', 9999).close }.not_to raise_error
54+
expect { TCPSocket.new('127.0.0.1', 9999).close }.to raise_error(Errno::ECONNREFUSED)
55+
expect {
56+
background_job_environment.setup_environment(9999)
57+
}.to change { open_port_count }.by(1)
58+
expect { TCPSocket.new('127.0.0.1', 9999).close }.not_to raise_error
5359
end
5460
end
5561
end

0 commit comments

Comments
 (0)