async def test_failure_first_attempt(self, _sleep): from google.api_core import exceptions # Create a minimal fake GAPIC with a dummy result. firestore_api = AsyncMock() # Make sure the first request fails with an un-retryable error. exc = exceptions.ResourceExhausted("We ran out of fries.") firestore_api.commit.side_effect = exc # Attach the fake GAPIC to a real client. client = _make_client("peanut-butter") client._firestore_api_internal = firestore_api # Call function and check result. txn_id = b"\x08\x06\x07\x05\x03\x00\x09-jenny" with self.assertRaises(exceptions.ResourceExhausted) as exc_info: await self._call_fut(client, mock.sentinel.write_pbs, txn_id) self.assertIs(exc_info.exception, exc) # Verify mocks used. _sleep.assert_not_called() firestore_api.commit.assert_called_once_with( request={ "database": client._database_string, "writes": mock.sentinel.write_pbs, "transaction": txn_id, }, metadata=client._rpc_metadata, )
def test__commit_with_retry_failure_first_attempt(_sleep): from google.api_core import exceptions from google.cloud.firestore_v1.services.firestore import client as firestore_client from google.cloud.firestore_v1.transaction import _commit_with_retry # Create a minimal fake GAPIC with a dummy result. firestore_api = mock.create_autospec(firestore_client.FirestoreClient, instance=True) # Make sure the first request fails with an un-retryable error. exc = exceptions.ResourceExhausted("We ran out of fries.") firestore_api.commit.side_effect = exc # Attach the fake GAPIC to a real client. client = _make_client("peanut-butter") client._firestore_api_internal = firestore_api # Call function and check result. txn_id = b"\x08\x06\x07\x05\x03\x00\x09-jenny" with pytest.raises(exceptions.ResourceExhausted) as exc_info: _commit_with_retry(client, mock.sentinel.write_pbs, txn_id) assert exc_info.value is exc # Verify mocks used. _sleep.assert_not_called() firestore_api.commit.assert_called_once_with( request={ "database": client._database_string, "writes": mock.sentinel.write_pbs, "transaction": txn_id, }, metadata=client._rpc_metadata, )
def test_failure_first_attempt(self, _sleep): from google.api_core import exceptions from google.cloud.firestore_v1beta1.gapic import firestore_client # Create a minimal fake GAPIC with a dummy result. firestore_api = mock.create_autospec(firestore_client.FirestoreClient, instance=True) # Make sure the first request fails with an un-retryable error. exc = exceptions.ResourceExhausted('We ran out of fries.') firestore_api.commit.side_effect = exc # Attach the fake GAPIC to a real client. client = _make_client('peanut-butter') client._firestore_api_internal = firestore_api # Call function and check result. txn_id = b'\x08\x06\x07\x05\x03\x00\x09-jenny' with self.assertRaises(exceptions.ResourceExhausted) as exc_info: self._call_fut(client, mock.sentinel.write_pbs, txn_id) self.assertIs(exc_info.exception, exc) # Verify mocks used. _sleep.assert_not_called() firestore_api.commit.assert_called_once_with( client._database_string, mock.sentinel.write_pbs, transaction=txn_id, metadata=client._rpc_metadata)