Skip to content

Commit

Permalink
Improve readability of transaction test (valkey-io#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Feb 15, 2024
1 parent 69d0754 commit 26e7a0b
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 117 deletions.
140 changes: 72 additions & 68 deletions node/tests/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,75 +63,79 @@ export function transactionTest(
const key8 = "{key}" + uuidv4();
const field = uuidv4();
const value = uuidv4();
baseTransaction
.set(key1, "bar")
.set(key2, "baz", {
returnOldValue: true,
})
.customCommand(["MGET", key1, key2])
.mset({ [key3]: value })
.mget([key1, key2])
.del([key1])
.hset(key4, { [field]: value })
.hget(key4, field)
.hgetall(key4)
.hdel(key4, [field])
.hmget(key4, [field])
.hexists(key4, field)
.lpush(key5, [field + "1", field + "2", field + "3", field + "4"])
.lpop(key5)
.llen(key5)
.lrem(key5, 1, field + "1")
.ltrim(key5, 0, 1)
.lrange(key5, 0, -1)
.lpopCount(key5, 2)
.rpush(key6, [field + "1", field + "2", field + "3"])
.rpop(key6)
.rpopCount(key6, 2)
.sadd(key7, ["bar", "foo"])
.srem(key7, ["foo"])
.scard(key7)
.smembers(key7)
.zadd(key8, { member1: 1, member2: 2 })
.zaddIncr(key8, "member2", 1)
.zrem(key8, ["member1"])
.zcard(key8)
.zscore(key8, "member2")
.zcount(key8, { bound: 2 }, "positiveInfinity");
return [
"OK",
null,
["bar", "baz"],
"OK",
["bar", "baz"],
1,
1,
value,
{ [field]: value },
1,
[null],
false,
4,
field + "4",
3,
1,
"OK",
[field + "3", field + "2"],
[field + "3", field + "2"],
3,
const args: ReturnType[] = [];
baseTransaction.set(key1, "bar");
args.push("OK");
baseTransaction.set(key2, "baz", {
returnOldValue: true,
});
args.push(null);
baseTransaction.customCommand(["MGET", key1, key2]);
args.push(["bar", "baz"]);
baseTransaction.mset({ [key3]: value });
args.push("OK");
baseTransaction.mget([key1, key2]);
args.push(["bar", "baz"]);
baseTransaction.del([key1]);
args.push(1);
baseTransaction.hset(key4, { [field]: value });
args.push(1);
baseTransaction.hget(key4, field);
args.push(value);
baseTransaction.hgetall(key4);
args.push({ [field]: value });
baseTransaction.hdel(key4, [field]);
args.push(1);
baseTransaction.hmget(key4, [field]);
args.push([null]);
baseTransaction.hexists(key4, field);
args.push(false);
baseTransaction.lpush(key5, [
field + "1",
field + "2",
field + "3",
[field + "2", field + "1"],
2,
1,
1,
["bar"],
2,
3,
1,
1,
3.0,
1,
];
field + "4",
]);
args.push(4);
baseTransaction.lpop(key5);
args.push(field + "4");
baseTransaction.llen(key5);
args.push(3);
baseTransaction.lrem(key5, 1, field + "1");
args.push(1);
baseTransaction.ltrim(key5, 0, 1);
args.push("OK");
baseTransaction.lrange(key5, 0, -1);
args.push([field + "3", field + "2"]);
baseTransaction.lpopCount(key5, 2);
args.push([field + "3", field + "2"]);
baseTransaction.rpush(key6, [field + "1", field + "2", field + "3"]);
args.push(3);
baseTransaction.rpop(key6);
args.push(field + "3");
baseTransaction.rpopCount(key6, 2);
args.push([field + "2", field + "1"]);
baseTransaction.sadd(key7, ["bar", "foo"]);
args.push(2);
baseTransaction.srem(key7, ["foo"]);
args.push(1);
baseTransaction.scard(key7);
args.push(1);
baseTransaction.smembers(key7);
args.push(["bar"]);
baseTransaction.zadd(key8, { member1: 1, member2: 2 });
args.push(2);
baseTransaction.zaddIncr(key8, "member2", 1);
args.push(3);
baseTransaction.zrem(key8, ["member1"]);
args.push(1);
baseTransaction.zcard(key8);
args.push(1);
baseTransaction.zscore(key8, "member2");
args.push(3.0);
baseTransaction.zcount(key8, { bound: 2 }, "positiveInfinity");
args.push(1);
return args;
}

export class RedisCluster {
Expand Down
98 changes: 49 additions & 49 deletions python/python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,120 +32,120 @@ def transaction_test(

value = datetime.now(timezone.utc).strftime("%m/%d/%Y, %H:%M:%S")
value2 = get_random_string(5)
args: List[TResult] = []

transaction.set(key, value)
args.append(OK)
transaction.get(key)
args.append(value)
transaction.type(key)
args.append("string")

transaction.exists([key])
args.append(1)

transaction.delete([key])
args.append(1)
transaction.get(key)
args.append(None)

transaction.mset({key: value, key2: value2})
args.append(OK)
transaction.mget([key, key2])
args.append([value, value2])

transaction.incr(key3)
args.append(1)
transaction.incrby(key3, 2)
args.append(3)

transaction.decr(key3)
args.append(2)
transaction.decrby(key3, 2)
args.append(0)

transaction.incrbyfloat(key3, 0.5)
args.append(0.5)

transaction.unlink([key3])
args.append(1)

transaction.ping()
args.append("PONG")

transaction.config_set({"timeout": "1000"})
args.append(OK)
transaction.config_get(["timeout"])
args.append({"timeout": "1000"})

transaction.hset(key4, {key: value, key2: value2})
args.append(2)
transaction.hget(key4, key2)
args.append(value2)
transaction.hlen(key4)
args.append(2)

transaction.hincrby(key4, key3, 5)
args.append(5)
transaction.hincrbyfloat(key4, key3, 5.5)
args.append(10.5)

transaction.hexists(key4, key)
args.append(True)
transaction.hmget(key4, [key, "nonExistingField", key2])
args.append([value, None, value2])
transaction.hgetall(key4)
args.append({key: value, key2: value2, key3: "10.5"})
transaction.hdel(key4, [key, key2])
args.append(2)

transaction.client_getname()
args.append(None)

transaction.lpush(key5, [value, value, value2, value2])
args.append(4)
transaction.llen(key5)
args.append(4)
transaction.lpop(key5)
args.append(value2)
transaction.lrem(key5, 1, value)
args.append(1)
transaction.ltrim(key5, 0, 1)
args.append(OK)
transaction.lrange(key5, 0, -1)
args.append([value2, value])
transaction.lpop_count(key5, 2)
args.append([value2, value])

transaction.rpush(key6, [value, value2, value2])
args.append(3)
transaction.rpop(key6)
args.append(value2)
transaction.rpop_count(key6, 2)
args.append([value2, value])

transaction.sadd(key7, ["foo", "bar"])
args.append(2)
transaction.srem(key7, ["foo"])
args.append(1)
transaction.smembers(key7)
args.append({"bar"})
transaction.scard(key7)
args.append(1)

transaction.zadd(key8, {"one": 1, "two": 2, "three": 3})
args.append(3)
transaction.zadd_incr(key8, "one", 3)
args.append(4)
transaction.zrem(key8, ["one"])
args.append(1)
transaction.zcard(key8)
args.append(2)
transaction.zcount(key8, ScoreLimit(2, True), InfBound.POS_INF)
args.append(2)
transaction.zscore(key8, "two")
return [
OK,
value,
"string",
1,
1,
None,
OK,
[value, value2],
1,
3,
2,
0,
0.5,
1,
"PONG",
OK,
{"timeout": "1000"},
2,
value2,
2,
5,
10.5,
True,
[value, None, value2],
{key: value, key2: value2, key3: "10.5"},
2,
None,
4,
4,
value2,
1,
OK,
[value2, value],
[value2, value],
3,
value2,
[value2, value],
2,
1,
{"bar"},
1,
3,
4,
1,
2,
2,
2.0,
]
args.append(2.0)
return args


@pytest.mark.asyncio
Expand Down

0 comments on commit 26e7a0b

Please sign in to comment.