Skip to content

Commit b9b3d89

Browse files
authored
RCORE-2149 Restore behavior of Sync_UploadDownloadProgress_1 test (#7773)
1 parent b6452b9 commit b9b3d89

File tree

1 file changed

+54
-43
lines changed

1 file changed

+54
-43
lines changed

test/test_sync.cpp

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,65 +2927,80 @@ TEST(Sync_UploadDownloadProgress_1)
29272927
TEST_DIR(server_dir);
29282928
TEST_CLIENT_DB(db);
29292929

2930-
std::atomic<uint_fast64_t> downloaded_bytes;
2931-
std::atomic<uint_fast64_t> downloadable_bytes;
2932-
std::atomic<uint_fast64_t> uploaded_bytes;
2933-
std::atomic<uint_fast64_t> uploadable_bytes;
2934-
std::atomic<uint_fast64_t> snapshot_version;
2935-
{
2936-
int handler_entry = 0;
2930+
struct ProgressInfo {
2931+
uint64_t downloaded_bytes = 0;
2932+
uint64_t downloadable_bytes = 0;
2933+
uint64_t uploaded_bytes = 0;
2934+
uint64_t uploadable_bytes = 0;
2935+
uint64_t snapshot_version = 0;
2936+
};
29372937

2938+
ProgressInfo first_run_progress;
2939+
2940+
{
29382941
ClientServerFixture fixture(server_dir, test_context);
29392942
fixture.start();
29402943

29412944
Session::Config config;
2945+
std::mutex progress_mutex;
2946+
std::condition_variable progress_cv;
2947+
std::optional<ProgressInfo> observed_progress;
2948+
auto wait_for_progress_info = [&] {
2949+
std::unique_lock lk(progress_mutex);
2950+
progress_cv.wait(lk, [&] {
2951+
return observed_progress;
2952+
});
2953+
auto ret = std::exchange(observed_progress, std::optional<ProgressInfo>{});
2954+
return *ret;
2955+
};
29422956
config.progress_handler = [&](uint64_t downloaded, uint64_t downloadable, uint64_t uploaded,
29432957
uint64_t uploadable, uint64_t snapshot, double, double, int64_t) {
2944-
downloaded_bytes = downloaded;
2945-
downloadable_bytes = downloadable;
2946-
uploaded_bytes = uploaded;
2947-
uploadable_bytes = uploadable;
2948-
snapshot_version = snapshot;
2949-
++handler_entry;
2958+
std::lock_guard lk(progress_mutex);
2959+
observed_progress = ProgressInfo{downloaded, downloadable, uploaded, uploadable, snapshot};
2960+
progress_cv.notify_one();
29502961
};
29512962

2952-
auto pf = util::make_promise_future();
2953-
config.connection_state_change_listener = [&](ConnectionState state, util::Optional<ErrorInfo>) {
2954-
if (state == ConnectionState::connected) {
2955-
pf.promise.emplace_value();
2956-
}
2957-
};
29582963

29592964
Session session = fixture.make_session(db, "/test", std::move(config));
2960-
pf.future.get();
2961-
CHECK_EQUAL(handler_entry, 0);
2965+
auto progress_info = wait_for_progress_info();
2966+
2967+
CHECK_EQUAL(progress_info.downloaded_bytes, uint_fast64_t(0));
2968+
CHECK_EQUAL(progress_info.downloadable_bytes, uint_fast64_t(0));
2969+
CHECK_EQUAL(progress_info.uploaded_bytes, uint_fast64_t(0));
2970+
CHECK_EQUAL(progress_info.uploadable_bytes, uint_fast64_t(0));
2971+
CHECK_GREATER_EQUAL(progress_info.snapshot_version, 1);
29622972

29632973
auto commit_version = write_transaction(db, [](WriteTransaction& wt) {
2964-
wt.get_group().add_table_with_primary_key("class_table", type_Int, "id");
2974+
auto tr = wt.get_group().add_table_with_primary_key("class_table", type_Int, "id");
2975+
tr->add_column(type_Int, "integer column");
29652976
});
29662977

29672978
session.wait_for_upload_complete_or_client_stopped();
29682979
session.wait_for_download_complete_or_client_stopped();
29692980

2970-
CHECK_EQUAL(downloaded_bytes, uint_fast64_t(0));
2971-
CHECK_EQUAL(downloadable_bytes, uint_fast64_t(0));
2972-
CHECK_NOT_EQUAL(uploaded_bytes, uint_fast64_t(0));
2973-
CHECK_NOT_EQUAL(uploadable_bytes, uint_fast64_t(0));
2974-
CHECK_GREATER_EQUAL(snapshot_version, commit_version);
2975-
2981+
auto old_progress_info = progress_info;
2982+
progress_info = wait_for_progress_info();
2983+
CHECK_EQUAL(progress_info.downloaded_bytes, uint_fast64_t(0));
2984+
CHECK_EQUAL(progress_info.downloadable_bytes, uint_fast64_t(0));
2985+
CHECK_GREATER(progress_info.uploaded_bytes, old_progress_info.uploaded_bytes);
2986+
CHECK_GREATER(progress_info.uploadable_bytes, old_progress_info.uploadable_bytes);
2987+
CHECK_GREATER_EQUAL(progress_info.snapshot_version, commit_version);
29762988

29772989
commit_version = write_transaction(db, [](WriteTransaction& wt) {
2978-
wt.get_table("class_table")->create_object_with_primary_key(1);
2990+
wt.get_table("class_table")->create_object_with_primary_key(1).set("integer column", 42);
29792991
});
29802992

29812993
session.wait_for_upload_complete_or_client_stopped();
29822994
session.wait_for_download_complete_or_client_stopped();
29832995

2984-
CHECK_EQUAL(downloaded_bytes, uint_fast64_t(0));
2985-
CHECK_EQUAL(downloadable_bytes, uint_fast64_t(0));
2986-
CHECK_NOT_EQUAL(uploaded_bytes, uint_fast64_t(0));
2987-
CHECK_NOT_EQUAL(uploadable_bytes, uint_fast64_t(0));
2988-
CHECK_GREATER_EQUAL(snapshot_version, commit_version);
2996+
old_progress_info = progress_info;
2997+
progress_info = wait_for_progress_info();
2998+
CHECK_EQUAL(progress_info.downloaded_bytes, uint_fast64_t(0));
2999+
CHECK_EQUAL(progress_info.downloadable_bytes, uint_fast64_t(0));
3000+
CHECK_GREATER(progress_info.uploaded_bytes, old_progress_info.uploaded_bytes);
3001+
CHECK_GREATER(progress_info.uploadable_bytes, old_progress_info.uploadable_bytes);
3002+
CHECK_GREATER_EQUAL(progress_info.snapshot_version, commit_version);
3003+
first_run_progress = progress_info;
29893004
}
29903005

29913006
{
@@ -2998,24 +3013,20 @@ TEST(Sync_UploadDownloadProgress_1)
29983013
fixture.start();
29993014

30003015
int number_of_handler_calls = 0;
3001-
30023016
auto pf = util::make_promise_future<int>();
30033017
Session::Config config;
30043018
config.progress_handler = [&](uint64_t downloaded, uint64_t downloadable, uint64_t uploaded,
30053019
uint64_t uploadable, uint64_t snapshot, double, double, int64_t) {
3006-
CHECK_EQUAL(downloaded, downloaded_bytes);
3007-
CHECK_EQUAL(downloadable, downloaded_bytes);
3008-
CHECK_EQUAL(uploaded, uploaded_bytes);
3009-
CHECK_GREATER(uploadable, uploaded_bytes);
3010-
CHECK_GREATER(snapshot, snapshot_version);
3020+
CHECK_EQUAL(downloaded, first_run_progress.downloaded_bytes);
3021+
CHECK_EQUAL(downloadable, first_run_progress.downloadable_bytes);
3022+
CHECK_EQUAL(uploaded, first_run_progress.uploaded_bytes);
3023+
CHECK_EQUAL(uploadable, first_run_progress.uploadable_bytes);
3024+
CHECK_GREATER(snapshot, first_run_progress.snapshot_version);
30113025
number_of_handler_calls++;
30123026
pf.promise.emplace_value(number_of_handler_calls);
30133027
};
30143028

30153029
Session session = fixture.make_session(db, "/test", std::move(config));
3016-
write_transaction(db, [](WriteTransaction& wt) {
3017-
wt.get_table("class_table")->create_object_with_primary_key(2);
3018-
});
30193030
CHECK_EQUAL(pf.future.get(), 1);
30203031
}
30213032
}

0 commit comments

Comments
 (0)