diff --git a/src/slic3r/Utils/OrcaCloudServiceAgent.hpp b/src/slic3r/Utils/OrcaCloudServiceAgent.hpp index 6518159c8c..7768c02f25 100644 --- a/src/slic3r/Utils/OrcaCloudServiceAgent.hpp +++ b/src/slic3r/Utils/OrcaCloudServiceAgent.hpp @@ -81,28 +81,28 @@ struct ProfileUpsert { std::string id; std::string name; nlohmann::json content; - long long updated_time; - long long created_time; + long long updated_time = 0; + long long created_time = 0; }; struct SyncPullResponse { - long long next_cursor; + long long next_cursor = 0; std::vector upserts; std::vector deletes; }; struct SyncPushResult { - bool success; - int http_code; - int conflict_code; - long long new_updated_time; + bool success = false; + int http_code = 0; + int conflict_code = 0; + long long new_updated_time = 0; ProfileUpsert server_version; - bool server_deleted; + bool server_deleted = false; std::string error_message; }; struct SyncState { - long long last_sync_timestamp; + long long last_sync_timestamp = 0; }; #endif // ORCA_SYNC_STRUCTS_DEFINED diff --git a/tests/slic3rutils/test_orca_cloud_agent.cpp b/tests/slic3rutils/test_orca_cloud_agent.cpp index 5f70d8c62a..b386a15fd6 100644 --- a/tests/slic3rutils/test_orca_cloud_agent.cpp +++ b/tests/slic3rutils/test_orca_cloud_agent.cpp @@ -876,3 +876,28 @@ TEST_CASE("A delete that fails to reach the gateway keeps its .info for a later CHECK(fs::exists(fixture.info_path)); CHECK(fixture.queue.size() == 1); } + +TEST_CASE_METHOD(HealthCheckFixture, "A session with no saved sync state pulls without a cursor", "[OrcaCloudServiceAgent]") +{ + // Nothing has been pulled yet, so there is no cursor to resume from. + CHECK(agent->get_sync_state().last_sync_timestamp == 0); + + sign_in("user-a"); + server.set_reply("200 OK", R"({"upserts":[],"deletes":[],"next_cursor":0})"); + REQUIRE(agent->get_setting_list2("", nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS); + + const auto requests = server.requests(); + REQUIRE(requests.size() == 1); + CHECK(requests.front().request_line == "GET /api/v1/sync/pull HTTP/1.1"); +} + +TEST_CASE_METHOD(HealthCheckFixture, "A pull answered 304 keeps the sync state it had", "[OrcaCloudServiceAgent]") +{ + sign_in("user-a"); + server.set_reply("304 Not Modified", ""); + REQUIRE(agent->get_setting_list2("", nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS); + + // Nothing changed, so there is still no cursor and none is written for the next session. + CHECK(agent->get_sync_state().last_sync_timestamp == 0); + CHECK_FALSE(fs::exists(dir.path() / "user" / "user-a" / "sync_state")); +}