integration test fixups

This commit is contained in:
meejah 2018-04-22 01:07:22 -06:00
parent fbc142d346
commit 41e6ec0fff
2 changed files with 17 additions and 13 deletions

@ -176,11 +176,13 @@ def test_bob_creates_alice_deletes_bob_restores(magic_folder):
"bob wrote this"
)
# alice deletes it (so bob should as well
# alice deletes it (so bob should as well .. but keep a backup)
unlink(join(alice_dir, "boom"))
util.await_file_vanishes(join(bob_dir, "boom"))
assert exists(join(bob_dir, "boom.backup"))
# bob restore it, with new contents
unlink(join(bob_dir, "boom.backup"))
with open(join(bob_dir, "boom"), "w") as f:
f.write("bob wrote this again, because reasons")
@ -207,7 +209,7 @@ def test_bob_creates_alice_deletes_alice_restores(magic_folder):
"bob wrote this"
)
# alice deletes it (so bob should as well
# alice deletes it (so bob should as well)
unlink(join(alice_dir, "boom2"))
util.await_file_vanishes(join(bob_dir, "boom2"))
@ -215,6 +217,12 @@ def test_bob_creates_alice_deletes_alice_restores(magic_folder):
with open(join(alice_dir, "boom2"), "w") as f:
f.write("alice re-wrote this again, because reasons")
util.await_file_contents(
join(bob_dir, "boom2"),
"alice re-wrote this again, because reasons"
)
def test_bob_conflicts_with_alice_fresh(magic_folder):
# both alice and bob make a file at "the same time".
@ -270,22 +278,16 @@ def test_bob_conflicts_with_alice_preexisting(magic_folder):
join(bob_dir, 'beta.conflict'),
join(alice_dir, 'beta.conflict'),
]
found = util.await_files_exist(acceptable, await_all=True)
found = util.await_files_exist(acceptable)
assert len(found) == 2, "both should have gotten a conflict"
assert len(found) >= 1, "should have found at least one conflict"
assert open(join(bob_dir, 'beta'), 'r').read() == "this is bob's beta\n"
assert open(join(bob_dir, 'beta.conflict'), 'r').read() == "this is alice's beta\n"
assert open(join(alice_dir, 'beta'), 'r').read() == "this is alice's beta\n"
if exists(join(alice_dir, 'beta.conflict')):
assert open(join(alice_dir, 'beta.conflict'), 'r').read() == "this is bob's beta\n"
assert exists(acceptable[1])
assert open(join(alice_dir, 'beta'), 'r').read() == "this is alice's beta\n"
assert open(join(alice_dir, 'beta.conflict'), 'r').read() == "this is bob's beta\n"
assert open(join(bob_dir, 'beta'), 'r').read() == "this is bob's beta\n"
if exists(join(bob_dir, 'beta.conflict')):
assert open(join(bob_dir, 'beta.conflict'), 'r').read() == "this is alice's beta\n"
if exists(join(alice_dir, 'beta.conflict')):
assert open(join(alice_dir, 'beta.conflict'), 'r').read() == "this is bob's beta\n"
@pytest.inlineCallbacks

@ -257,7 +257,9 @@ def await_files_exist(paths, timeout=15, await_all=False):
if found:
return found
time.sleep(1)
raise Exception("Didn't find any of {} after {}s".format(', '.join(paths), timeout))
if await_all:
raise Exception("Didn't find {} after {}s".format(' and '.join(paths), timeout))
raise Exception("Didn't find {} after {}s".format(' or '.join(paths), timeout))
def await_file_vanishes(path, timeout=10):