|
18 | 18 | from datetime import datetime
|
19 | 19 | from ipaddress import ip_address
|
20 | 20 |
|
| 21 | +import pytest |
21 | 22 | from elasticsearch import ConflictError, NotFoundError
|
22 | 23 | from pytest import raises
|
23 | 24 | from pytz import timezone
|
@@ -234,6 +235,38 @@ def test_update_script(write_client):
|
234 | 235 | assert w.views == 47
|
235 | 236 |
|
236 | 237 |
|
| 238 | +def test_update_retry_on_conflict(write_client): |
| 239 | + Wiki.init() |
| 240 | + w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42) |
| 241 | + w.save() |
| 242 | + |
| 243 | + w1 = Wiki.get(id="elasticsearch-py") |
| 244 | + w2 = Wiki.get(id="elasticsearch-py") |
| 245 | + w1.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1) |
| 246 | + w2.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1) |
| 247 | + |
| 248 | + w = Wiki.get(id="elasticsearch-py") |
| 249 | + assert w.views == 52 |
| 250 | + |
| 251 | + |
| 252 | +@pytest.mark.parametrize("retry_on_conflict", [None, 0]) |
| 253 | +def test_update_conflicting_version(write_client, retry_on_conflict): |
| 254 | + Wiki.init() |
| 255 | + w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42) |
| 256 | + w.save() |
| 257 | + |
| 258 | + w1 = Wiki.get(id="elasticsearch-py") |
| 259 | + w2 = Wiki.get(id="elasticsearch-py") |
| 260 | + w1.update(script="ctx._source.views += params.inc", inc=5) |
| 261 | + |
| 262 | + with raises(ConflictError): |
| 263 | + w2.update( |
| 264 | + script="ctx._source.views += params.inc", |
| 265 | + inc=5, |
| 266 | + retry_on_conflict=retry_on_conflict, |
| 267 | + ) |
| 268 | + |
| 269 | + |
237 | 270 | def test_save_and_update_return_doc_meta(write_client):
|
238 | 271 | Wiki.init()
|
239 | 272 | w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42)
|
|
0 commit comments