Skip to content

Commit 314210f

Browse files
binarycodeioquatix
authored andcommitted
use Async::RSpec::Reactor to detect socket leaks
1 parent 091ee4a commit 314210f

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

spec/async/http/faraday/adapter_spec.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
require 'async'
2626

2727
RSpec.describe Async::HTTP::Faraday::Adapter do
28+
include_context Async::RSpec::Reactor
29+
2830
let(:endpoint) {
2931
Async::HTTP::Endpoint.parse('http://127.0.0.1:9294')
3032
}
@@ -86,25 +88,4 @@ def get_response(url, path)
8688
expect(response.body).to be_nil
8789
end
8890
end
89-
90-
if RbConfig::CONFIG['host_os'] =~ /linux/
91-
it 'does not leak sockets' do
92-
def get_socket_count
93-
`ls -l /proc/#{$$}/fd | grep socket | wc -l`.to_i
94-
end
95-
96-
REQUEST_COUNT = 3
97-
98-
run_server(Protocol::HTTP::Response[204]) do
99-
# warm up
100-
get_response(endpoint.url, '/index')
101-
102-
sockets_before = get_socket_count
103-
REQUEST_COUNT.times { get_response(endpoint.url, '/index') }
104-
sockets_after = get_socket_count
105-
106-
expect(sockets_after).to eq sockets_before
107-
end
108-
end
109-
end
11091
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
require 'async/rspec'
23
require 'covered/rspec'
34

45
RSpec.configure do |config|

0 commit comments

Comments
 (0)