Skip to content

Commit 07d2ad6

Browse files
committed
test: temp changes to check_connections DAG for stress test
1 parent 1e14988 commit 07d2ad6

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/aind_airflow_jobs/dag_tasks/check_connections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
from pathlib import Path
8+
from time import sleep
89

910
import boto3
1011

@@ -16,6 +17,8 @@
1617
stream=sys.stdout,
1718
)
1819

20+
SLEEP_TIME = 120
21+
1922

2023
class CheckConnectionsDag(DagTasks):
2124
"""DAG tasks for checking connections to external services."""
@@ -43,6 +46,7 @@ def check_param_store_connection(self):
4346
raise AssertionError("Unable to retrieve ams_uri!")
4447
if not co_uri:
4548
raise AssertionError("Unable to retrieve co_uri!")
49+
sleep(SLEEP_TIME)
4650

4751
def check_aws_connection(self):
4852
"""Check AWS S3 connection."""
@@ -59,6 +63,7 @@ def check_aws_connection(self):
5963
)
6064
finally:
6165
s3_client.close()
66+
sleep(SLEEP_TIME)
6267

6368
def check_slurm_connection(self):
6469
"""Check SLURM connection."""
@@ -81,6 +86,7 @@ def check_vast_connection(self):
8186
is_dir = Path(mounted_directory).is_dir()
8287
if not is_dir:
8388
raise NotADirectoryError(f"{mounted_directory} not recognized!")
89+
sleep(SLEEP_TIME)
8490

8591
def check_hpc_connection(self):
8692
"""Check hpc ssh command output can be read"""

tests/dag_tasks/test_check_connections.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def setUpClass(cls):
2222
dag = CheckConnectionsDag(airflow_task_settings=settings)
2323
cls.dag = dag
2424

25+
@patch("aind_airflow_jobs.dag_tasks.check_connections.sleep")
2526
@patch.dict(
2627
"os.environ",
2728
{
@@ -31,7 +32,7 @@ def setUpClass(cls):
3132
},
3233
clear=True,
3334
)
34-
def test_check_param_store_connection(self):
35+
def test_check_param_store_connection(self, mock_sleep: MagicMock):
3536
"""Tests check_param_store_connection."""
3637

3738
with self.assertLogs(level="INFO") as captured:
@@ -44,6 +45,7 @@ def test_check_param_store_connection(self):
4445
],
4546
captured.output,
4647
)
48+
mock_sleep.assert_called_once()
4749

4850
@patch.dict(
4951
"os.environ",
@@ -122,8 +124,11 @@ def test_check_param_store_connection_missing_co_uri(self):
122124

123125
self.assertEqual("Unable to retrieve co_uri!", exc.exception.args[0])
124126

127+
@patch("aind_airflow_jobs.dag_tasks.check_connections.sleep")
125128
@patch("aind_airflow_jobs.dag_tasks.check_connections.boto3.client")
126-
def test_check_aws_connection(self, mock_boto_client: MagicMock):
129+
def test_check_aws_connection(
130+
self, mock_boto_client: MagicMock, mock_sleep: MagicMock
131+
):
127132
"""Tests check_aws_connection."""
128133

129134
mock_s3_client = MagicMock()
@@ -136,6 +141,7 @@ def test_check_aws_connection(self, mock_boto_client: MagicMock):
136141
Bucket="my-bucket", MaxKeys=1
137142
)
138143
mock_s3_client.close.assert_called_once()
144+
mock_sleep.assert_called_once()
139145

140146
@patch("aind_airflow_jobs.dag_tasks.check_connections.boto3.client")
141147
def test_check_aws_connection_closes_on_error(
@@ -189,14 +195,18 @@ def test_check_slurm_connection(
189195
captured.output,
190196
)
191197

198+
@patch("aind_airflow_jobs.dag_tasks.check_connections.sleep")
192199
@patch("aind_airflow_jobs.dag_tasks.check_connections.Path.is_dir")
193-
def test_check_vast_connection(self, mock_is_dir: MagicMock):
200+
def test_check_vast_connection(
201+
self, mock_is_dir: MagicMock, mock_sleep: MagicMock
202+
):
194203
"""Tests check_vast_connection validates mounted directory."""
195204

196205
mock_is_dir.return_value = True
197206
self.dag.check_vast_connection()
198207

199208
mock_is_dir.assert_called_once_with()
209+
mock_sleep.assert_called_once()
200210

201211
@patch("aind_airflow_jobs.dag_tasks.check_connections.Path.is_dir")
202212
def test_check_vast_connection_not_directory(self, mock_is_dir: MagicMock):

0 commit comments

Comments
 (0)