diff --git a/sources/network/redis_connection.cpp b/sources/network/redis_connection.cpp index 7191ffc0..123071d5 100644 --- a/sources/network/redis_connection.cpp +++ b/sources/network/redis_connection.cpp @@ -122,6 +122,7 @@ redis_connection::commit(void) { m_client->async_write(request); } catch (const std::exception& e) { + m_buffer = std::move(buffer); __CPP_REDIS_LOG(error, std::string("cpp_redis::network::redis_connection ") + e.what()); throw redis_error(e.what()); } diff --git a/sources/redis_client.cpp b/sources/redis_client.cpp index 71d49857..c0a3bb3f 100644 --- a/sources/redis_client.cpp +++ b/sources/redis_client.cpp @@ -114,7 +114,6 @@ redis_client::try_commit(void) { } catch (const cpp_redis::redis_error& e) { __CPP_REDIS_LOG(error, "cpp_redis::redis_client could not send pipelined commands"); - clear_callbacks(); throw e; } } @@ -126,10 +125,10 @@ redis_client::connection_receive_handler(network::redis_connection&, reply& repl __CPP_REDIS_LOG(info, "cpp_redis::redis_client received reply"); { std::lock_guard lock(m_callbacks_mutex); + m_callbacks_running += 1; if (m_callbacks.size()) { callback = m_callbacks.front(); - m_callbacks_running += 1; m_callbacks.pop(); } } diff --git a/tacopie b/tacopie index bba37f21..0b1ea257 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit bba37f21b11887644c40010478c08061f0163cd2 +Subproject commit 0b1ea257a40b5728c26290cec199eed332b289d1 diff --git a/tests/sources/spec/redis_client_spec.cpp b/tests/sources/spec/redis_client_spec.cpp index df348d10..f88ff32e 100644 --- a/tests/sources/spec/redis_client_spec.cpp +++ b/tests/sources/spec/redis_client_spec.cpp @@ -199,8 +199,8 @@ TEST(RedisClient, SendNotConnectedSyncCommitNotConnectedSyncCommitConnected) { EXPECT_THROW(client.sync_commit(), cpp_redis::redis_error); client.connect(); client.sync_commit(); - //! should have cleared commands in the buffer - EXPECT_FALSE(callback_run); + //! should not have cleared commands in the buffer + EXPECT_TRUE(callback_run); } TEST(RedisClient, Send) { @@ -297,7 +297,7 @@ TEST(RedisClient, DisconnectionHandlerWithoutQuit) { EXPECT_FALSE(disconnection_handler_called); } -TEST(RedisClient, ClearBufferOnError) { +TEST(RedisClient, DoNotClearBufferOnError) { cpp_redis::redis_client client; client.connect(); @@ -310,7 +310,25 @@ TEST(RedisClient, ClearBufferOnError) { client.connect(); client.send({"GET", "HELLO"}, [&](cpp_redis::reply& reply) { EXPECT_TRUE(reply.is_string()); - EXPECT_TRUE(reply.as_string() == "BEFORE"); + EXPECT_TRUE(reply.as_string() == "AFTER"); + }); + client.sync_commit(); +} + +TEST(RedisClient, ClearBufferOnUserDisconnect) { + cpp_redis::redis_client client; + + client.connect(); + client.send({"SET", "HELLO", "BEFORE"}); + client.sync_commit(); + client.send({"SET", "HELLO", "AFTER"}); + client.disconnect(); + + EXPECT_THROW(client.sync_commit(), cpp_redis::redis_error); + client.connect(); + client.send({"GET", "HELLO"}, [&](cpp_redis::reply& reply) { + EXPECT_TRUE(reply.is_string()); + EXPECT_TRUE(reply.as_string() == "AFTER"); }); client.sync_commit(); } diff --git a/tests/sources/spec/redis_subscriber_spec.cpp b/tests/sources/spec/redis_subscriber_spec.cpp index 9ab382a8..01088f07 100644 --- a/tests/sources/spec/redis_subscriber_spec.cpp +++ b/tests/sources/spec/redis_subscriber_spec.cpp @@ -225,7 +225,7 @@ TEST(RedisSubscriber, SubNotConnectedCommitNotConnectedCommitConnected) { std::this_thread::sleep_for(std::chrono::seconds(2)); - EXPECT_FALSE(callback_run); + EXPECT_TRUE(callback_run); } TEST(RedisSubscriber, SubscribeSomethingPublished) {