def finalize(self): # When serving a cached initial payload we should still generate a new sync log # This is to avoid issues with multiple devices ending up syncing to the same # sync log, which causes all kinds of assertion errors when the two devices # touch the same cases if self and self.is_initial: try: file_reference = copy_payload_and_synclog_and_get_new_file(self.payload) self.payload = file_reference.file self.payload_path = file_reference.path except Exception, e: # don't fail hard if anything goes wrong since this is an edge case optimization soft_assert(to=['czue' + '@' + 'dimagi.com'])(False, u'Error finalizing cached log: {}'.format(e))
def test_copy_payload(self): sync_log = SimplifiedSyncLog(case_ids_on_phone=set(["case-1", "case-2"])) sync_log.save() payload = dummy_restore_xml(sync_log._id).strip() fd, path = tempfile.mkstemp() with os.fdopen(fd, "wb") as f: f.write(payload) with open(path, "r") as f: updated_fileref = copy_payload_and_synclog_and_get_new_file(f) updated_payload = updated_fileref.file.read() updated_id = synclog_id_from_restore_payload(updated_payload) self.assertNotEqual(sync_log._id, updated_id) self.assertTrue(_restore_id_block(updated_id) in updated_payload) self.assertFalse(sync_log._id in updated_payload) updated_log = get_properly_wrapped_sync_log(updated_id) self.assertEqual(updated_log.case_ids_on_phone, sync_log.case_ids_on_phone)
def test_copy_payload(self): sync_log = SimplifiedSyncLog(case_ids_on_phone=set(['case-1', 'case-2'])) sync_log.save() payload = dummy_restore_xml(sync_log._id).strip() fd, path = tempfile.mkstemp() with os.fdopen(fd, 'wb') as f: f.write(payload) with open(path, 'r') as f: updated_fileref = copy_payload_and_synclog_and_get_new_file(f) updated_payload = updated_fileref.file.read() updated_id = synclog_id_from_restore_payload(updated_payload) self.assertNotEqual(sync_log._id, updated_id) self.assertTrue(_restore_id_block(updated_id) in updated_payload) self.assertFalse(sync_log._id in updated_payload) updated_log = get_properly_wrapped_sync_log(updated_id) self.assertEqual(updated_log.case_ids_on_phone, sync_log.case_ids_on_phone)