Send a started response after each dest file is registered
This commit is contained in:
parent
af5c0b3b71
commit
745e97e0ab
@ -58,7 +58,7 @@ class TransmissionType(NameReprEnum):
|
|||||||
rsync = auto()
|
rsync = auto()
|
||||||
|
|
||||||
|
|
||||||
ErrorCode = Enum('ErrorCode', 'OK EINVAL EPERM EISDIR')
|
ErrorCode = Enum('ErrorCode', 'OK STARTED EINVAL EPERM EISDIR')
|
||||||
|
|
||||||
|
|
||||||
class TransmissionError(Exception):
|
class TransmissionError(Exception):
|
||||||
@ -437,6 +437,9 @@ class FileTransmission:
|
|||||||
self.send_fail_on_os_error(err, 'Failed to create directory', ar, df.file_id)
|
self.send_fail_on_os_error(err, 'Failed to create directory', ar, df.file_id)
|
||||||
else:
|
else:
|
||||||
self.send_status_response(ErrorCode.OK, ar.id, df.file_id, name=df.name)
|
self.send_status_response(ErrorCode.OK, ar.id, df.file_id, name=df.name)
|
||||||
|
else:
|
||||||
|
if ar.send_acknowledgements:
|
||||||
|
self.send_status_response(code=ErrorCode.STARTED, request_id=ar.id, file_id=df.file_id, name=df.name)
|
||||||
elif cmd.action in (Action.data, Action.end_data):
|
elif cmd.action in (Action.data, Action.end_data):
|
||||||
try:
|
try:
|
||||||
df = ar.add_data(cmd)
|
df = ar.add_data(cmd)
|
||||||
|
|||||||
@ -92,14 +92,15 @@ class TestFileTransmission(BaseTest):
|
|||||||
dest = os.path.join(self.tdir, '1.bin')
|
dest = os.path.join(self.tdir, '1.bin')
|
||||||
ft.handle_serialized_command(serialized_cmd(action='send', quiet=quiet))
|
ft.handle_serialized_command(serialized_cmd(action='send', quiet=quiet))
|
||||||
self.assertIn('', ft.active_receives)
|
self.assertIn('', ft.active_receives)
|
||||||
|
self.ae(ft.test_responses, [] if quiet else [response(status='OK')])
|
||||||
ft.handle_serialized_command(serialized_cmd(action='file', name=dest, quiet=quiet))
|
ft.handle_serialized_command(serialized_cmd(action='file', name=dest, quiet=quiet))
|
||||||
self.assertPathEqual(ft.active_file().name, dest)
|
self.assertPathEqual(ft.active_file().name, dest)
|
||||||
self.assertIsNone(ft.active_file().actual_file)
|
self.assertIsNone(ft.active_file().actual_file)
|
||||||
self.ae(ft.test_responses, [] if quiet else [response(status='OK')])
|
self.ae(ft.test_responses, [] if quiet else [response(status='OK'), response(status='STARTED', name=dest)])
|
||||||
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
||||||
self.assertPathEqual(ft.active_file().actual_file.name, dest)
|
self.assertPathEqual(ft.active_file().actual_file.name, dest)
|
||||||
ft.handle_serialized_command(serialized_cmd(action='end_data', data='123'))
|
ft.handle_serialized_command(serialized_cmd(action='end_data', data='123'))
|
||||||
self.ae(ft.test_responses, [] if quiet else [response(status='OK'), response(status='OK', name=dest)])
|
self.ae(ft.test_responses, [] if quiet else [response(status='OK'), response(status='STARTED', name=dest), response(status='OK', name=dest)])
|
||||||
self.assertTrue(ft.active_receives)
|
self.assertTrue(ft.active_receives)
|
||||||
ft.handle_serialized_command(serialized_cmd(action='finish'))
|
ft.handle_serialized_command(serialized_cmd(action='finish'))
|
||||||
self.assertFalse(ft.active_receives)
|
self.assertFalse(ft.active_receives)
|
||||||
@ -115,7 +116,7 @@ class TestFileTransmission(BaseTest):
|
|||||||
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
||||||
self.assertTrue(os.path.exists(dest))
|
self.assertTrue(os.path.exists(dest))
|
||||||
ft.handle_serialized_command(serialized_cmd(action='cancel'))
|
ft.handle_serialized_command(serialized_cmd(action='cancel'))
|
||||||
self.ae(ft.test_responses, [response(status='OK')])
|
self.ae(ft.test_responses, [response(status='OK'), response(status='STARTED', name=dest)])
|
||||||
self.assertFalse(ft.active_receives)
|
self.assertFalse(ft.active_receives)
|
||||||
# compress with zlib
|
# compress with zlib
|
||||||
ft = FileTransmission()
|
ft = FileTransmission()
|
||||||
@ -129,7 +130,7 @@ class TestFileTransmission(BaseTest):
|
|||||||
ft.handle_serialized_command(serialized_cmd(action='data', data=data[:len(data)//2]))
|
ft.handle_serialized_command(serialized_cmd(action='data', data=data[:len(data)//2]))
|
||||||
self.assertTrue(os.path.exists(dest))
|
self.assertTrue(os.path.exists(dest))
|
||||||
ft.handle_serialized_command(serialized_cmd(action='end_data', data=data[len(data)//2:]))
|
ft.handle_serialized_command(serialized_cmd(action='end_data', data=data[len(data)//2:]))
|
||||||
self.ae(ft.test_responses, [response(status='OK'), response(status='OK', name=dest)])
|
self.ae(ft.test_responses, [response(status='OK'), response(status='STARTED', name=dest), response(status='OK', name=dest)])
|
||||||
ft.handle_serialized_command(serialized_cmd(action='finish'))
|
ft.handle_serialized_command(serialized_cmd(action='finish'))
|
||||||
with open(dest, 'rb') as f:
|
with open(dest, 'rb') as f:
|
||||||
self.ae(f.read(), odata)
|
self.ae(f.read(), odata)
|
||||||
@ -151,6 +152,7 @@ class TestFileTransmission(BaseTest):
|
|||||||
kw['file_id'] = str(fid)
|
kw['file_id'] = str(fid)
|
||||||
kw['name'] = name
|
kw['name'] = name
|
||||||
ft.handle_serialized_command(serialized_cmd(**kw))
|
ft.handle_serialized_command(serialized_cmd(**kw))
|
||||||
|
self.assertResponses(ft, status='OK' if not data else 'STARTED', name=name, file_id=str(fid))
|
||||||
if data:
|
if data:
|
||||||
ft.handle_serialized_command(serialized_cmd(action='end_data', file_id=str(fid), data=data))
|
ft.handle_serialized_command(serialized_cmd(action='end_data', file_id=str(fid), data=data))
|
||||||
self.assertResponses(ft, status='OK', name=name, file_id=str(fid))
|
self.assertResponses(ft, status='OK', name=name, file_id=str(fid))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user