Skip to content

Commit

Permalink
fix node tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon committed Dec 31, 2023
1 parent 9d07f40 commit 58c1721
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
12 changes: 9 additions & 3 deletions node/tests/RedisClusterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ describe("RedisClusterClient", () => {
const client = await RedisClusterClient.createClient(
getOptions(cluster.ports())
);
const result = (await client.info([
const info_server = (await client.info([
InfoOptions.Server,
])) as Record<string, string>;
expect(info_server.toString()).toEqual(expect.stringContaining("# Server"));

const result = (await client.info([
InfoOptions.Replication,
])) as Record<string, string>;
const clusterNodes = await client.customCommand([
Expand All @@ -161,9 +165,8 @@ describe("RedisClusterClient", () => {
]);
expect(
(clusterNodes as string)?.split("master").length - 1
).toEqual(Object.keys(result).length);
).toEqual(Object.keys(info_server).length);
Object.values(result).every((item) => {
expect(item).toEqual(expect.stringContaining("# Server"));
expect(item).toEqual(expect.stringContaining("# Replication"));
expect(item).toEqual(
expect.not.stringContaining("# Errorstats")
Expand Down Expand Up @@ -216,7 +219,10 @@ describe("RedisClusterClient", () => {
);
const transaction = new ClusterTransaction();
const expectedRes = transactionTest(transaction);
console.log(expectedRes);
console.log(transaction);
const result = await client.exec(transaction);
console.log(result);
expect(result).toEqual(expectedRes);
client.close();
},
Expand Down
55 changes: 42 additions & 13 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,20 @@ export function runBaseTests<Context>(config: {
expect(await client.ttl(key)).toBeLessThanOrEqual(10);
/// set command clears the timeout.
expect(await client.set(key, "bar")).toEqual("OK");
expect(
await client.pexpire(key, 10000, ExpireOptions.HasNoExpiry)
).toEqual(true);
const version = await getVersion();
if (version[0] < 7 ) {
expect(
await client.pexpire(key, 10000)
).toEqual(true);
}
else {
expect(
await client.pexpire(key, 10000, ExpireOptions.HasNoExpiry)
).toEqual(true);
}

expect(await client.ttl(key)).toBeLessThanOrEqual(10);
/// TTL will be updated to the new value = 15
const version = await getVersion();
if (version[0] < 7 ) {
expect(
await client.expire(
Expand Down Expand Up @@ -1026,24 +1034,45 @@ export function runBaseTests<Context>(config: {
)
).toEqual(true);
expect(await client.ttl(key)).toBeLessThanOrEqual(10);
expect(
await client.expireAt(
key,
Math.floor(Date.now() / 1000) + 50,
ExpireOptions.NewExpiryGreaterThanCurrent
)
).toEqual(true);
const version = await getVersion();
if (version[0] < 7 ) {
expect(
await client.expireAt(
key,
Math.floor(Date.now() / 1000) + 50
)
).toEqual(true);
}
else{
expect(
await client.expireAt(
key,
Math.floor(Date.now() / 1000) + 50,
ExpireOptions.NewExpiryGreaterThanCurrent
)
).toEqual(true);
}
expect(await client.ttl(key)).toBeLessThanOrEqual(50);

/// set command clears the timeout.
expect(await client.set(key, "bar")).toEqual("OK");
if (version[0] < 7 ) {
expect(
await client.pexpireAt(
key,
Date.now() + 50000,
ExpireOptions.HasExistingExpiry
Date.now() + 50000
)
).toEqual(false);
}
else{
expect(
await client.pexpireAt(
key,
Date.now() + 50000,
ExpireOptions.HasExistingExpiry
)
).toEqual(false);
}
});
},
config.timeout
Expand Down
1 change: 0 additions & 1 deletion python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ async def test_request_error_raises_exception(self, redis_client: TRedisClient):
@pytest.mark.parametrize("cluster_mode", [True, False])
async def test_info_server_replication(self, redis_client: TRedisClient):
info = get_first_result(await redis_client.info([InfoSection.SERVER]))
print(info)
assert "# Server" in info
cluster_mode = parse_info_response(info)["redis_mode"]
expected_cluster_mode = isinstance(redis_client, RedisClusterClient)
Expand Down

0 comments on commit 58c1721

Please sign in to comment.