File: test_sync.py

package info (click to toggle)
vdirsyncer 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 944 kB
  • sloc: python: 7,380; makefile: 205; sh: 66
file content (747 lines) | stat: -rw-r--r-- 20,999 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
from __future__ import annotations

import asyncio
import contextlib
from copy import deepcopy

import aiostream
import hypothesis.strategies as st
import pytest
from hypothesis import assume
from hypothesis.stateful import Bundle
from hypothesis.stateful import RuleBasedStateMachine
from hypothesis.stateful import rule

from tests import blow_up
from tests import uid_strategy
from vdirsyncer.storage.memory import MemoryStorage
from vdirsyncer.storage.memory import _random_string
from vdirsyncer.sync import sync as _sync
from vdirsyncer.sync.exceptions import BothReadOnly
from vdirsyncer.sync.exceptions import IdentConflict
from vdirsyncer.sync.exceptions import PartialSync
from vdirsyncer.sync.exceptions import StorageEmpty
from vdirsyncer.sync.exceptions import SyncConflict
from vdirsyncer.sync.status import SqliteStatus
from vdirsyncer.vobject import Item


async def sync(a, b, status, *args, **kwargs) -> None:
    with contextlib.closing(SqliteStatus(":memory:")) as new_status:
        new_status.load_legacy_status(status)
        await _sync(a, b, new_status, *args, **kwargs)
        status.clear()
        status.update(new_status.to_legacy_status())


def empty_storage(x):
    return list(x.list()) == []


def items(s):
    return {x[1].raw for x in s.items.values()}


@pytest.mark.asyncio
async def test_irrelevant_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {"1": ("1", 1234, "1.ics", 2345)}
    await sync(a, b, status)
    assert not status
    assert not items(a)
    assert not items(b)


@pytest.mark.asyncio
async def test_missing_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    item = Item("asdf")
    await a.upload(item)
    await b.upload(item)
    await sync(a, b, status)
    assert len(status) == 1
    assert items(a) == items(b) == {item.raw}


@pytest.mark.asyncio
async def test_missing_status_and_different_items():
    a = MemoryStorage()
    b = MemoryStorage()

    status = {}
    item1 = Item("UID:1\nhaha")
    item2 = Item("UID:1\nhoho")
    await a.upload(item1)
    await b.upload(item2)
    with pytest.raises(SyncConflict):
        await sync(a, b, status)
    assert not status
    await sync(a, b, status, conflict_resolution="a wins")
    assert items(a) == items(b) == {item1.raw}


@pytest.mark.asyncio
async def test_read_only_and_prefetch():
    a = MemoryStorage()
    b = MemoryStorage()
    b.read_only = True

    status = {}
    item1 = Item("UID:1\nhaha")
    item2 = Item("UID:2\nhoho")
    await a.upload(item1)
    await a.upload(item2)

    await sync(a, b, status, force_delete=True)
    await sync(a, b, status, force_delete=True)

    assert not items(a) and not items(b)


@pytest.mark.asyncio
async def test_partial_sync_error():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    await a.upload(Item("UID:0"))
    b.read_only = True

    with pytest.raises(PartialSync):
        await sync(a, b, status, partial_sync="error")


@pytest.mark.asyncio
async def test_partial_sync_ignore():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    item0 = Item("UID:0\nhehe")
    await a.upload(item0)
    await b.upload(item0)

    b.read_only = True

    item1 = Item("UID:1\nhaha")
    await a.upload(item1)

    await sync(a, b, status, partial_sync="ignore")
    await sync(a, b, status, partial_sync="ignore")

    assert items(a) == {item0.raw, item1.raw}
    assert items(b) == {item0.raw}


@pytest.mark.asyncio
async def test_partial_sync_ignore2():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    href, etag = await a.upload(Item("UID:0"))
    a.read_only = True

    await sync(a, b, status, partial_sync="ignore", force_delete=True)
    assert items(b) == items(a) == {"UID:0"}

    b.items.clear()
    await sync(a, b, status, partial_sync="ignore", force_delete=True)
    await sync(a, b, status, partial_sync="ignore", force_delete=True)
    assert items(a) == {"UID:0"}
    assert not b.items

    a.read_only = False
    await a.update(href, Item("UID:0\nupdated"), etag)
    a.read_only = True
    await sync(a, b, status, partial_sync="ignore", force_delete=True)
    assert items(b) == items(a) == {"UID:0\nupdated"}


@pytest.mark.asyncio
async def test_upload_and_update():
    a = MemoryStorage(fileext=".a")
    b = MemoryStorage(fileext=".b")
    status = {}

    item = Item("UID:1")  # new item 1 in a
    await a.upload(item)
    await sync(a, b, status)
    assert items(b) == items(a) == {item.raw}

    item = Item("UID:1\nASDF:YES")  # update of item 1 in b
    await b.update("1.b", item, (await b.get("1.b"))[1])
    await sync(a, b, status)
    assert items(b) == items(a) == {item.raw}

    item2 = Item("UID:2")  # new item 2 in b
    await b.upload(item2)
    await sync(a, b, status)
    assert items(b) == items(a) == {item.raw, item2.raw}

    item2 = Item("UID:2\nASDF:YES")  # update of item 2 in a
    await a.update("2.a", item2, (await a.get("2.a"))[1])
    await sync(a, b, status)
    assert items(b) == items(a) == {item.raw, item2.raw}


@pytest.mark.asyncio
async def test_deletion():
    a = MemoryStorage(fileext=".a")
    b = MemoryStorage(fileext=".b")
    status = {}

    item = Item("UID:1")
    await a.upload(item)
    item2 = Item("UID:2")
    await a.upload(item2)
    await sync(a, b, status)
    await b.delete("1.b", (await b.get("1.b"))[1])
    await sync(a, b, status)
    assert items(a) == items(b) == {item2.raw}

    await a.upload(item)
    await sync(a, b, status)
    assert items(a) == items(b) == {item.raw, item2.raw}
    await a.delete("1.a", (await a.get("1.a"))[1])
    await sync(a, b, status)
    assert items(a) == items(b) == {item2.raw}


@pytest.mark.asyncio
async def test_insert_hash():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    item = Item("UID:1")
    href, etag = await a.upload(item)
    await sync(a, b, status)

    for d in status["1"]:
        del d["hash"]

    await a.update(href, Item("UID:1\nHAHA:YES"), etag)
    await sync(a, b, status)
    assert "hash" in status["1"][0] and "hash" in status["1"][1]


@pytest.mark.asyncio
async def test_already_synced():
    a = MemoryStorage(fileext=".a")
    b = MemoryStorage(fileext=".b")
    item = Item("UID:1")
    await a.upload(item)
    await b.upload(item)
    status = {
        "1": (
            {"href": "1.a", "hash": item.hash, "etag": (await a.get("1.a"))[1]},
            {"href": "1.b", "hash": item.hash, "etag": (await b.get("1.b"))[1]},
        )
    }
    old_status = deepcopy(status)
    a.update = b.update = a.upload = b.upload = lambda *a, **kw: pytest.fail(
        "Method shouldn't have been called."
    )

    for _ in (1, 2):
        await sync(a, b, status)
        assert status == old_status
        assert items(a) == items(b) == {item.raw}


@pytest.mark.parametrize("winning_storage", "ab")
@pytest.mark.asyncio
async def test_conflict_resolution_both_etags_new(winning_storage):
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item("UID:1")
    href_a, etag_a = await a.upload(item)
    href_b, etag_b = await b.upload(item)
    status = {}
    await sync(a, b, status)
    assert status
    item_a = Item("UID:1\nitem a")
    item_b = Item("UID:1\nitem b")
    await a.update(href_a, item_a, etag_a)
    await b.update(href_b, item_b, etag_b)
    with pytest.raises(SyncConflict):
        await sync(a, b, status)
    await sync(a, b, status, conflict_resolution=f"{winning_storage} wins")
    assert (
        items(a) == items(b) == {item_a.raw if winning_storage == "a" else item_b.raw}
    )


@pytest.mark.asyncio
async def test_updated_and_deleted():
    a = MemoryStorage()
    b = MemoryStorage()
    href_a, etag_a = await a.upload(Item("UID:1"))
    status = {}
    await sync(a, b, status, force_delete=True)

    ((href_b, etag_b),) = await aiostream.stream.list(b.list())
    await b.delete(href_b, etag_b)
    updated = Item("UID:1\nupdated")
    await a.update(href_a, updated, etag_a)
    await sync(a, b, status, force_delete=True)

    assert items(a) == items(b) == {updated.raw}


@pytest.mark.asyncio
async def test_conflict_resolution_invalid_mode():
    a = MemoryStorage()
    b = MemoryStorage()
    item_a = Item("UID:1\nitem a")
    item_b = Item("UID:1\nitem b")
    await a.upload(item_a)
    await b.upload(item_b)
    with pytest.raises(ValueError):
        await sync(a, b, {}, conflict_resolution="yolo")


@pytest.mark.asyncio
async def test_conflict_resolution_new_etags_without_changes():
    a = MemoryStorage()
    b = MemoryStorage()
    item = Item("UID:1")
    href_a, etag_a = await a.upload(item)
    href_b, etag_b = await b.upload(item)
    status = {"1": (href_a, "BOGUS_a", href_b, "BOGUS_b")}

    await sync(a, b, status)

    ((ident, (status_a, status_b)),) = status.items()
    assert ident == "1"
    assert status_a["href"] == href_a
    assert status_a["etag"] == etag_a
    assert status_b["href"] == href_b
    assert status_b["etag"] == etag_b


@pytest.mark.asyncio
async def test_uses_get_multi(monkeypatch):
    def breakdown(*a, **kw):
        raise AssertionError("Expected use of get_multi")

    get_multi_calls = []

    old_get = MemoryStorage.get

    async def get_multi(self, hrefs):
        hrefs = list(hrefs)
        get_multi_calls.append(hrefs)
        for href in hrefs:
            item, etag = await old_get(self, href)
            yield href, item, etag

    monkeypatch.setattr(MemoryStorage, "get", breakdown)
    monkeypatch.setattr(MemoryStorage, "get_multi", get_multi)

    a = MemoryStorage()
    b = MemoryStorage()
    item = Item("UID:1")
    expected_href, etag = await a.upload(item)

    await sync(a, b, {})
    assert get_multi_calls == [[expected_href]]


@pytest.mark.asyncio
async def test_empty_storage_dataloss():
    a = MemoryStorage()
    b = MemoryStorage()
    await a.upload(Item("UID:1"))
    await a.upload(Item("UID:2"))
    status = {}
    await sync(a, b, status)
    with pytest.raises(StorageEmpty):
        await sync(MemoryStorage(), b, status)

    with pytest.raises(StorageEmpty):
        await sync(a, MemoryStorage(), status)


@pytest.mark.asyncio
async def test_no_uids():
    a = MemoryStorage()
    b = MemoryStorage()
    await a.upload(Item("ASDF"))
    await b.upload(Item("FOOBAR"))
    status = {}
    await sync(a, b, status)
    assert items(a) == items(b) == {"ASDF", "FOOBAR"}


@pytest.mark.asyncio
async def test_changed_uids():
    a = MemoryStorage()
    b = MemoryStorage()
    href_a, etag_a = await a.upload(Item("UID:A-ONE"))
    href_b, etag_b = await b.upload(Item("UID:B-ONE"))
    status = {}
    await sync(a, b, status)

    await a.update(href_a, Item("UID:A-TWO"), etag_a)
    await sync(a, b, status)


@pytest.mark.asyncio
async def test_both_readonly():
    a = MemoryStorage(read_only=True)
    b = MemoryStorage(read_only=True)
    assert a.read_only
    assert b.read_only
    status = {}
    with pytest.raises(BothReadOnly):
        await sync(a, b, status)


@pytest.mark.asyncio
async def test_partial_sync_revert():
    a = MemoryStorage(instance_name="a")
    b = MemoryStorage(instance_name="b")
    status = {}
    await a.upload(Item("UID:1"))
    await b.upload(Item("UID:2"))
    b.read_only = True

    await sync(a, b, status, partial_sync="revert")
    assert len(status) == 2
    assert items(a) == {"UID:1", "UID:2"}
    assert items(b) == {"UID:2"}

    await sync(a, b, status, partial_sync="revert")
    assert len(status) == 1
    assert items(a) == {"UID:2"}
    assert items(b) == {"UID:2"}

    # Check that updates get reverted
    a.items[next(iter(a.items))] = ("foo", Item("UID:2\nupdated"))
    assert items(a) == {"UID:2\nupdated"}
    await sync(a, b, status, partial_sync="revert")
    assert len(status) == 1
    assert items(a) == {"UID:2\nupdated"}
    await sync(a, b, status, partial_sync="revert")
    assert items(a) == {"UID:2"}

    # Check that deletions get reverted
    a.items.clear()
    await sync(a, b, status, partial_sync="revert", force_delete=True)
    await sync(a, b, status, partial_sync="revert", force_delete=True)
    assert items(a) == {"UID:2"}


@pytest.mark.parametrize("sync_inbetween", (True, False))
@pytest.mark.asyncio
async def test_ident_conflict(sync_inbetween):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    href_a, etag_a = await a.upload(Item("UID:aaa"))
    href_b, etag_b = await a.upload(Item("UID:bbb"))
    if sync_inbetween:
        await sync(a, b, status)

    await a.update(href_a, Item("UID:xxx"), etag_a)
    await a.update(href_b, Item("UID:xxx"), etag_b)

    with pytest.raises(IdentConflict):
        await sync(a, b, status)


@pytest.mark.asyncio
async def test_moved_href():
    """
    Concrete application: ppl_ stores contact aliases in filenames, which means
    item's hrefs get changed. Vdirsyncer doesn't synchronize this data, but
    also shouldn't do things like deleting and re-uploading to the server.

    .. _ppl: http://ppladdressbook.org/
    """
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    href, etag = await a.upload(Item("UID:haha"))
    await sync(a, b, status)

    b.items["lol"] = b.items.pop("haha")

    # The sync algorithm should prefetch `lol`, see that it's the same ident
    # and not do anything else.
    a.get_multi = blow_up  # Absolutely no prefetch on A
    # No actual sync actions
    a.delete = a.update = a.upload = b.delete = b.update = b.upload = blow_up

    await sync(a, b, status)
    assert len(status) == 1
    assert items(a) == items(b) == {"UID:haha"}
    assert status["haha"][1]["href"] == "lol"
    old_status = deepcopy(status)

    # Further sync should be a noop. Not even prefetching should occur.
    b.get_multi = blow_up

    await sync(a, b, status)
    assert old_status == status
    assert items(a) == items(b) == {"UID:haha"}


@pytest.mark.asyncio
async def test_bogus_etag_change():
    """Assert that sync algorithm is resilient against etag changes if content
    didn\'t change.

    In this particular case we test a scenario where both etags have been
    updated, but only one side actually changed its item content.
    """
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    href_a, etag_a = await a.upload(Item("UID:ASDASD"))
    await sync(a, b, status)
    assert (
        len(status)
        == len(await aiostream.stream.list(a.list()))
        == len(await aiostream.stream.list(b.list()))
        == 1
    )

    ((href_b, etag_b),) = await aiostream.stream.list(b.list())
    await a.update(href_a, Item("UID:ASDASD"), etag_a)
    await b.update(href_b, Item("UID:ASDASD\nACTUALCHANGE:YES"), etag_b)

    b.delete = b.update = b.upload = blow_up

    await sync(a, b, status)
    assert len(status) == 1
    assert items(a) == items(b) == {"UID:ASDASD\nACTUALCHANGE:YES"}


@pytest.mark.asyncio
async def test_unicode_hrefs():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    href, etag = await a.upload(Item("UID:รครครค"))
    await sync(a, b, status)


class ActionIntentionallyFailed(Exception):
    pass


def action_failure(*a, **kw):
    raise ActionIntentionallyFailed


class SyncMachine(RuleBasedStateMachine):
    Status = Bundle("status")
    Storage = Bundle("storage")

    @rule(target=Storage, flaky_etags=st.booleans(), null_etag_on_upload=st.booleans())
    @pytest.mark.asyncio
    def newstorage(self, flaky_etags, null_etag_on_upload):
        s = MemoryStorage()
        if flaky_etags:

            async def get(href):
                old_etag, item = s.items[href]
                etag = _random_string()
                s.items[href] = etag, item
                return item, etag

            s.get = get

        if null_etag_on_upload:
            _old_upload = s.upload
            _old_update = s.update

            async def upload(item):
                return (await _old_upload(item))[0], "NULL"

            async def update(href, item, etag):
                return await _old_update(href, item, etag) and "NULL"

            s.upload = upload
            s.update = update

        return s

    @rule(s=Storage, read_only=st.booleans())
    def is_read_only(self, s, read_only):
        assume(s.read_only != read_only)
        s.read_only = read_only

    @rule(s=Storage)
    def actions_fail(self, s):
        s.upload = action_failure
        s.update = action_failure
        s.delete = action_failure

    @rule(s=Storage)
    def none_as_etag(self, s):
        _old_upload = s.upload
        _old_update = s.update

        async def upload(item):
            return (await _old_upload(item))[0], None

        async def update(href, item, etag):
            return await _old_update(href, item, etag)

        s.upload = upload
        s.update = update

    @rule(target=Status)
    def newstatus(self):
        return {}

    @rule(storage=Storage, uid=uid_strategy, etag=st.text())
    def upload(self, storage, uid, etag):
        item = Item(f"UID:{uid}")
        storage.items[uid] = (etag, item)

    @rule(storage=Storage, href=st.text())
    def delete(self, storage, href):
        assume(storage.items.pop(href, None))

    @rule(
        status=Status,
        a=Storage,
        b=Storage,
        force_delete=st.booleans(),
        conflict_resolution=st.one_of((st.just("a wins"), st.just("b wins"))),
        with_error_callback=st.booleans(),
        partial_sync=st.one_of(
            (st.just("ignore"), st.just("revert"), st.just("error"))
        ),
    )
    def sync(
        self,
        status,
        a,
        b,
        force_delete,
        conflict_resolution,
        with_error_callback,
        partial_sync,
    ):
        async def inner():
            assume(a is not b)
            old_items_a = items(a)
            old_items_b = items(b)

            a.instance_name = "a"
            b.instance_name = "b"

            errors = []

            if with_error_callback:
                error_callback = errors.append
            else:
                error_callback = None

            try:
                # If one storage is read-only, double-sync because changes don't
                # get reverted immediately.
                for _ in range(2 if a.read_only or b.read_only else 1):
                    await sync(
                        a,
                        b,
                        status,
                        force_delete=force_delete,
                        conflict_resolution=conflict_resolution,
                        error_callback=error_callback,
                        partial_sync=partial_sync,
                    )

                for e in errors:
                    raise e
            except PartialSync:
                assert partial_sync == "error"
            except ActionIntentionallyFailed:
                pass
            except BothReadOnly:
                assert a.read_only and b.read_only
                assume(False)
            except StorageEmpty:
                if force_delete:
                    raise
                else:
                    not_a = not await aiostream.stream.list(a.list())
                    not_b = not await aiostream.stream.list(b.list())
                    assert not_a or not_b
            else:
                items_a = items(a)
                items_b = items(b)

                assert items_a == items_b or partial_sync == "ignore"
                assert items_a == old_items_a or not a.read_only
                assert items_b == old_items_b or not b.read_only

                assert (
                    set(a.items) | set(b.items) == set(status)
                    or partial_sync == "ignore"
                )

        asyncio.run(inner())


TestSyncMachine = SyncMachine.TestCase


@pytest.mark.parametrize("error_callback", [True, False])
@pytest.mark.asyncio
async def test_rollback(error_callback):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.items["0"] = ("", Item("UID:0"))
    b.items["1"] = ("", Item("UID:1"))

    b.upload = b.update = b.delete = action_failure

    if error_callback:
        errors = []

        await sync(
            a,
            b,
            status=status,
            conflict_resolution="a wins",
            error_callback=errors.append,
        )

        assert len(errors) == 1
        assert isinstance(errors[0], ActionIntentionallyFailed)

        assert len(status) == 1
        assert status["1"]
    else:
        with pytest.raises(ActionIntentionallyFailed):
            await sync(a, b, status=status, conflict_resolution="a wins")


@pytest.mark.asyncio
async def test_duplicate_hrefs():
    a = MemoryStorage()
    b = MemoryStorage()

    async def fake_list():
        for item in [("a", "a")] * 3:
            yield item

    a.list = fake_list
    a.items["a"] = ("a", Item("UID:a"))

    status = {}
    await sync(a, b, status)
    with pytest.raises(AssertionError):
        await sync(a, b, status)