From 8bf8da2126aa246d09c72bf6eaf2a455c2ebb406 Mon Sep 17 00:00:00 2001 From: jamshale Date: Wed, 6 Mar 2024 18:30:32 +0000 Subject: [PATCH] Integration tests - Add retry to did registration Signed-off-by: jamshale --- demo/bdd_support/agent_backchannel_client.py | 3 ++- demo/features/steps/0586-sign-transaction.py | 18 ++++++++----- demo/runners/agent_container.py | 28 +++++++++++--------- demo/runners/support/agent.py | 23 ++++++++-------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/demo/bdd_support/agent_backchannel_client.py b/demo/bdd_support/agent_backchannel_client.py index 7dd2c24828..5d116e2fea 100644 --- a/demo/bdd_support/agent_backchannel_client.py +++ b/demo/bdd_support/agent_backchannel_client.py @@ -4,7 +4,6 @@ from runners.agent_container import AgentContainer, create_agent_with_args_list - ###################################################################### # coroutine utilities ###################################################################### @@ -246,6 +245,7 @@ def agent_container_POST( data: dict = None, text: bool = False, params: dict = None, + raise_error: bool = True, ) -> dict: return run_coroutine( the_container.admin_POST, @@ -253,6 +253,7 @@ def agent_container_POST( data=data, text=text, params=params, + raise_error=raise_error, ) diff --git a/demo/features/steps/0586-sign-transaction.py b/demo/features/steps/0586-sign-transaction.py index e0786afc38..25a63e46c9 100644 --- a/demo/features/steps/0586-sign-transaction.py +++ b/demo/features/steps/0586-sign-transaction.py @@ -32,7 +32,7 @@ def step_impl(context, agent_name, did_role): created_did = agent_container_POST(agent["agent"], "/wallet/did/create") # publish to the ledger with did_role - registered_did = agent_container_register_did( + agent_container_register_did( agent["agent"], created_did["result"]["did"], created_did["result"]["verkey"], @@ -40,11 +40,17 @@ def step_impl(context, agent_name, did_role): ) # make the new did the wallet's public did - published_did = agent_container_POST( - agent["agent"], - "/wallet/did/public", - params={"did": created_did["result"]["did"]}, - ) + retries = 3 + for retry in range(retries): + published_did = agent_container_POST( + agent["agent"], + "/wallet/did/public", + params={"did": created_did["result"]["did"]}, + raise_error=retries - 1 == retry, + ) + if "result" in published_did or "txn" in published_did: + break + if "result" in published_did: # published right away! pass diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index b2db5ed138..23afb3f49a 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -7,26 +7,25 @@ import sys import time from typing import List -import yaml - -from qrcode import QRCode +import yaml from aiohttp import ClientError +from qrcode import QRCode sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from runners.support.agent import ( # noqa:E402 - DemoAgent, - default_genesis_txns, - start_mediator_agent, - connect_wallet_to_mediator, - start_endorser_agent, - connect_wallet_to_endorser, - WALLET_TYPE_INDY, CRED_FORMAT_INDY, CRED_FORMAT_JSON_LD, DID_METHOD_KEY, KEY_TYPE_BLS, + WALLET_TYPE_INDY, + DemoAgent, + connect_wallet_to_endorser, + connect_wallet_to_mediator, + default_genesis_txns, + start_endorser_agent, + start_mediator_agent, ) from runners.support.utils import ( # noqa:E402 check_requires, @@ -36,7 +35,6 @@ log_timer, ) - CRED_PREVIEW_TYPE = "https://didcomm.org/issue-credential/2.0/credential-preview" SELF_ATTESTED = os.getenv("SELF_ATTESTED") TAILS_FILE_COUNT = int(os.getenv("TAILS_FILE_COUNT", 100)) @@ -1174,7 +1172,9 @@ async def admin_GET(self, path, text=False, params=None) -> dict: """ return await self.agent.admin_GET(path, text=text, params=params) - async def admin_POST(self, path, data=None, text=False, params=None) -> dict: + async def admin_POST( + self, path, data=None, text=False, params=None, raise_error=True + ) -> dict: """Execute an admin POST request in the context of the current wallet. path = /path/of/request @@ -1182,7 +1182,9 @@ async def admin_POST(self, path, data=None, text=False, params=None) -> dict: text = True if the expected response is text, False if json data params = any additional parameters to pass with the request """ - return await self.agent.admin_POST(path, data=data, text=text, params=params) + return await self.agent.admin_POST( + path, data=data, text=text, params=params, raise_error=raise_error + ) async def admin_PATCH(self, path, data=None, text=False, params=None) -> dict: """Execute an admin PATCH request in the context of the current wallet. diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index a114ef00a3..5e2e34be86 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -1,6 +1,4 @@ import asyncio -from concurrent.futures import ThreadPoolExecutor -import asyncpg import base64 import functools import json @@ -9,17 +7,18 @@ import random import subprocess import sys -import yaml - +from concurrent.futures import ThreadPoolExecutor from timeit import default_timer +import asyncpg +import yaml from aiohttp import ( - web, - ClientSession, + ClientError, ClientRequest, ClientResponse, - ClientError, + ClientSession, ClientTimeout, + web, ) from .utils import flatten, log_json, log_msg, log_timer, output_reader @@ -1045,17 +1044,17 @@ async def handle_problem_report(self, message): ) async def handle_endorse_transaction(self, message): - self.log(f"Received endorse transaction ...\n", source="stderr") + self.log("Received endorse transaction ...\n", source="stderr") async def handle_revocation_registry(self, message): reg_id = message.get("revoc_reg_id", "(undetermined)") self.log(f"Revocation registry: {reg_id} state: {message['state']}") async def handle_mediation(self, message): - self.log(f"Received mediation message ...\n") + self.log("Received mediation message ...\n") async def handle_keylist(self, message): - self.log(f"Received handle_keylist message ...\n") + self.log("Received handle_keylist message ...\n") self.log(json.dumps(message)) async def taa_accept(self): @@ -1167,7 +1166,7 @@ async def agency_admin_POST( raise async def admin_POST( - self, path, data=None, text=False, params=None, headers=None + self, path, data=None, text=False, params=None, headers=None, raise_error=True ) -> ClientResponse: try: EVENT_LOGGER.debug( @@ -1192,6 +1191,8 @@ async def admin_POST( return response except ClientError as e: self.log(f"Error during POST {path}: {str(e)}") + if not raise_error: + return None raise async def admin_PATCH(