From 7d365353409e791e88303cd7d761102da84e7559 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 6 Aug 2024 16:57:22 -0400 Subject: [PATCH 1/2] Updated non-streaming upload progress to report 1.0 if nothing to upload --- src/realm/object-store/sync/sync_session.cpp | 11 +++++++---- .../sync/session/progress_notifications.cpp | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/realm/object-store/sync/sync_session.cpp b/src/realm/object-store/sync/sync_session.cpp index 2cf2489e55..2ae5fc3a9f 100644 --- a/src/realm/object-store/sync/sync_session.cpp +++ b/src/realm/object-store/sync/sync_session.cpp @@ -1585,7 +1585,7 @@ void SyncProgressNotifier::set_local_version(uint64_t snapshot_version) util::UniqueFunction SyncProgressNotifier::NotifierPackage::create_invocation(Progress const& current_progress, bool& is_expired) { - uint64_t transfered = is_download ? current_progress.downloaded : current_progress.uploaded; + uint64_t transferred = is_download ? current_progress.downloaded : current_progress.uploaded; uint64_t transferable = is_download ? current_progress.downloadable : current_progress.uploadable; double estimate = is_download ? current_progress.download_estimate : current_progress.upload_estimate; @@ -1617,16 +1617,19 @@ SyncProgressNotifier::NotifierPackage::create_invocation(Progress const& current // the total number of uploadable bytes available rather than the number of // bytes this NotifierPackage was waiting to upload. if (!is_download) { - estimate = transferable > 0 ? std::min(transfered / double(transferable), 1.0) : 0.0; + // If the upload transferable value is 0, report a progress estimate of 1.0, + // since the non-streaming request is going to be expired below and there + // is nothing to upload. + estimate = transferable > 0 ? std::min(transferred / double(transferable), 1.0) : 1.0; } } // A notifier is expired if at least as many bytes have been transferred // as were originally considered transferrable. is_expired = - !is_streaming && (transfered >= transferable && (!is_download || !pending_query_version || estimate >= 1.0)); + !is_streaming && (transferred >= transferable && (!is_download || !pending_query_version || estimate >= 1.0)); return [=, notifier = notifier] { - notifier(transfered, transferable, estimate); + notifier(transferred, transferable, estimate); }; } diff --git a/test/object-store/sync/session/progress_notifications.cpp b/test/object-store/sync/session/progress_notifications.cpp index 2d5cc2f8ce..33c5b38a20 100644 --- a/test/object-store/sync/session/progress_notifications.cpp +++ b/test/object-store/sync/session/progress_notifications.cpp @@ -162,7 +162,8 @@ TEST_CASE("progress notification", "[sync][session][progress]") { SECTION("callback is invoked immediately when a progress update has already occurred") { progress.set_local_version(1); - progress.update(0, 0, 0, 0, 1, 0.0, 0.0, 0); + // progress is reported as 1.0 for transferrable/transferred values of 0 + progress.update(0, 0, 0, 0, 1, 1.0, 1.0, 0); bool callback_was_called = false; SECTION("for upload notifications, with no data transfer ongoing") { @@ -174,7 +175,7 @@ TEST_CASE("progress notification", "[sync][session][progress]") { }, NotifierType::upload, false, 0); REQUIRE(callback_was_called); - REQUIRE(estimate == 0.0); + REQUIRE(estimate == 1.0); } SECTION("for download notifications, with no data transfer ongoing") { @@ -185,7 +186,7 @@ TEST_CASE("progress notification", "[sync][session][progress]") { estimate = ep; }, NotifierType::download, false, 0); - REQUIRE(estimate == 0.0); + REQUIRE(estimate == 1.0); REQUIRE(callback_was_called); } @@ -206,7 +207,8 @@ TEST_CASE("progress notification", "[sync][session][progress]") { } SECTION("callback is invoked after each update for streaming notifiers") { - progress.update(0, 0, 0, 0, 1, 0.0, 0.0, 0); + // progress is reported as 1.0 for transferrable/transferred values of 0 + progress.update(0, 0, 0, 0, 1, 1.0, 1.0, 0); bool callback_was_called = false; uint64_t transferred = 0; From cb23f9e633f5c76105bdcaaf0e60a020d41437a2 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 6 Aug 2024 17:10:43 -0400 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0539d3fa2a..9a9d797e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ * None. ### Breaking changes -* None. +* Non-streaming upload progress notifications will report an estimate of 1.0 instead of 0.0 if there is nothing to upload. [PR #7957](https://github.com/realm/realm-core/pull/7957) ### Compatibility * Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10. If you want to upgrade from an earlier file format version you will have to use RealmCore v13.x.y or earlier.