|
10 | 10 | from dbtsl.api.graphql.client.asyncio import AsyncGraphQLClient |
11 | 11 | from dbtsl.api.graphql.client.sync import SyncGraphQLClient |
12 | 12 | from dbtsl.api.graphql.protocol import GetQueryResultVariables, GraphQLProtocol, ProtocolOperation |
| 13 | +from dbtsl.error import RetryTimeoutError |
13 | 14 | from dbtsl.models.query import QueryId, QueryResult, QueryStatus |
14 | 15 |
|
15 | 16 | # The following 2 tests are copies of each other since testing the same sync/async functionality is |
@@ -145,3 +146,63 @@ def run_behavior(op: ProtocolOperation[Any, Any], raw_variables: GetQueryResultV |
145 | 146 | ) |
146 | 147 |
|
147 | 148 | assert result_table.equals(table, check_metadata=True) |
| 149 | + |
| 150 | + |
| 151 | +# avoid raising mock warning related to mocking a context manager |
| 152 | +@pytest.mark.filterwarnings("ignore::pytest_mock.PytestMockWarning") |
| 153 | +def test_sync_poll_timeout_includes_status(mocker: MockerFixture) -> None: |
| 154 | + """Test that RetryTimeoutError includes the last known query status.""" |
| 155 | + client = SyncGraphQLClient(server_host="test", environment_id=0, auth_token="test", timeout=0.001, lazy=False) |
| 156 | + |
| 157 | + compiled_result = QueryResult( |
| 158 | + query_id=QueryId("test-query-id"), |
| 159 | + status=QueryStatus.COMPILED, |
| 160 | + sql=None, |
| 161 | + error=None, |
| 162 | + total_pages=None, |
| 163 | + arrow_result=None, |
| 164 | + ) |
| 165 | + |
| 166 | + run_mock = MagicMock(return_value=compiled_result) |
| 167 | + mocker.patch.object(client, "_run", new=run_mock) |
| 168 | + |
| 169 | + mocker.patch.object(client, "create_query", return_value=QueryId("test-query-id")) |
| 170 | + |
| 171 | + gql_mock = mocker.patch.object(client, "_gql") |
| 172 | + mocker.patch.object(gql_mock, "__aenter__") |
| 173 | + mocker.patch("dbtsl.api.graphql.client.sync.isinstance", return_value=True) |
| 174 | + |
| 175 | + with client.session(): |
| 176 | + with pytest.raises(RetryTimeoutError) as exc_info: |
| 177 | + client.query(metrics=["m1"]) |
| 178 | + |
| 179 | + assert exc_info.value.status == "COMPILED" |
| 180 | + |
| 181 | + |
| 182 | +async def test_async_poll_timeout_includes_status(mocker: MockerFixture) -> None: |
| 183 | + """Test that RetryTimeoutError includes the last known query status (async).""" |
| 184 | + client = AsyncGraphQLClient(server_host="test", environment_id=0, auth_token="test", timeout=0.001, lazy=False) |
| 185 | + |
| 186 | + compiled_result = QueryResult( |
| 187 | + query_id=QueryId("test-query-id"), |
| 188 | + status=QueryStatus.COMPILED, |
| 189 | + sql=None, |
| 190 | + error=None, |
| 191 | + total_pages=None, |
| 192 | + arrow_result=None, |
| 193 | + ) |
| 194 | + |
| 195 | + run_mock = AsyncMock(return_value=compiled_result) |
| 196 | + mocker.patch.object(client, "_run", new=run_mock) |
| 197 | + |
| 198 | + mocker.patch.object(client, "create_query", return_value=QueryId("test-query-id"), new_callable=AsyncMock) |
| 199 | + |
| 200 | + gql_mock = mocker.patch.object(client, "_gql") |
| 201 | + mocker.patch.object(gql_mock, "__aenter__", new_callable=AsyncMock) |
| 202 | + mocker.patch("dbtsl.api.graphql.client.asyncio.isinstance", return_value=True) |
| 203 | + |
| 204 | + async with client.session(): |
| 205 | + with pytest.raises(RetryTimeoutError) as exc_info: |
| 206 | + await client.query(metrics=["m1"]) |
| 207 | + |
| 208 | + assert exc_info.value.status == "COMPILED" |
0 commit comments