Skip to content

Commit

Permalink
pool challenge doesn't need cryptographic security
Browse files Browse the repository at this point in the history
* Use PHP's regular php_rand() function instead of mt_rand() because we
don't need cryptographic security for the test, and mt_rand() will seed
for us if it's unseeded.

* Adds a cluster test that should retreive connections from the pool.
  • Loading branch information
michael-grunder committed Feb 19, 2020
1 parent 0cee8f7 commit 9ef2ed8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 1 addition & 5 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,11 +1813,7 @@ redis_sock_check_liveness(RedisSock *redis_sock)
}

gettimeofday(&tv, NULL);
if (!BG(mt_rand_is_seeded)) {
php_mt_srand(GENERATE_SEED());
}

uniqid_len = snprintf(uniqid, sizeof(uniqid), "phpredis_pool:%08lx%05lx:%08" PRIx32, (long)tv.tv_sec, (long)tv.tv_usec, php_mt_rand());
uniqid_len = snprintf(uniqid, sizeof(uniqid), "phpredis_pool:%08lx%05lx:%08lx", (long)tv.tv_sec, (long)tv.tv_usec, (long)php_rand());
redis_cmd_init_sstr(&cmd, 1, "ECHO", sizeof("ECHO") - 1);
redis_cmd_append_sstr(&cmd, uniqid, uniqid_len);
smart_string_0(&cmd);
Expand Down
15 changes: 15 additions & 0 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,21 @@ public function testSlotCache() {
ini_set('redis.clusters.cache_slots', 0);
}

/* Regression test for connection pool liveness checks */
public function testConnectionPool() {
$prev_value = ini_get('redis.pconnect.pooling_enabled');
ini_set('redis.pconnect.pooling_enabled', 1);

$pong = 0;
for ($i = 0; $i < 10; $i++) {
$obj_rc = new RedisCluster(NULL, self::$_arr_node_map, 30, 30, true);
$pong += $obj_rc->ping("key:$i");
}

$this->assertEquals($pong, $i);
ini_set('redis.pconnect.pooling_enabled', $prev_value);
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 9ef2ed8

Please sign in to comment.