diff --git a/Pipfile.lock b/Pipfile.lock index 29dfe1e..297e506 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -119,11 +119,11 @@ }, "alembic": { "hashes": [ - "sha256:295b54bbb92c4008ab6a7dcd1e227e668416d6f84b98b3c4446a2bc6214a556b", - "sha256:43942c3d4bf2620c466b91c0f4fca136fe51ae972394a0cc8b90810d664e4f5c" + "sha256:d8bf706124e96e526889ac9c87a0d50debd9ef325ef32ae5391cf0315bdab4e1", + "sha256:f0e74af5a6ade86b72770790188aaf64122c9cba64efd1d7ff3323ac3fdb75e0" ], "markers": "python_version >= '3.7'", - "version": "==1.10.4" + "version": "==1.11.0" }, "anyio": { "hashes": [ @@ -135,11 +135,11 @@ }, "apache-airflow": { "hashes": [ - "sha256:78cc7957546fd74eee09234ad39fe7a6c913a114d66077fc85410a2cedec51ea", - "sha256:a7375b1b738f129462e70eb5a1bb95f604862fcb6437047ee159e5b885739402" + "sha256:26f5d5f39b5e49b4cc7cc3f4e536078623251262185c37fe4ea839cf0b566c91", + "sha256:628b42491b5f922fef0ebbdba0b5341fe32782826b6817e56069358378911f1e" ], "markers": "python_version ~= '3.7'", - "version": "==2.6.0" + "version": "==2.6.1" }, "apache-airflow-providers-common-sql": { "hashes": [ @@ -528,11 +528,11 @@ }, "docutils": { "hashes": [ - "sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6", - "sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc" + "sha256:a428f10de4de4774389734c986a01b4af2d802d26717108b0f1b9356862937c5", + "sha256:f75a5a52fbcacd81b47e42888ad2b380748aaccfb3f13af0fe69deb759f01eb6" ], "markers": "python_version >= '3.7'", - "version": "==0.19" + "version": "==0.20" }, "email-validator": { "hashes": [ @@ -599,10 +599,11 @@ }, "flask-session": { "hashes": [ - "sha256:2f3954a8ca2fd4fdc9ffda97f5f469668f5f18fab0fe2f69d496d17be312d96e", - "sha256:e87c9daef93336e75dbf114f5fdec92f67bac21cef541b8d37173461b6174eca" + "sha256:1619bcbc16f04f64e90f8e0b17145ba5c9700090bb1294e889956c1282d58631", + "sha256:190875e6aebf2953c6803d42379ef3b934bc209ef8ef006f97aecb08f5aaeb86" ], - "version": "==0.4.1" + "markers": "python_version >= '3.7'", + "version": "==0.5.0" }, "flask-sqlalchemy": { "hashes": [ @@ -1293,11 +1294,11 @@ }, "pyjwt": { "hashes": [ - "sha256:69285c7e31fc44f68a1feb309e948e0df53259d579295e6cfe2b1792329f05fd", - "sha256:d83c3d892a77bbb74d3e1a2cfa90afaadb60945205d1095d9221f04466f64c14" + "sha256:ba2b425b15ad5ef12f200dc67dd56af4e26de2331f965c5439994dad075876e1", + "sha256:bd6ca4a3c4285c1a2d4349e5a035fdf8fb94e04ccd0fcbe6ba289dae9cc3e074" ], "markers": "python_version >= '3.7'", - "version": "==2.6.0" + "version": "==2.7.0" }, "pyrsistent": { "hashes": [ @@ -2026,11 +2027,11 @@ }, "alembic": { "hashes": [ - "sha256:295b54bbb92c4008ab6a7dcd1e227e668416d6f84b98b3c4446a2bc6214a556b", - "sha256:43942c3d4bf2620c466b91c0f4fca136fe51ae972394a0cc8b90810d664e4f5c" + "sha256:d8bf706124e96e526889ac9c87a0d50debd9ef325ef32ae5391cf0315bdab4e1", + "sha256:f0e74af5a6ade86b72770790188aaf64122c9cba64efd1d7ff3323ac3fdb75e0" ], "markers": "python_version >= '3.7'", - "version": "==1.10.4" + "version": "==1.11.0" }, "anyio": { "hashes": [ @@ -2042,11 +2043,11 @@ }, "apache-airflow": { "hashes": [ - "sha256:78cc7957546fd74eee09234ad39fe7a6c913a114d66077fc85410a2cedec51ea", - "sha256:a7375b1b738f129462e70eb5a1bb95f604862fcb6437047ee159e5b885739402" + "sha256:26f5d5f39b5e49b4cc7cc3f4e536078623251262185c37fe4ea839cf0b566c91", + "sha256:628b42491b5f922fef0ebbdba0b5341fe32782826b6817e56069358378911f1e" ], "markers": "python_version ~= '3.7'", - "version": "==2.6.0" + "version": "==2.6.1" }, "apache-airflow-providers-common-sql": { "hashes": [ @@ -2664,11 +2665,11 @@ }, "docutils": { "hashes": [ - "sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6", - "sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc" + "sha256:a428f10de4de4774389734c986a01b4af2d802d26717108b0f1b9356862937c5", + "sha256:f75a5a52fbcacd81b47e42888ad2b380748aaccfb3f13af0fe69deb759f01eb6" ], "markers": "python_version >= '3.7'", - "version": "==0.19" + "version": "==0.20" }, "email-validator": { "hashes": [ @@ -2772,10 +2773,11 @@ }, "flask-session": { "hashes": [ - "sha256:2f3954a8ca2fd4fdc9ffda97f5f469668f5f18fab0fe2f69d496d17be312d96e", - "sha256:e87c9daef93336e75dbf114f5fdec92f67bac21cef541b8d37173461b6174eca" + "sha256:1619bcbc16f04f64e90f8e0b17145ba5c9700090bb1294e889956c1282d58631", + "sha256:190875e6aebf2953c6803d42379ef3b934bc209ef8ef006f97aecb08f5aaeb86" ], - "version": "==0.4.1" + "markers": "python_version >= '3.7'", + "version": "==0.5.0" }, "flask-sqlalchemy": { "hashes": [ @@ -3044,11 +3046,11 @@ }, "ipykernel": { "hashes": [ - "sha256:bd6f487d9e2744c84f6e667d46462d7647a4c862e70e08282f05a52b9d4b705f", - "sha256:fc886f1dcdc0ec17f277e4d21fd071c857d381adcb04f3f3735d25325ca323c6" + "sha256:1aba0ae8453e15e9bc6b24e497ef6840114afcdb832ae597f32137fa19d42a6f", + "sha256:77aeffab056c21d16f1edccdc9e5ccbf7d96eb401bd6703610a21be8b068aadc" ], "markers": "python_version >= '3.8'", - "version": "==6.23.0" + "version": "==6.23.1" }, "ipython": { "hashes": [ @@ -3106,10 +3108,10 @@ }, "json5": { "hashes": [ - "sha256:1aa54b80b5e507dfe31d12b7743a642e2ffa6f70bf73b8e3d7d1d5fba83d99bd", - "sha256:4f1e196acc55b83985a51318489f345963c7ba84aa37607e49073066c562e99b" + "sha256:740c7f1b9e584a468dbb2939d8d458db3427f2c93ae2139d05f47e453eae964f", + "sha256:9ed66c3a6ca3510a976a9ef9b8c0787de24802724ab1860bc0153c7fdd589b02" ], - "version": "==0.9.11" + "version": "==0.9.14" }, "jsonpointer": { "hashes": [ @@ -3511,35 +3513,35 @@ }, "mypy": { "hashes": [ - "sha256:023fe9e618182ca6317ae89833ba422c411469156b690fde6a315ad10695a521", - "sha256:031fc69c9a7e12bcc5660b74122ed84b3f1c505e762cc4296884096c6d8ee140", - "sha256:2de7babe398cb7a85ac7f1fd5c42f396c215ab3eff731b4d761d68d0f6a80f48", - "sha256:2e93a8a553e0394b26c4ca683923b85a69f7ccdc0139e6acd1354cc884fe0128", - "sha256:390bc685ec209ada4e9d35068ac6988c60160b2b703072d2850457b62499e336", - "sha256:3a2d219775a120581a0ae8ca392b31f238d452729adbcb6892fa89688cb8306a", - "sha256:3efde4af6f2d3ccf58ae825495dbb8d74abd6d176ee686ce2ab19bd025273f41", - "sha256:4a99fe1768925e4a139aace8f3fb66db3576ee1c30b9c0f70f744ead7e329c9f", - "sha256:4b41412df69ec06ab141808d12e0bf2823717b1c363bd77b4c0820feaa37249e", - "sha256:4c8d8c6b80aa4a1689f2a179d31d86ae1367ea4a12855cc13aa3ba24bb36b2d8", - "sha256:4d19f1a239d59f10fdc31263d48b7937c585810288376671eaf75380b074f238", - "sha256:4e4a682b3f2489d218751981639cffc4e281d548f9d517addfd5a2917ac78119", - "sha256:695c45cea7e8abb6f088a34a6034b1d273122e5530aeebb9c09626cea6dca4cb", - "sha256:701189408b460a2ff42b984e6bd45c3f41f0ac9f5f58b8873bbedc511900086d", - "sha256:70894c5345bea98321a2fe84df35f43ee7bb0feec117a71420c60459fc3e1eed", - "sha256:8293a216e902ac12779eb7a08f2bc39ec6c878d7c6025aa59464e0c4c16f7eb9", - "sha256:8d26b513225ffd3eacece727f4387bdce6469192ef029ca9dd469940158bc89e", - "sha256:a197ad3a774f8e74f21e428f0de7f60ad26a8d23437b69638aac2764d1e06a6a", - "sha256:bea55fc25b96c53affab852ad94bf111a3083bc1d8b0c76a61dd101d8a388cf5", - "sha256:c9a084bce1061e55cdc0493a2ad890375af359c766b8ac311ac8120d3a472950", - "sha256:d0e9464a0af6715852267bf29c9553e4555b61f5904a4fc538547a4d67617937", - "sha256:d8e9187bfcd5ffedbe87403195e1fc340189a68463903c39e2b63307c9fa0394", - "sha256:eaeaa0888b7f3ccb7bcd40b50497ca30923dba14f385bde4af78fac713d6d6f6", - "sha256:f46af8d162f3d470d8ffc997aaf7a269996d205f9d746124a179d3abe05ac602", - "sha256:f70a40410d774ae23fcb4afbbeca652905a04de7948eaf0b1789c8d1426b72d1", - "sha256:fe91be1c51c90e2afe6827601ca14353bbf3953f343c2129fa1e247d55fd95ba" + "sha256:1c4c42c60a8103ead4c1c060ac3cdd3ff01e18fddce6f1016e08939647a0e703", + "sha256:44797d031a41516fcf5cbfa652265bb994e53e51994c1bd649ffcd0c3a7eccbf", + "sha256:473117e310febe632ddf10e745a355714e771ffe534f06db40702775056614c4", + "sha256:4c99c3ecf223cf2952638da9cd82793d8f3c0c5fa8b6ae2b2d9ed1e1ff51ba85", + "sha256:550a8b3a19bb6589679a7c3c31f64312e7ff482a816c96e0cecec9ad3a7564dd", + "sha256:658fe7b674769a0770d4b26cb4d6f005e88a442fe82446f020be8e5f5efb2fae", + "sha256:6e33bb8b2613614a33dff70565f4c803f889ebd2f859466e42b46e1df76018dd", + "sha256:6e42d29e324cdda61daaec2336c42512e59c7c375340bd202efa1fe0f7b8f8ca", + "sha256:74bc9b6e0e79808bf8678d7678b2ae3736ea72d56eede3820bd3849823e7f305", + "sha256:76ec771e2342f1b558c36d49900dfe81d140361dd0d2df6cd71b3db1be155409", + "sha256:7d23370d2a6b7a71dc65d1266f9a34e4cde9e8e21511322415db4b26f46f6b8c", + "sha256:87df44954c31d86df96c8bd6e80dfcd773473e877ac6176a8e29898bfb3501cb", + "sha256:8c5979d0deb27e0f4479bee18ea0f83732a893e81b78e62e2dda3e7e518c92ee", + "sha256:95d8d31a7713510685b05fbb18d6ac287a56c8f6554d88c19e73f724a445448a", + "sha256:a22435632710a4fcf8acf86cbd0d69f68ac389a3892cb23fbad176d1cddaf228", + "sha256:a8763e72d5d9574d45ce5881962bc8e9046bf7b375b0abf031f3e6811732a897", + "sha256:c1eb485cea53f4f5284e5baf92902cd0088b24984f4209e25981cc359d64448d", + "sha256:c5d2cc54175bab47011b09688b418db71403aefad07cbcd62d44010543fc143f", + "sha256:cbc07246253b9e3d7d74c9ff948cd0fd7a71afcc2b77c7f0a59c26e9395cb152", + "sha256:d0b6c62206e04061e27009481cb0ec966f7d6172b5b936f3ead3d74f29fe3dcf", + "sha256:ddae0f39ca146972ff6bb4399f3b2943884a774b8771ea0a8f50e971f5ea5ba8", + "sha256:e1f4d16e296f5135624b34e8fb741eb0eadedca90862405b1f1fde2040b9bd11", + "sha256:e86c2c6852f62f8f2b24cb7a613ebe8e0c7dc1402c61d36a609174f63e0ff017", + "sha256:ebc95f8386314272bbc817026f8ce8f4f0d2ef7ae44f947c4664efac9adec929", + "sha256:f9dca1e257d4cc129517779226753dbefb4f2266c4eaad610fc15c6a7e14283e", + "sha256:faff86aa10c1aa4a10e1a301de160f3d8fc8703b88c7e98de46b531ff1276a9a" ], "markers": "python_version >= '3.7'", - "version": "==1.2.0" + "version": "==1.3.0" }, "mypy-extensions": { "hashes": [ @@ -3591,11 +3593,11 @@ }, "nodeenv": { "hashes": [ - "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e", - "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b" + "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2", + "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'", - "version": "==1.7.0" + "version": "==1.8.0" }, "notebook": { "hashes": [ @@ -3696,11 +3698,11 @@ }, "platformdirs": { "hashes": [ - "sha256:47692bc24c1958e8b0f13dd727307cff1db103fca36399f457da8e05f222fdc4", - "sha256:7954a68d0ba23558d753f73437c55f89027cf8f5108c19844d4b82e5af396335" + "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f", + "sha256:e2378146f1964972c03c085bb5662ae80b2b8c06226c54b2ff4aa9483e8a13a5" ], "markers": "python_version >= '3.7'", - "version": "==3.5.0" + "version": "==3.5.1" }, "pluggy": { "hashes": [ @@ -3865,11 +3867,11 @@ }, "pyjwt": { "hashes": [ - "sha256:69285c7e31fc44f68a1feb309e948e0df53259d579295e6cfe2b1792329f05fd", - "sha256:d83c3d892a77bbb74d3e1a2cfa90afaadb60945205d1095d9221f04466f64c14" + "sha256:ba2b425b15ad5ef12f200dc67dd56af4e26de2331f965c5439994dad075876e1", + "sha256:bd6ca4a3c4285c1a2d4349e5a035fdf8fb94e04ccd0fcbe6ba289dae9cc3e074" ], "markers": "python_version >= '3.7'", - "version": "==2.6.0" + "version": "==2.7.0" }, "pyrsistent": { "hashes": [ @@ -3912,6 +3914,14 @@ "markers": "python_version >= '3.7'", "version": "==7.3.1" }, + "pytest-asyncio": { + "hashes": [ + "sha256:2b38a496aef56f56b0e87557ec313e11e1ab9276fc3863f6a7be0f1d0e415e1b", + "sha256:f2b3366b7cd501a4056858bd39349d5af19742aed2d81660b7998b6341c7eb9c" + ], + "markers": "python_version >= '3.7'", + "version": "==0.21.0" + }, "pytest-cov": { "hashes": [ "sha256:2feb1b751d66a8bd934e5edfa2e961d11309dc37b73b0eabe73b5945fee20f6b", @@ -4521,20 +4531,20 @@ }, "tornado": { "hashes": [ - "sha256:1285f0691143f7ab97150831455d4db17a267b59649f7bd9700282cba3d5e771", - "sha256:3455133b9ff262fd0a75630af0a8ee13564f25fb4fd3d9ce239b8a7d3d027bf8", - "sha256:5e2f49ad371595957c50e42dd7e5c14d64a6843a3cf27352b69c706d1b5918af", - "sha256:81c17e0cc396908a5e25dc8e9c5e4936e6dfd544c9290be48bd054c79bcad51e", - "sha256:90f569a35a8ec19bde53aa596952071f445da678ec8596af763b9b9ce07605e6", - "sha256:9661aa8bc0e9d83d757cd95b6f6d1ece8ca9fd1ccdd34db2de381e25bf818233", - "sha256:a27a1cfa9997923f80bdd962b3aab048ac486ad8cfb2f237964f8ab7f7eb824b", - "sha256:b4e7b956f9b5e6f9feb643ea04f07e7c6b49301e03e0023eedb01fa8cf52f579", - "sha256:d7117f3c7ba5d05813b17a1f04efc8e108a1b811ccfddd9134cc68553c414864", - "sha256:db181eb3df8738613ff0a26f49e1b394aade05034b01200a63e9662f347d4415", - "sha256:ffdce65a281fd708da5a9def3bfb8f364766847fa7ed806821a69094c9629e8a" + "sha256:05615096845cf50a895026f749195bf0b10b8909f9be672f50b0fe69cba368e4", + "sha256:0c325e66c8123c606eea33084976c832aa4e766b7dff8aedd7587ea44a604cdf", + "sha256:29e71c847a35f6e10ca3b5c2990a52ce38b233019d8e858b755ea6ce4dcdd19d", + "sha256:4b927c4f19b71e627b13f3db2324e4ae660527143f9e1f2e2fb404f3a187e2ba", + "sha256:5b17b1cf5f8354efa3d37c6e28fdfd9c1c1e5122f2cb56dac121ac61baa47cbe", + "sha256:6a0848f1aea0d196a7c4f6772197cbe2abc4266f836b0aac76947872cd29b411", + "sha256:7efcbcc30b7c654eb6a8c9c9da787a851c18f8ccd4a5a3a95b05c7accfa068d2", + "sha256:834ae7540ad3a83199a8da8f9f2d383e3c3d5130a328889e4cc991acc81e87a0", + "sha256:b46a6ab20f5c7c1cb949c72c1994a4585d2eaa0be4853f50a03b5031e964fc7c", + "sha256:c2de14066c4a38b4ecbbcd55c5cc4b5340eb04f1c5e81da7451ef555859c833f", + "sha256:c367ab6c0393d71171123ca5515c61ff62fe09024fa6bf299cd1339dc9456829" ], "markers": "python_version >= '3.8'", - "version": "==6.3.1" + "version": "==6.3.2" }, "tox": { "hashes": [ diff --git a/setup.cfg b/setup.cfg index 8b4c18d..9230762 100644 --- a/setup.cfg +++ b/setup.cfg @@ -79,6 +79,7 @@ testing = pytest-cov~=4.0 pytest-mock~=3.0 pytest-dotenv~=0.5.2 + pytest-asyncio~=0.21.0 # Dependencies for development (used by Pipenv) dev = @@ -120,7 +121,6 @@ apache_airflow_provider = # Comment those flags to avoid this pytest issue. addopts = --cov "orca" --cov-report "term-missing" --cov-report "xml" - -m "not slow and not integration and not acceptance and not cost" --verbose norecursedirs = dist diff --git a/src/orca/services/nextflowtower/models.py b/src/orca/services/nextflowtower/models.py index 2cbb736..50036b0 100644 --- a/src/orca/services/nextflowtower/models.py +++ b/src/orca/services/nextflowtower/models.py @@ -321,6 +321,10 @@ class Workflow(BaseTowerModel): "state": "status", } + def __repr__(self) -> str: + """String representation of a workflow.""" + return f"Workflow(run_name={self.run_name}, id={self.id}, state={self.state})" + @property def status(self) -> WorkflowStatus: """Workflow run status.""" diff --git a/src/orca/services/nextflowtower/ops.py b/src/orca/services/nextflowtower/ops.py index b34c1bb..92c1d47 100644 --- a/src/orca/services/nextflowtower/ops.py +++ b/src/orca/services/nextflowtower/ops.py @@ -1,3 +1,4 @@ +import asyncio import logging from dataclasses import field from functools import cached_property @@ -180,18 +181,6 @@ def get_workflow(self, workflow_id: str) -> Workflow: """ return self.client.get_workflow(workflow_id, self.workspace_id) - def get_workflow_status(self, workflow_id: str) -> WorkflowStatus: - """Retrieve status of a workflow run. - - Args: - workflow_id: Workflow run ID. - - Returns: - Workflow status and whether the workflow is done. - """ - workflow = self.get_workflow(workflow_id) - return workflow.status - def list_workflows(self, search_filter: str = "") -> list[Workflow]: """List available workflows that match search filter. @@ -261,3 +250,25 @@ def get_latest_previous_workflow( # Otherwise, return latest based on submission timestamp sorted_runs = sorted(previous_runs, key=lambda x: x.get("submit")) return sorted_runs[-1] + + async def monitor_workflow( + self, run_id: str, wait_time: int = 60 * 5 + ) -> WorkflowStatus: + """Wait until the workflow run completes. + + Args: + run_id: Workflow run ID. + wait_time: Number of seconds to wait between checks. + Default is 5 minutes. + + Returns: + Final workflow status. + """ + workflow = self.get_workflow(run_id) + while not workflow.status.is_done: + logger.info(f"{workflow} is not done yet...") + await asyncio.sleep(wait_time) + workflow = self.get_workflow(run_id) + + logger.info(f"{workflow} is now done!") + return workflow.status diff --git a/tests/services/nextflowtower/test_integration.py b/tests/services/nextflowtower/test_integration.py index 2d1b6d7..aaf9511 100644 --- a/tests/services/nextflowtower/test_integration.py +++ b/tests/services/nextflowtower/test_integration.py @@ -44,6 +44,17 @@ def test_that_a_workflow_can_be_launched(ops): assert workflow_id +@pytest.mark.integration +def test_that_a_workflow_can_be_retrieved(ops): + launch_info = models.LaunchInfo( + pipeline="nextflow-io/hello", + run_name="test_get_workflow", + ) + workflow_id = ops.launch_workflow(launch_info, "spot") + workflow = ops.get_workflow(workflow_id) + assert workflow + + @pytest.mark.integration def test_that_a_workflow_can_be_relaunched(ops): launch_info = models.LaunchInfo( diff --git a/tests/services/nextflowtower/test_ops.py b/tests/services/nextflowtower/test_ops.py index b2533ed..c06a9a3 100644 --- a/tests/services/nextflowtower/test_ops.py +++ b/tests/services/nextflowtower/test_ops.py @@ -138,32 +138,6 @@ def test_that_launch_workflow_works(mocked_ops, get_response, mocker): assert launch_info.compute_env_id == response["computeEnv"]["id"] -def test_that_get_workflow_status_returns_expected_status_for_complete_workflow( - mocker, get_response, mocked_ops -): - response = get_response("get_workflow") - expected = models.Workflow.from_json(response["workflow"]) - mock = mocker.patch.object(mocked_ops, "client") - mock.get_workflow.return_value = expected - result = mocked_ops.get_workflow_status(workflow_id="123456789") - mock.get_workflow.assert_called_once() - assert result == models.WorkflowStatus("SUCCEEDED") - - -def test_that_get_workflow_status_returns_expected_status_for_incomplete_workflow( - mocked_ops, mocker, get_response -): - response = get_response("get_workflow") - response["workflow"]["complete"] = None - response["workflow"]["status"] = "SUBMITTED" - expected = models.Workflow.from_json(response["workflow"]) - mock = mocker.patch.object(mocked_ops, "client") - mock.get_workflow.return_value = expected - result = mocked_ops.get_workflow_status(workflow_id="123456789") - mock.get_workflow.assert_called_once() - assert result == models.WorkflowStatus("SUBMITTED") - - def test_that_list_workflows_filters_on_launch_label(mocked_ops, mocker): mock = mocker.patch.object(mocked_ops.client, "list_workflows") mocked_ops.list_workflows() @@ -295,3 +269,36 @@ def test_that_launch_workflow_works_when_there_are_no_previous_runs( assert launch_info.run_name == "example-run" assert not launch_info.resume assert launch_info.session_id is None + + +@pytest.mark.asyncio +async def test_that_monitor_workflow_works_for_a_complete_workflow( + mocker, get_response, mocked_ops +): + response = get_response("get_workflow") + workflow = models.Workflow.from_json(response["workflow"]) + + mock = mocker.patch.object(mocked_ops, "get_workflow") + mock.return_value = workflow + + result = await mocked_ops.monitor_workflow("123456789", wait_time=0.01) + + mock.assert_called_once() + assert result == models.WorkflowStatus("SUCCEEDED") + + +@pytest.mark.asyncio +async def test_that_monitor_workflow_works_for_an_incomplete_workflow( + mocker, get_response, mocked_ops +): + response = get_response("get_workflow") + complete_workflow = models.Workflow.from_json(response["workflow"]) + incomplete_workflow = replace(complete_workflow, state="RUNNING") + + mock = mocker.patch.object(mocked_ops, "get_workflow") + mock.side_effect = [incomplete_workflow] * 2 + [complete_workflow] + + result = await mocked_ops.monitor_workflow("123456789", wait_time=0.01) + + assert mock.call_count > 1 + assert result == models.WorkflowStatus("SUCCEEDED")