2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 05:11:27 -04:00
|
|
|
require 'fast_spec_helper'
|
2017-12-06 04:39:25 -05:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::TcpChecker, :permit_dns do
|
2017-12-06 04:39:25 -05:00
|
|
|
before do
|
|
|
|
@server = TCPServer.new('localhost', 0)
|
|
|
|
_, @port, _, @ip = @server.addr
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@server.close
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:checker) { described_class.new(@ip, @port) }
|
|
|
|
|
|
|
|
describe '#check' do
|
|
|
|
subject { checker.check }
|
|
|
|
|
|
|
|
it 'can connect to an open port' do
|
|
|
|
is_expected.to be_truthy
|
|
|
|
|
|
|
|
expect(checker.error).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails to connect to a closed port' do
|
|
|
|
@server.close
|
|
|
|
|
|
|
|
is_expected.to be_falsy
|
|
|
|
|
|
|
|
expect(checker.error).to be_a(Errno::ECONNREFUSED)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|