Skip to content

Commit

Permalink
fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dansan committed Nov 25, 2019
1 parent 80e9a25 commit 025c267
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
45 changes: 23 additions & 22 deletions tests/test_base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,29 @@ async def test_move_multiple_objects(
old_cn_dn, old_cn_obj_url, old_cn_data = new_cn(position=top_cn_dn)
cn_name = old_cn_data["properties"]["name"]
users = dict((num, user_created_via_http(position=old_cn_dn)) for num in range(10))
async with UDM(**udm_kwargs) as udm:
mod_user = udm.get("users/user")
for dn, url, data in users.values():
user_obj = await mod_user.get(dn)
assert user_obj.position == old_cn_dn

mod_cn = udm.get("container/cn")
cn_obj = await mod_cn.get(old_cn_dn)
assert cn_obj.dn == old_cn_dn
assert cn_obj.dn != base_dn

cn_obj.position = base_dn
await cn_obj.save()

assert cn_obj.dn == f"cn={cn_name},{base_dn}"

for dn, url, data in users.values():
query = dn.split(",", 1)[0]
async for obj in mod_user.search(query):
assert old_cn_dn not in obj.dn
assert obj.position == cn_obj.dn
assert obj.dn == f"uid={data['properties']['username']},{cn_obj.dn}"
with patch.object(base_http, "MIN_FOLLOW_REDIRECT_SLEEP_TIME", 2.1):
async with UDM(**udm_kwargs) as udm:
mod_user = udm.get("users/user")
for dn, url, data in users.values():
user_obj = await mod_user.get(dn)
assert user_obj.position == old_cn_dn

mod_cn = udm.get("container/cn")
cn_obj = await mod_cn.get(old_cn_dn)
assert cn_obj.dn == old_cn_dn
assert cn_obj.dn != base_dn

cn_obj.position = base_dn
await cn_obj.save()

assert cn_obj.dn == f"cn={cn_name},{base_dn}"

for dn, url, data in users.values():
query = dn.split(",", 1)[0]
async for obj in mod_user.search(query):
assert old_cn_dn not in obj.dn
assert obj.position == cn_obj.dn
assert obj.dn == f"uid={data['properties']['username']},{cn_obj.dn}"


@pytest.mark.asyncio
Expand Down
9 changes: 6 additions & 3 deletions udm_rest_client/base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"search": "udm_{}_object_search_with_http_info",
"update": "udm_{}_object_update_with_http_info",
}
MIN_FOLLOW_REDIRECT_SLEEP_TIME = 1.0
logger = logging.getLogger(__name__)

ApiModule = TypeVar("ApiModule") # openapi_client_udm.SharesShareApi etc
Expand Down Expand Up @@ -862,7 +863,6 @@ async def _follow_move_redirects(
) -> Dict[str, Any]:
operation_timeout = 300 # TODO: make configurable?
start_time = time.time()
sleep_time = 1.0
while time.time() - start_time < operation_timeout:
resp = await self._udm_module.session.session.get(
move_progress_url,
Expand All @@ -875,12 +875,15 @@ async def _follow_move_redirects(
try:
sleep_time = float(resp.headers["Retry-After"])
except (KeyError, ValueError):
pass
sleep_time = MIN_FOLLOW_REDIRECT_SLEEP_TIME
sleep_time = min(sleep_time, MIN_FOLLOW_REDIRECT_SLEEP_TIME)
if resp.status == 301:
await asyncio.sleep(sleep_time)
# report that we're alive, when moving takes more than 2s
operation_time = time.time() - start_time
if operation_time > 2 and int(operation_time) % 2 == 0:
if (
operation_time > 2 and int(operation_time) % 2 == 0
): # pragma: no cover
logger.debug(
"Waiting on move operation since %.2f seconds...",
operation_time,
Expand Down

0 comments on commit 025c267

Please sign in to comment.