test(server): test transaction locked keys (#1669)

* test(server): test transaction locked keys

1. add test utility class that will add suspension to transaction
   execution.
2. add test for locked keys in transaction

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-08-09 15:52:13 +03:00 committed by GitHub
parent 16c2353faf
commit f9a3e2811c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 18 deletions

View file

@ -12,6 +12,7 @@
#include "io/io.h"
#include "server/conn_context.h"
#include "server/main_service.h"
#include "server/transaction.h"
#include "util/proactor_pool.h"
namespace dfly {
@ -37,6 +38,19 @@ class TestConnection : public facade::Connection {
bool is_admin_ = false;
};
// The TransactionSuspension class is designed to facilitate the temporary suspension of commands
// executions. When the 'start' method is invoked, it enforces the suspension of other
// transactions by acquiring a global shard lock. Conversely, invoking the 'terminate' method
// releases the global shard lock, enabling all transactions in the queue to resume execution.
class TransactionSuspension {
public:
void Start();
void Terminate();
private:
boost::intrusive_ptr<dfly::Transaction> transaction_;
};
class BaseFamilyTest : public ::testing::Test {
protected:
BaseFamilyTest();
@ -105,6 +119,8 @@ class BaseFamilyTest : public ::testing::Test {
size_t index) const;
static absl::flat_hash_set<std::string> GetLastUsedKeys();
static void ExpectConditionWithinTimeout(const std::function<bool()>& condition,
absl::Duration timeout = absl::Seconds(10));
static unsigned NumLocked();