Commit c4fea9af authored by dmitry.mashoshin's avatar dmitry.mashoshin
Browse files

Merge branch 'mashony/add-initial-noop' into 'master'

feat: add initial noop to add posibility to get latest ts if query is empty during initial sync

See merge request !191
parents 52de711a e769e04a
......@@ -283,6 +283,8 @@ class MongoDBMirror:
)
else:
await client.upsert(ts, send_data)
# send noop always to be able to get latest ts even if query if empty
await client.noop(ts, {})
async def _get_newest_oplog_ts(self):
"""Get the latest timestamp of the change log in db.
......
......@@ -225,7 +225,8 @@ class TestMongoDBMirror:
mock_serialize_document, init_point, collection_filter):
mock_client = Mock(
get_sync_init_point=AsyncMock(return_value=init_point),
upsert=AsyncMock()
upsert=AsyncMock(),
noop=AsyncMock(return_value='')
)
mocked_acl_context = Mock()
mock_client.ws.acl_context = mocked_acl_context
......@@ -239,6 +240,7 @@ class TestMongoDBMirror:
mock_get_newest_oplog_ts.assert_called_once()
mock_find.assert_called_once_with(collection_filter, batch_size=10)
mock_serialize_document.assert_called_once_with(self.test_data, 'collection_name', mocked_acl_context)
mock_client.noop.assert_called_once_with([self.current_ts.time, self.current_ts.inc], {})
mock_client.upsert.assert_called_once_with([self.current_ts.time, self.current_ts.inc], self.test_data)
@pytest.mark.parametrize('exception_type', (TypeError, ValueError, AttributeError, KeyError))
......@@ -250,7 +252,7 @@ class TestMongoDBMirror:
@patch('mongodb_mirror.mirror.prometheus_client.Counter.inc')
async def test_initial_sync_fails(self, mock_counter_inc, mock_sort, mock_find, mock_get_newest_oplog_ts,
mock_namespace_to_db_collection, mock_serialize_document, exception_type):
mock_client = Mock(get_sync_init_point=AsyncMock(return_value=''))
mock_client = Mock(get_sync_init_point=AsyncMock(return_value=''), noop=AsyncMock(return_value=''))
mock_client.namespace = self.client_namespace
mock_client.handle_error = AsyncMock()
mock_get_newest_oplog_ts.return_value = self.current_ts
......@@ -261,6 +263,7 @@ class TestMongoDBMirror:
mock_serialize_document.side_effect = exception_type
await self.mongo_db_mirror._initial_sync(mock_client)
mock_counter_inc.assert_called_once()
mock_client.noop.assert_called_once_with([self.current_ts.time, self.current_ts.inc], {})
mock_client.handle_error.assert_called_once_with(
ts=[self.current_ts.time, self.current_ts.inc],
object_id=data_with_obj_id.get("_id"),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment