Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync monitor issue when switching between reader and contributor role #1391

Closed
vxgmichel opened this issue Aug 24, 2020 · 0 comments
Closed
Assignees
Projects

Comments

@vxgmichel
Copy link
Contributor

The following scenario fails:

diff --git a/tests/core/test_sync_monitor_stateful.py b/tests/core/test_sync_monitor_stateful.py
index fd29007f..b600ac1e 100644
--- a/tests/core/test_sync_monitor_stateful.py
+++ b/tests/core/test_sync_monitor_stateful.py
@@ -187,6 +187,7 @@ def test_sync_monitor_stateful(
                 await wfs.touch(file_path)
             else:
                 data = self.get_next_data()
+                assert await wfs.exists(file_path)
                 await wfs.write_bytes(file_path, data)
             await wfs.sync()
 
@@ -203,8 +204,8 @@ def test_sync_monitor_stateful(
             else:
                 data = self.get_next_data()
                 try:
-                    if await wfs.exists(file_path):
-                        await wfs.write_bytes(file_path, data)
+                    assert await wfs.exists(file_path)
+                    await wfs.write_bytes(file_path, data)
                 except (FSWorkspaceNoAccess, OSError):
                     return
 
@@ -247,4 +248,19 @@ def test_sync_monitor_stateful(
             self.synced_files.update(new_synced_files)
             return multiple(*(sorted(new_synced_files)))
 
-    run_state_machine_as_test(SyncMonitorStateful, settings=hypothesis_settings)
+    from parsec.api.protocol import RealmRole
+    state = SyncMonitorStateful()
+
+    async def steps():
+        await state.init()
+        v1 = await state.create_sharing(RealmRole.CONTRIBUTOR)
+        await state.create_file(author=bob.device_id, wid=v1)
+        v2 = await state.let_core_monitors_process_changes()
+        await state.update_file(author=alice.device_id, file=v2.values[0])
+        await state.update_sharing(new_role=RealmRole.READER, wid=v1)
+        await state.update_sharing(new_role=RealmRole.CONTRIBUTOR, wid=v1)
+        await state.let_core_monitors_process_changes()
+        await state.teardown()
+    state.trio_run(steps)
+
+    # run_state_machine_as_test(SyncMonitorStateful, settings=hypothesis_settings)

Trace:

../../miniconda/envs/parsec/lib/python3.7/site-packages/hypothesis_trio/stateful.py:293: in _trio_main_afn
    await corofn(*args)
tests/core/test_sync_monitor_stateful.py:262: in steps
    await state.let_core_monitors_process_changes()
tests/core/test_sync_monitor_stateful.py:241: in let_core_monitors_process_changes
    recursive_compare_fs_dumps(alice_dump, bob_dump, ignore_need_sync=False)
tests/core/test_sync_monitor_stateful.py:46: in recursive_compare_fs_dumps
    recursive_compare_fs_dumps(alice_value, bob_value, ignore_need_sync=ignore_need_sync)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

alice_dump = {'base_version': 1, 'blocks': [[{'access': None, 'id': ChunkID('33fe6913-38ed-4394-af68-a0a31582b898'), 'raw_offset': 0, 'raw_size': 6, ...}]], 'blocksize': 524288, 'created': <Pendulum [2020-08-24T09:55:15.367170+00:00]>, ...}
bob_dump = {'base_version': 1, 'blocks': [], 'blocksize': 524288, 'created': <Pendulum [2020-08-24T09:55:15.367170+00:00]>, ...}
ignore_need_sync = False

    def recursive_compare_fs_dumps(alice_dump, bob_dump, ignore_need_sync=False):
        if ignore_need_sync and alice_dump.get("need_sync", False):
            return
    
        alice_stripped_dump = {}
        bob_stripped_dump = {}
        for field in TO_COMPARE_FIELDS:
            alice_value = alice_dump.get(field, MISSING)
            bob_value = bob_dump.get(field, MISSING)
            if alice_value is not MISSING and bob_value is not MISSING:
                alice_stripped_dump[field] = alice_value
                bob_stripped_dump[field] = bob_value
>       assert alice_stripped_dump == bob_stripped_dump
E       AssertionError: assert {'base_versio...': False, ...} == {'base_versio...': False, ...}
E         Omitting 4 identical items, use -vv to show
E         Differing items:
E         {'need_sync': True} != {'need_sync': False}
E         {'updated': <Pendulum [2020-08-24T09:55:15.488858+00:00]>} != {'updated': <Pendulum [2020-08-24T09:55:15.367170+00:00]>}
E         Use -v to get the full diff

tests/core/test_sync_monitor_stateful.py:38: AssertionError
@stefan-contiu stefan-contiu added this to New comers in Dev Board Aug 26, 2020
@touilleMan touilleMan moved this from New comers to Doing in Dev Board Aug 26, 2020
vxgmichel added a commit that referenced this issue Sep 9, 2020
…ction

Re-raising a caught exception is bad practice is its internal state
gets mutated everytime it is raised (see issue #1391)
@vxgmichel vxgmichel moved this from Doing to Done in Dev Board Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Dev Board
To review
Development

No branches or pull requests

1 participant