Skip to content

Commit

Permalink
(PCP-294) Acceptance - on pcp-broker start-up, wait for 'running' state
Browse files Browse the repository at this point in the history
Due to PCP-294, the acceptance tests might message pcp-broker before it has fully started.
This commit changes the pre-suite to use the master ref for pcp-broker (PCP-250 being fixed allows this);
and changes the helper methods so pcp-broker is queried for its running state.
[skip ci]
  • Loading branch information
james-stocks committed Feb 11, 2016
1 parent f0b6ebe commit e0604d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions acceptance/lib/pxp-agent/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'pxp-agent/config_helper.rb'
require 'pcp/client'
require 'net/http'
require 'openssl'
require 'json'

# This file contains general test helper methods for pxp-agent acceptance tests

Expand Down Expand Up @@ -40,6 +43,16 @@ def run_pcp_broker(host)
on(host, 'cd /opt/puppet-git-repos/pcp-broker; export LEIN_ROOT=ok; lein tk </dev/null >/var/log/pcp-broker.log 2>&1 &')
assert(port_open_within?(host, PCP_BROKER_PORT, 60),
"pcp-broker port #{PCP_BROKER_PORT.to_s} not open within 1 minutes of starting the broker")
broker_state = nil
attempts = 0
until broker_state == "running" or attempts == 100 do
broker_state = get_pcp_broker_status(host)
if broker_state != "running"
attempts += 1
sleep 0.5
end
end
assert_equal("running", broker_state, "Shortly after startup, pcp-broker should report its state as being 'running'")
end

def kill_pcp_broker(host)
Expand All @@ -49,6 +62,21 @@ def kill_pcp_broker(host)
end
end

def get_pcp_broker_status(host)
uri = URI.parse("https://#{host}:#{PCP_BROKER_PORT}/status/v1/services/broker-service")
begin
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
res = http.get(uri.request_uri)
document = JSON.load(res.body)
return document["state"]
rescue => e
puts e.inspect
return nil
end
end

# Query pcp-broker's inventory of associated clients
# Reference: https://github.com/puppetlabs/pcp-specifications/blob/master/pcp/inventory.md
# @param broker hostname or beaker host object of the pcp-broker host
Expand Down
2 changes: 1 addition & 1 deletion acceptance/setup/common/010_Setup_Broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

step 'Clone pcp-broker to master' do
clone_git_repo_on(master, GIT_CLONE_FOLDER,
extract_repo_info_from(build_git_url('pcp-broker', nil, nil, 'https')).merge(:rev => '602c003'))
extract_repo_info_from(build_git_url('pcp-broker', nil, nil, 'https')))
end

step 'Download lein bootstrap' do
Expand Down

0 comments on commit e0604d0

Please sign in to comment.