From: Brett Smith Date: Tue, 27 May 2014 14:04:19 +0000 (-0400) Subject: 2752: arv-put saves and restores write progress information. X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/78722718f1369094e4cc9216f14c846c3b614e7d 2752: arv-put saves and restores write progress information. This will make output less confusing to the user, and help them understand that an upload is resuming. --- diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index 4568565d11..4398c5bca6 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -224,14 +224,17 @@ class ResumeCache(object): class ArvPutCollectionWriter(arvados.ResumableCollectionWriter): + STATE_PROPS = (arvados.ResumableCollectionWriter.STATE_PROPS + + ['bytes_written']) + def __init__(self, cache=None, reporter=None, bytes_expected=None): + self.bytes_written = 0 self.__init_locals__(cache, reporter, bytes_expected) super(ArvPutCollectionWriter, self).__init__() def __init_locals__(self, cache, reporter, bytes_expected): self.cache = cache self.report_func = reporter - self.bytes_written = 0 self.bytes_expected = bytes_expected @classmethod diff --git a/sdk/python/tests/test_arv-put.py b/sdk/python/tests/test_arv-put.py index a98eaa6a5e..cd0e9658eb 100644 --- a/sdk/python/tests/test_arv-put.py +++ b/sdk/python/tests/test_arv-put.py @@ -236,17 +236,36 @@ class ArvadosPutCollectionWriterTest(ArvadosKeepLocalStoreTestCase): self.cache) self.assertEquals(cwriter.manifest_text(), new_writer.manifest_text()) + def make_progress_tester(self): + progression = [] + def record_func(written, expected): + progression.append((written, expected)) + return progression, record_func + def test_progress_reporting(self): for expect_count in (None, 8): - progression = [] + progression, reporter = self.make_progress_tester() cwriter = arv_put.ArvPutCollectionWriter( - reporter=lambda *args: progression.append(args), - bytes_expected=expect_count) + reporter=reporter, bytes_expected=expect_count) with self.make_test_file() as testfile: cwriter.write_file(testfile.name, 'test') cwriter.finish_current_stream() self.assertIn((4, expect_count), progression) + def test_resume_progress(self): + cwriter = arv_put.ArvPutCollectionWriter(self.cache, bytes_expected=4) + with self.make_test_file() as testfile: + # Set up a writer with some flushed bytes. + cwriter.write_file(testfile.name, 'test') + cwriter.finish_current_stream() + cwriter.checkpoint_state() + # Restore a writer from that state and check its progress report. + progression, reporter = self.make_progress_tester() + new_writer = arv_put.ArvPutCollectionWriter.from_cache( + self.cache, reporter, bytes_expected=4) + new_writer.flush_data() + self.assertIn((4, 4), progression) + class ArvadosExpectedBytesTest(ArvadosBaseTestCase): TEST_SIZE = os.path.getsize(__file__)