bug(transaction): local result needs to be reset on InitByArgs Fixes … (#762)

* bug(transaction): local result needs to be reset on InitByArgs Fixes #752

Signed-off-by: adi_holden <adi@dragonflydb.io>

* add unit test

Signed-off-by: adi_holden <adi@dragonflydb.io>

---------

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-02-06 15:48:12 +02:00 committed by GitHub
parent 448508a23a
commit 4a826fdb7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -971,6 +971,19 @@ TEST_F(DefragDflyEngineTest, TestDefragOption) {
});
}
TEST_F(DflyEngineTest, Issue752) {
// https://github.com/dragonflydb/dragonfly/issues/752
// local_result_ member was not reset between commands
Run({"multi"});
auto resp = Run({"llen", kKey1});
ASSERT_EQ(resp, "QUEUED");
resp = Run({"del", kKey1, kKey2});
ASSERT_EQ(resp, "QUEUED");
resp = Run({"exec"});
ASSERT_THAT(resp, ArrLen(2));
ASSERT_THAT(resp.GetVec(), ElementsAre(IntArg(0), IntArg(0)));
}
// TODO: to test transactions with a single shard since then all transactions become local.
// To consider having a parameter in dragonfly engine controlling number of shards
// unconditionally from number of cpus. TO TEST BLPOP under multi for single/multi argument case.

View file

@ -82,6 +82,7 @@ Transaction::~Transaction() {
OpStatus Transaction::InitByArgs(DbIndex index, CmdArgList args) {
db_index_ = index;
cmd_with_full_args_ = args;
local_result_ = OpStatus::OK;
if (IsGlobal()) {
unique_shard_cnt_ = shard_set->size();