|
1 | 1 | # Functional test suite for abaco. |
2 | 2 | # This test suite now runs in its own docker container. To build the image, run |
3 | | -# docker build -f Dockerfile-test -t jstubbs/abaco_testsuite . |
| 3 | +# docker build -f Dockerfile-test -t abaco/testsuite . |
4 | 4 | # from within the tests directory. |
5 | 5 | # |
6 | 6 | # To run the tests execute, first start the development stack using: |
@@ -1718,6 +1718,72 @@ def test_create_actor_with_link(headers): |
1718 | 1718 | rsp = requests.post(url, data=data, headers=headers) |
1719 | 1719 | result = basic_response_checks(rsp) |
1720 | 1720 |
|
| 1721 | +def test_create_actor_with_webhook(headers): |
| 1722 | + # register an actor to serve as the webhook target |
| 1723 | + url = '{}/{}'.format(base_url, '/actors') |
| 1724 | + data = {'image': 'jstubbs/abaco_test', 'name': 'abaco_test_suite_event-webhook', 'stateless': False} |
| 1725 | + rsp = requests.post(url, data=data, headers=headers) |
| 1726 | + result = basic_response_checks(rsp) |
| 1727 | + aid = get_actor_id(headers, name='abaco_test_suite_event-webhook') |
| 1728 | + # create a nonce for this actor |
| 1729 | + url = '{}/actors/{}/nonces'.format(base_url, aid) |
| 1730 | + rsp = requests.post(url, headers=headers) |
| 1731 | + result = basic_response_checks(rsp) |
| 1732 | + nonce = result['id'] |
| 1733 | + # in practice, no one should ever do this - the built in link property should be used instead; |
| 1734 | + # but this illustrates the use of the webhook feature without relying on external APIs. |
| 1735 | + webhook = '{}/actors/{}/messages?x-nonce={}'.format(base_url, aid, nonce) |
| 1736 | + # make a new actor with a webhook property that points to the above messages endpoint - |
| 1737 | + url = '{}/actors'.format(base_url) |
| 1738 | + data = {'image': 'jstubbs/abaco_test', |
| 1739 | + 'name': 'abaco_test_suite_event-2', |
| 1740 | + 'webhook': webhook} |
| 1741 | + rsp = requests.post(url, data=data, headers=headers) |
| 1742 | + result = basic_response_checks(rsp) |
| 1743 | + event_aid = result['id'] |
| 1744 | + # once the new actor is READY, the webhook actor should have gotten a message to |
| 1745 | + url = '{}/actors/{}/executions'.format(base_url, aid) |
| 1746 | + webhook_ready_ex_id = None |
| 1747 | + idx = 0 |
| 1748 | + while not webhook_ready_ex_id and idx < 25: |
| 1749 | + rsp = requests.get(url, headers=headers) |
| 1750 | + ex_data = rsp.json().get('result').get('executions') |
| 1751 | + if ex_data and len(ex_data) > 0: |
| 1752 | + webhook_ready_ex_id = ex_data[0]['id'] |
| 1753 | + break |
| 1754 | + else: |
| 1755 | + idx = idx + 1 |
| 1756 | + time.sleep(1) |
| 1757 | + if not webhook_ready_ex_id: |
| 1758 | + print("webhook actor never executed. actor_id: {}; webhook_actor_id: {}".format(event_aid, aid)) |
| 1759 | + assert False |
| 1760 | + # wait for linked execution to complete and get logs |
| 1761 | + idx = 0 |
| 1762 | + done = False |
| 1763 | + while not done and idx < 20: |
| 1764 | + # get executions for linked actor and check status of each |
| 1765 | + rsp = requests.get(url, headers=headers) |
| 1766 | + ex_data = rsp.json().get('result').get('executions') |
| 1767 | + if ex_data[0].get('status') == 'COMPLETE': |
| 1768 | + done = True |
| 1769 | + break |
| 1770 | + else: |
| 1771 | + time.sleep(1) |
| 1772 | + idx = idx + 1 |
| 1773 | + if not done: |
| 1774 | + print("webhook actor executions never completed. actor: {}; " |
| 1775 | + "actor: {}; Final execution data: {}".format(event_aid, aid, ex_data)) |
| 1776 | + assert False |
| 1777 | + # now check the logs from the two executions -- |
| 1778 | + # first one should be the actor READY message: |
| 1779 | + url = '{}/actors/{}/executions/{}/logs'.format(base_url, aid, webhook_ready_ex_id) |
| 1780 | + rsp = requests.get(url, headers=headers) |
| 1781 | + result = basic_response_checks(rsp) |
| 1782 | + logs = result.get('logs') |
| 1783 | + assert "'event_type': 'ACTOR_READY'" in logs |
| 1784 | + check_event_logs(logs) |
| 1785 | + |
| 1786 | + |
1721 | 1787 | def test_execute_event_actor(headers): |
1722 | 1788 | actor_id = get_actor_id(headers, name='abaco_test_suite_event') |
1723 | 1789 | data = {'message': 'testing events execution'} |
|
0 commit comments