From e44611301cc39f705c030705d249778a58d6a230 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 6 Jun 2017 19:40:52 +0100 Subject: [PATCH] Fix the problem with redis not being initialized anymore. --- src/tawashi/CMakeLists.txt | 5 +++-- src/tawashi/storage.cpp | 4 +++- src/tawashi/submit_paste_response.cpp | 19 +++++++++++++------ src/tawashi/submit_paste_response.hpp | 9 +++++++++ test/simulation/test_submit_pastie.cpp | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/tawashi/CMakeLists.txt b/src/tawashi/CMakeLists.txt index 478491c..bcc326c 100644 --- a/src/tawashi/CMakeLists.txt +++ b/src/tawashi/CMakeLists.txt @@ -60,8 +60,9 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1 PUBLIC $<$:SPDLOG_DEBUG_ON> PUBLIC $<$:SPDLOG_TRACE_ON> - PUBLIC tawashi_virtual_testing$<$:=virtual> - PUBLIC $<$:TAWASHI_WITH_TESTING> + PUBLIC $<$:tawashi_virtual_testing=virtual> + PUBLIC $<$>:tawashi_virtual_testing=> + PUBLIC $<$:TAWASHI_WITH_TESTING> ) target_compile_options(${PROJECT_NAME} PRIVATE -fdiagnostics-color=always diff --git a/src/tawashi/storage.cpp b/src/tawashi/storage.cpp index 9417f24..cd5a711 100644 --- a/src/tawashi/storage.cpp +++ b/src/tawashi/storage.cpp @@ -69,6 +69,7 @@ namespace tawashi { assert(not m_redis); m_redis = std::make_unique(make_incredis(*m_settings)); m_redis->connect(); + SPDLOG_TRACE(spdlog::get("statuslog"), "Trying to connect to Redis asynchronously"); } bool Storage::is_connected() const { @@ -76,8 +77,9 @@ namespace tawashi { } void Storage::finalize_connection() { + SPDLOG_TRACE(spdlog::get("statuslog"), "Asked Storage to finalize the Redis connection"); if (m_redis) { - SPDLOG_TRACE(spdlog::get("statuslog"), "Finalizing redis connection"); + SPDLOG_TRACE(spdlog::get("statuslog"), "Finalizing Redis connection"); m_redis->wait_for_connect(); auto batch = m_redis->make_batch(); batch.select(m_settings->as("redis_db")); diff --git a/src/tawashi/submit_paste_response.cpp b/src/tawashi/submit_paste_response.cpp index 9d3f1c1..271c48b 100644 --- a/src/tawashi/submit_paste_response.cpp +++ b/src/tawashi/submit_paste_response.cpp @@ -34,11 +34,6 @@ namespace tawashi { const char g_post_key[] = "pastie"; const char g_language_key[] = "lang"; const char g_duration_key[] = "ttl"; -#if defined(TAWASHI_WITH_TESTING) - const bool g_connect_to_redis = false; -#else - const bool g_connect_to_redis = true; -#endif class MissingPostVarError : public TawashiException { public: @@ -78,12 +73,24 @@ namespace tawashi { } } //unnamed namespace +#if defined(TAWASHI_WITH_TESTING) + SubmitPasteResponse::SubmitPasteResponse ( + const Kakoune::SafePtr& parSettings, + std::ostream* parStreamOut, + const Kakoune::SafePtr& parCgiEnv, + bool parInitStorage + ) : + Response(parSettings, parStreamOut, parCgiEnv, parInitStorage) + { + } +#endif + SubmitPasteResponse::SubmitPasteResponse ( const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : - Response(parSettings, parStreamOut, parCgiEnv, g_connect_to_redis) + Response(parSettings, parStreamOut, parCgiEnv, true) { } diff --git a/src/tawashi/submit_paste_response.hpp b/src/tawashi/submit_paste_response.hpp index 1d9d431..9a08ae4 100644 --- a/src/tawashi/submit_paste_response.hpp +++ b/src/tawashi/submit_paste_response.hpp @@ -27,6 +27,15 @@ namespace tawashi { class SubmitPasteResponse : public Response { public: +#if defined(TAWASHI_WITH_TESTING) + SubmitPasteResponse ( + const Kakoune::SafePtr& parSettings, + std::ostream* parStreamOut, + const Kakoune::SafePtr& parCgiEnv, + bool parInitStorage + ); +#endif + SubmitPasteResponse ( const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, diff --git a/test/simulation/test_submit_pastie.cpp b/test/simulation/test_submit_pastie.cpp index 636f0a9..66185a2 100644 --- a/test/simulation/test_submit_pastie.cpp +++ b/test/simulation/test_submit_pastie.cpp @@ -38,7 +38,7 @@ namespace tawashi { const Kakoune::SafePtr& parCgiEnv, std::string&& parPostData ) : - SubmitPasteResponse(parSettings, parStreamOut, parCgiEnv), + SubmitPasteResponse(parSettings, parStreamOut, parCgiEnv, false), m_fake_storage(parSettings, true), m_post_data(std::move(parPostData)) {