From 71f2d1b0b7db6bb35dd6bd9220795aed3174d90b Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 27 Dec 2013 16:47:57 -0800 Subject: added more network tests and pgrep test helper --- bin/run_tests | 19 ++++++++++++++++++- tests/white-box/couchdb.rb | 9 +++++---- tests/white-box/network.rb | 20 ++++++++++++++++++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/bin/run_tests b/bin/run_tests index 86a72f26..f4778988 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -107,7 +107,7 @@ class LeapTest < MiniTest::Unit::TestCase options ||= {} get(url, params) do |body, response, error| if body - yield body + yield body if block_given? elsif response fail ["Expected a 200 status code from #{url}, but got #{response.code} instead.", options[:error_msg]].compact.join("\n") else @@ -231,6 +231,22 @@ class LeapTest < MiniTest::Unit::TestCase return latest end + # + # works like pgrep command line + # return an array of hashes like so [{:pid => "1234", :process => "ls"}] + # + def pgrep(match) + output = `pgrep --full --list-name '#{match}'` + output.each_line.map{|line| + pid = line.split(' ')[0] + process = line.gsub(/(#{pid} |\n)/, '') + if process =~ /pgrep --full --list-name/ + nil + else + {:pid => pid, :process => process} + end + }.compact + end end # @@ -310,6 +326,7 @@ class LeapRunner < MiniTest::Unit # def report_line(prefix, klass, meth, e=nil, message=nil) if message + message = message.sub(/http:\/\/([a-z_]+):([a-zA-Z0-9_]+)@/, "http://\\1:password@") indent = "\n " msg_txt = indent + message.split("\n").join(indent) end diff --git a/tests/white-box/couchdb.rb b/tests/white-box/couchdb.rb index 3abddefc..c83e5714 100644 --- a/tests/white-box/couchdb.rb +++ b/tests/white-box/couchdb.rb @@ -3,6 +3,7 @@ raise SkipTest unless $node["services"].include?("couchdb") require 'json' class TestCouchdb < LeapTest + depends_on "TestNetwork" def setup end @@ -10,7 +11,7 @@ class TestCouchdb < LeapTest # # check to make sure we can get welcome response from local couchdb # - def test_01_is_running + def test_01_couch_is_running assert_get(couchdb_url) do |body| assert_match /"couchdb":"Welcome"/, body, "Could not get welcome message from #{couchdb_url}. Probably couchdb is not running." end @@ -39,7 +40,7 @@ class TestCouchdb < LeapTest # # this seems backward to me, so it might be the other way around. # - def test_03_replica_membership + def test_03_replica_membership_is_kosher url = couchdb_url("/_membership") assert_get(url) do |body| response = JSON.parse(body) @@ -64,12 +65,12 @@ class TestCouchdb < LeapTest response = JSON.parse(body) assert_equal 6, response['total_rows'] actual_users = response['rows'].map{|row| row['id'].sub(/^org.couchdb.user:/, '') } - assert_equal acl_users, actual_users + assert_equal acl_users.sort, actual_users.sort end pass end - def test_05_databases_exist + def test_05_required_databases_exist dbs_that_should_exist = ["customers","identities","keycache","sessions","shared","tickets","tokens","users"] dbs_that_should_exist.each do |db_name| assert_get(couchdb_url("/"+db_name)) do |body| diff --git a/tests/white-box/network.rb b/tests/white-box/network.rb index 02eb80ca..53df80dc 100644 --- a/tests/white-box/network.rb +++ b/tests/white-box/network.rb @@ -7,6 +7,11 @@ class TestNetwork < LeapTest def setup end + def test_01_can_connect_to_internet + assert_get('http://www.google.com/images/srpr/logo11w.png') + pass + end + # # example properties: # @@ -20,15 +25,24 @@ class TestNetwork < LeapTest # accept: 15984 # connect: "127.0.0.1:5984" # - def test_01_stunnel_is_running + def test_02_stunnel_is_running if $node['stunnel'] + good_stunnel_pids = [] $node['stunnel'].each do |stunnel_type, stunnel_configs| if stunnel_type =~ /_clients?$/ - stunnel_configs.values.each do |stunnel_conf| + stunnel_configs.each do |stunnel_name, stunnel_conf| + config_file_name = "/etc/stunnel/#{stunnel_name}.conf" + processes = pgrep(config_file_name) + assert_equal 6, processes.length, "There should be six stunnel processes running for `#{config_file_name}`" + good_stunnel_pids += processes.map{|ps| ps[:pid]} assert port = stunnel_conf['accept_port'], 'Field `accept_port` must be present in `stunnel` property.' assert_tcp_socket('localhost', port) end elsif stunnel_type =~ /_server$/ + config_file_name = "/etc/stunnel/#{stunnel_type}.conf" + processes = pgrep(config_file_name) + assert_equal 6, processes.length, "There should be six stunnel processes running for `#{config_file_name}`" + good_stunnel_pids += processes.map{|ps| ps[:pid]} assert accept = stunnel_configs['accept'], "Field `accept` must be present in property `stunnel.#{stunnel_type}`" assert_tcp_socket('localhost', accept) assert connect = stunnel_configs['connect'], "Field `connect` must be present in property `stunnel.#{stunnel_type}`" @@ -37,6 +51,8 @@ class TestNetwork < LeapTest skip "Unknown stunnel type `#{stunnel_type}`" end end + all_stunnel_pids = pgrep('/usr/bin/stunnel').collect{|process| process[:pid]}.uniq + assert_equal good_stunnel_pids.sort, all_stunnel_pids.sort, "There should not be any extra stunnel processes that are not configured in /etc/stunnel" end pass end -- cgit v1.2.3