From 406234367544a4207141230683dddaccd98fb21a Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 21 Jul 2017 08:19:20 +0200 Subject: fix: filedescriptor leak from http_adapters Now we reuse a single adapter for all requests triggered by an incoming request. Then we .terminate the adapter. Includes a regression test. --- test/functional/sample_test.rb | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/functional/sample_test.rb (limited to 'test/functional/sample_test.rb') diff --git a/test/functional/sample_test.rb b/test/functional/sample_test.rb new file mode 100644 index 0000000..5886349 --- /dev/null +++ b/test/functional/sample_test.rb @@ -0,0 +1,58 @@ +require 'support/functional_test' + +class SampleTest < FunctionalTest + # don't parallize me... Hard to get that right with nickserver start & stop + + def run(*args) + nickserver :start + super + ensure + nickserver :stop + end + + def test_running + assert_running + end + + # def test_invalid + # assert_lookup_status 400, 'invalid' + # end + + def test_nicknym + assert_lookup_status 200, 'test@mail.bitmask.net' + end + + # Regression Tests + + def test_no_file_descriptors_leak + lookup 'test@mail.bitmask.net' + before = open_files_count + lookup 'test@mail.bitmask.net' + assert_equal before, open_files_count, 'Filedescriptors leaked' + end + + protected + + def assert_lookup_status(status, address) + assert_equal status, lookup(address).to_i + end + + def lookup(address) + run_command %Q(curl localhost:6425 #{curl_opts} -d "address=#{address}") + end + + def curl_opts + '--silent -w "%{http_code}" -o /dev/null' + end + + def open_files_count + `lsof | grep " #{nickserver_pid} " | wc -l`.to_i + end + + def run_command(command) + `#{command} 2>&1`.tap do |out| + assert ($?.exitstatus == 0), + "failed to run '#{command}':\n #{out}" + end + end +end -- cgit v1.2.3