|
3 | 3 | from ravendb.documents.operations.indexes import PutIndexesOperation |
4 | 4 | from ravendb.tests.test_base import TestBase |
5 | 5 | from ravendb.exceptions.exceptions import InvalidOperationException |
| 6 | +import datetime |
6 | 7 | import unittest |
7 | 8 | import pathlib |
8 | 9 | import os |
@@ -126,6 +127,74 @@ def test_try_delete_attachment_putted_in_the_same_session(self): |
126 | 127 | with self.assertRaises(InvalidOperationException): |
127 | 128 | session.advanced.attachments.delete("users/1-A", "my_text_file") |
128 | 129 |
|
| 130 | + def test_wait_for_replication_timeout_propagates(self): |
| 131 | + with self.store.open_session() as session: |
| 132 | + session.store(User("Idan", 30), "users/1-A") |
| 133 | + session.advanced.wait_for_replication_after_save_changes( |
| 134 | + lambda opts: opts.with_timeout(datetime.timedelta(seconds=5)) |
| 135 | + ) |
| 136 | + batch_options = session._save_changes_options |
| 137 | + self.assertIsNotNone(batch_options) |
| 138 | + self.assertIsNotNone(batch_options.replication_options) |
| 139 | + self.assertEqual(batch_options.replication_options.wait_for_replicas_timeout, datetime.timedelta(seconds=5)) |
| 140 | + |
| 141 | + def test_wait_for_indexes_throw_on_timeout_propagates(self): |
| 142 | + with self.store.open_session() as session: |
| 143 | + session.store(User("Idan", 30), "users/1-A") |
| 144 | + session.advanced.wait_for_indexes_after_save_changes(lambda opts: opts.throw_on_timeout(False)) |
| 145 | + batch_options = session._save_changes_options |
| 146 | + self.assertIsNotNone(batch_options) |
| 147 | + self.assertIsNotNone(batch_options.index_options) |
| 148 | + self.assertIs(batch_options.index_options.throw_on_timeout_in_wait_for_indexes, False) |
| 149 | + |
| 150 | + def test_wait_for_indexes_specific_indexes_propagates(self): |
| 151 | + with self.store.open_session() as session: |
| 152 | + session.store(User("Idan", 30), "users/1-A") |
| 153 | + session.advanced.wait_for_indexes_after_save_changes(lambda opts: opts.wait_for_indexes(["MyIndex"])) |
| 154 | + batch_options = session._save_changes_options |
| 155 | + self.assertIsNotNone(batch_options) |
| 156 | + self.assertIsNotNone(batch_options.index_options) |
| 157 | + self.assertIn("MyIndex", batch_options.index_options.wait_for_specific_indexes) |
| 158 | + |
| 159 | + |
| 160 | +class _FakeSession: |
| 161 | + def __init__(self): |
| 162 | + self._save_changes_options = None |
| 163 | + |
| 164 | + |
| 165 | +class TestWaitForOptions(unittest.TestCase): |
| 166 | + def test_replication_timeout_propagates(self): |
| 167 | + from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import ( |
| 168 | + InMemoryDocumentSessionOperations, |
| 169 | + ) |
| 170 | + |
| 171 | + session = _FakeSession() |
| 172 | + builder = InMemoryDocumentSessionOperations.ReplicationWaitOptsBuilder(session) |
| 173 | + builder.with_timeout(datetime.timedelta(seconds=5)) |
| 174 | + self.assertEqual( |
| 175 | + session._save_changes_options.replication_options.wait_for_replicas_timeout, datetime.timedelta(seconds=5) |
| 176 | + ) |
| 177 | + |
| 178 | + def test_indexes_throw_on_timeout_propagates(self): |
| 179 | + from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import ( |
| 180 | + InMemoryDocumentSessionOperations, |
| 181 | + ) |
| 182 | + |
| 183 | + session = _FakeSession() |
| 184 | + builder = InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder(session) |
| 185 | + builder.throw_on_timeout(False) |
| 186 | + self.assertIs(session._save_changes_options.index_options.throw_on_timeout_in_wait_for_indexes, False) |
| 187 | + |
| 188 | + def test_specific_indexes_propagates(self): |
| 189 | + from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import ( |
| 190 | + InMemoryDocumentSessionOperations, |
| 191 | + ) |
| 192 | + |
| 193 | + session = _FakeSession() |
| 194 | + builder = InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder(session) |
| 195 | + builder.wait_for_indexes(["MyIndex"]) |
| 196 | + self.assertIn("MyIndex", session._save_changes_options.index_options.wait_for_specific_indexes) |
| 197 | + |
129 | 198 |
|
130 | 199 | if __name__ == "__main__": |
131 | 200 | unittest.main() |
0 commit comments