Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
wait for callback server to start up in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-burnett committed Jun 11, 2014
1 parent 5485cb6 commit 629859a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion tests/api/v1/generator/base_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ptero_petri.implementation.petri.webhooks import _retry as retry
import abc
import collections
import errno
Expand Down Expand Up @@ -157,7 +158,7 @@ def _assemble_callback_url(self, callback_name, request_data):
return urlparse.urlunparse((
'http',
'localhost:%d' % self.callback_port,
'/' + callback_name,
'/callbacks/' + callback_name,
'',
urllib.urlencode(request_data),
'',
Expand Down Expand Up @@ -197,6 +198,16 @@ def _start_callback_receipt_webserver(self):
'--port', str(self.callback_port),
],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self._wait_for_callback_webserver()

def _wait_for_callback_webserver(self):
response = retry(requests.get, self._callback_ping_url())
if response.status_code != 200:
raise RuntimeError('Failed to spin up callback webserver: %s'
% response.text)

def _callback_ping_url(self):
return 'http://localhost:%d/ping' % self.callback_port

def _stop_callback_receipt_webserver(self):
_stop_subprocess(self._callback_webserver)
Expand Down
7 changes: 6 additions & 1 deletion tests/api/v1/generator/callback_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def parse_arguments():
app = Flask(__name__)


@app.route('/<path:callback_name>', methods=['PUT'])
@app.route('/ping', methods=['GET'])
def ping():
return 'PONG'


@app.route('/callbacks/<path:callback_name>', methods=['PUT'])
def log_request(callback_name):
try:
print callback_name
Expand Down

0 comments on commit 629859a

Please sign in to comment.