diff --git a/test/Makefile.am b/test/Makefile.am index 30b2f0736..e415c7e1c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -41,7 +41,6 @@ all_la_unit_tests = \ unit-uno-command.la \ unit-load-torture.la \ unit-copy-paste.la \ - unit-wopi-async-upload-modify.la \ unit-http.la \ unit-wopi-temp.la \ unit-wopi-async-upload-close.la \ @@ -205,8 +204,6 @@ unit_wopi_la_SOURCES = UnitWOPI.cpp unit_wopi_la_LIBADD = $(CPPUNIT_LIBS) unit_wopi_async_upload_close_la_SOURCES = UnitWOPIAsyncUpload_Close.cpp unit_wopi_async_upload_close_la_LIBADD = $(CPPUNIT_LIBS) -unit_wopi_async_upload_modify_la_SOURCES = UnitWOPIAsyncUpload_Modify.cpp -unit_wopi_async_upload_modify_la_LIBADD = $(CPPUNIT_LIBS) unit_wopi_async_upload_modifyclose_la_SOURCES = UnitWOPIAsyncUpload_ModifyClose.cpp unit_wopi_async_upload_modifyclose_la_LIBADD = $(CPPUNIT_LIBS) unit_wopi_async_slow_la_SOURCES = UnitWOPISlow.cpp diff --git a/test/UnitWOPIAsyncUpload_Modify.cpp b/test/UnitWOPIAsyncUpload_Modify.cpp deleted file mode 100644 index 4a4e3643b..000000000 --- a/test/UnitWOPIAsyncUpload_Modify.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include - -#include "HttpRequest.hpp" -#include "Util.hpp" -#include "lokassert.hpp" - -#include -#include -#include -#include -#include -#include -#include - -/// Test Async uploading with simulated failing. -/// We modify the document, save, and attempt to upload, -/// which fails. We then modify the document again -/// and save. We expect another upload attempt, -/// which will succeed. -/// Modify, Save, Upload fails. -/// Modify, Save, Upload fails, close -> Upload. -class UnitWOPIAsyncUpload_Modify : public WopiTestServer -{ - STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, WaitUnmodifiedStatus, WaitDestroy) - _phase; - -public: - UnitWOPIAsyncUpload_Modify() - : WopiTestServer("UnitWOPIAsyncUpload_Modify") - , _phase(Phase::Load) - { - } - - std::unique_ptr - assertPutFileRequest(const Poco::Net::HTTPRequest& request) override - { - LOK_ASSERT_MESSAGE("Too many PutFile attempts", getCountPutFile() <= 3); - - // The document is modified. - LOK_ASSERT_EQUAL(std::string("true"), request.get("X-COOL-WOPI-IsModifiedByUser")); - LOK_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsModifiedByUser")); - - // Triggered manually or during closing, not auto-save. - LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsAutosave")); - LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsAutosave")); - - // Certainly not exiting yet. - LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsExitSave")); - LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsExitSave")); - - LOK_ASSERT_MESSAGE("Unexpected phase", _phase == Phase::WaitModifiedStatus || - _phase == Phase::WaitUnmodifiedStatus); - - // We save twice. First right after loading, unmodified. - if (getCountPutFile() == 1) - { - LOG_TST("First PutFile, which will fail"); - - // Fail with error. - LOG_TST("Simulate PutFile failure"); - return Util::make_unique(http::StatusLine(500)); - } - - if (getCountPutFile() == 2) - { - LOG_TST("Second PutFile, which will also fail"); - - LOG_TST("Simulate PutFile failure (again)"); - return Util::make_unique(http::StatusLine(500)); - } - - if (getCountPutFile() == 3) - { - // This during closing the document. - LOG_TST("Third PutFile, which will succeed"); - - // The document should now unload. - TRANSITION_STATE(_phase, Phase::WaitDestroy); - - // Success. - return nullptr; - } - - failTest("Unexpected Phase in PutFile: " + std::to_string(static_cast(_phase))); - return nullptr; - } - - /// The document is loaded. - bool onDocumentLoaded(const std::string& message) override - { - LOG_TST("Got: [" << message << ']'); - LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus); - - TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); - WSD_CMD("key type=input char=97 key=0"); - WSD_CMD("key type=up char=0 key=512"); - - return true; - } - - /// The document is modified. Save it. - bool onDocumentModified(const std::string& message) override - { - LOG_TST("Got: [" << message << ']'); - LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus); - - TRANSITION_STATE(_phase, Phase::WaitUnmodifiedStatus); - WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 " - "extendedData=CustomFlag%3DCustom%20Value%3BAnotherFlag%3DAnotherValue"); - - return true; - } - - /// The document is unmodified. Modify again. - bool onDocumentUnmodified(const std::string& message) override - { - LOG_TST("Got: [" << message << ']'); - LOK_ASSERT_STATE(_phase, Phase::WaitUnmodifiedStatus); - - if (getCountPutFile() <= 1) - { - // Modify again. - TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); - WSD_CMD("key type=input char=97 key=0"); - WSD_CMD("key type=up char=0 key=512"); - } - else - { - LOG_ASSERT(getCountPutFile() > 1); - LOG_TST("More than one upload attempted, closing the document"); - WSD_CMD("closedocument"); - } - - return true; - } - - // Wait for clean unloading. - void onDocBrokerDestroy(const std::string& docKey) override - { - LOG_TST("Destroyed dockey [" << docKey << ']'); - LOK_ASSERT_STATE(_phase, Phase::WaitDestroy); - - passTest("Document uploaded on closing as expected."); - } - - void invokeWSDTest() override - { - switch (_phase) - { - case Phase::Load: - { - TRANSITION_STATE(_phase, Phase::WaitLoadStatus); - - LOG_TST("Load: initWebsocket."); - initWebsocket("/wopi/files/0?access_token=anything"); - - WSD_CMD("load url=" + getWopiSrc()); - break; - } - case Phase::WaitLoadStatus: - case Phase::WaitModifiedStatus: - case Phase::WaitUnmodifiedStatus: - case Phase::WaitDestroy: - break; - } - } -}; - -UnitBase* unit_create_wsd(void) { return new UnitWOPIAsyncUpload_Modify(); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/UnitWOPIFailUpload.cpp b/test/UnitWOPIFailUpload.cpp index 57ab75aa3..214e1e099 100644 --- a/test/UnitWOPIFailUpload.cpp +++ b/test/UnitWOPIFailUpload.cpp @@ -465,13 +465,176 @@ public: } }; +/// Test Async uploading with simulated failing. +/// We modify the document, save, and attempt to upload, +/// which fails. We then modify the document again +/// and save. We expect another upload attempt, +/// which will succeed. +/// Modify, Save, Upload fails. +/// Modify, Save, Upload fails, close -> Upload. +class UnitFailUploadModified : public WopiTestServer +{ + STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, WaitUnmodifiedStatus, WaitDestroy) + _phase; + +public: + UnitFailUploadModified() + : WopiTestServer("UnitFailUploadModified") + , _phase(Phase::Load) + { + } + + void configure(Poco::Util::LayeredConfiguration& config) override + { + WopiTestServer::configure(config); + + // We intentionally fail uploading twice, so need at least 3 tries. + config.setUInt("per_document.limit_store_failures", 3); + config.setBool("per_document.always_save_on_exit", false); + } + + std::unique_ptr + assertPutFileRequest(const Poco::Net::HTTPRequest& request) override + { + LOK_ASSERT_MESSAGE("Too many PutFile attempts", getCountPutFile() <= 3); + + // The document is modified. + LOK_ASSERT_EQUAL(std::string("true"), request.get("X-COOL-WOPI-IsModifiedByUser")); + LOK_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsModifiedByUser")); + + // Triggered manually or during closing, not auto-save. + LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsAutosave")); + LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsAutosave")); + + // Certainly not exiting yet. + LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsExitSave")); + LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsExitSave")); + + LOK_ASSERT_MESSAGE("Unexpected phase", _phase == Phase::WaitModifiedStatus || + _phase == Phase::WaitUnmodifiedStatus); + + // We save twice. First right after loading, unmodified. + if (getCountPutFile() == 1) + { + LOG_TST("First PutFile, which will fail"); + + // Fail with error. + LOG_TST("Simulate PutFile failure"); + return Util::make_unique(http::StatusLine(500)); + } + + if (getCountPutFile() == 2) + { + LOG_TST("Second PutFile, which will also fail"); + + LOG_TST("Simulate PutFile failure (again)"); + return Util::make_unique(http::StatusLine(500)); + } + + if (getCountPutFile() == 3) + { + // This is during closing the document. + LOG_TST("Third PutFile, which will succeed"); + + // The document should now unload. + TRANSITION_STATE(_phase, Phase::WaitDestroy); + + // Success. + return nullptr; + } + + failTest("Unexpected Phase in PutFile: " + std::to_string(static_cast(_phase))); + return nullptr; + } + + /// The document is loaded. + bool onDocumentLoaded(const std::string& message) override + { + LOG_TST("Got: [" << message << ']'); + LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus); + + TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); + WSD_CMD("key type=input char=97 key=0"); + WSD_CMD("key type=up char=0 key=512"); + + return true; + } + + /// The document is modified. Save it. + bool onDocumentModified(const std::string& message) override + { + LOG_TST("Got: [" << message << ']'); + LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus); + + TRANSITION_STATE(_phase, Phase::WaitUnmodifiedStatus); + WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 " + "extendedData=CustomFlag%3DCustom%20Value%3BAnotherFlag%3DAnotherValue"); + + return true; + } + + /// The document is unmodified. Modify again. + bool onDocumentUnmodified(const std::string& message) override + { + LOG_TST("Got: [" << message << ']'); + LOK_ASSERT_STATE(_phase, Phase::WaitUnmodifiedStatus); + + if (getCountPutFile() <= 1) + { + // Modify again. + TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); + WSD_CMD("key type=input char=97 key=0"); + WSD_CMD("key type=up char=0 key=512"); + } + else + { + LOG_ASSERT(getCountPutFile() > 1); + LOG_TST("More than one upload attempted, closing the document"); + WSD_CMD("closedocument"); + } + + return true; + } + + // Wait for clean unloading. + void onDocBrokerDestroy(const std::string& docKey) override + { + LOG_TST("Destroyed dockey [" << docKey << ']'); + LOK_ASSERT_STATE(_phase, Phase::WaitDestroy); + + passTest("Document uploaded on closing as expected."); + } + + void invokeWSDTest() override + { + switch (_phase) + { + case Phase::Load: + { + TRANSITION_STATE(_phase, Phase::WaitLoadStatus); + + LOG_TST("Load: initWebsocket."); + initWebsocket("/wopi/files/0?access_token=anything"); + + WSD_CMD("load url=" + getWopiSrc()); + break; + } + case Phase::WaitLoadStatus: + case Phase::WaitModifiedStatus: + case Phase::WaitUnmodifiedStatus: + case Phase::WaitDestroy: + break; + } + } +}; + UnitBase** unit_create_wsd_multi(void) { - return new UnitBase* [6] + return new UnitBase* [7] { new UnitWOPIExpiredToken(), new UnitWOPIFailUpload(), new UnitWOPIReadOnly(UnitWOPIReadOnly::Scenario::ViewWithComment), - new UnitWOPIReadOnly(UnitWOPIReadOnly::Scenario::Edit), + new UnitWOPIReadOnly(UnitWOPIReadOnly::Scenario::Edit), new UnitFailUploadModified() }; }