Skip to content

Commit

Permalink
Add time_out parameter for wait_operation. (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiliDeng committed Jan 6, 2022
1 parent 8106c40 commit 73fd462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lisa/sut_orchestrator/azure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT license.

import re
import sys
from dataclasses import InitVar, dataclass, field
from threading import Lock
from time import sleep
Expand Down Expand Up @@ -325,16 +326,17 @@ def get_environment_context(environment: Environment) -> EnvironmentContext:
return environment.get_context(EnvironmentContext)


def wait_operation(operation: Any) -> Any:
timeout = 60 * 5
def wait_operation(operation: Any, time_out: int = sys.maxsize) -> Any:
timer = create_timer()
while timeout > timer.elapsed(False):
while time_out > timer.elapsed(False):
check_cancelled()
if operation.done():
break
operation.wait(1)
if timeout < timer.elapsed():
raise Exception("Timeout on operation")
if time_out < timer.elapsed():
raise Exception(
f"timeout on wait Azure operation completed after {time_out} seconds."
)


def get_storage_credential(
Expand Down
2 changes: 1 addition & 1 deletion lisa/sut_orchestrator/azure/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ def resize(
)

# Waiting for the Long Running Operation to finish
wait_operation(lro_poller)
wait_operation(lro_poller, time_out=300)

self._node.close()
self._node.capability = schema.load_by_type(
Expand Down

0 comments on commit 73fd462

Please sign in to comment.