Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCORE-2227 Updated non-streaming upload progress to report 1.0 if nothing to upload #7957

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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.
Expand Down
11 changes: 7 additions & 4 deletions src/realm/object-store/sync/sync_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ void SyncProgressNotifier::set_local_version(uint64_t snapshot_version)
util::UniqueFunction<void()>
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;

Expand Down Expand Up @@ -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);
};
}

Expand Down
10 changes: 6 additions & 4 deletions test/object-store/sync/session/progress_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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") {
Expand All @@ -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);
}

Expand All @@ -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;
Expand Down
Loading