8000 Refactor session tests by michael-grunder · Pull Request #2492 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

Refactor session tests #2492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor session tests
* Update these external scripts to take formal arguments with `getopt` to
  make it more straightforward what each of the currently positional
  arguments are actually for.

* Create small helper classes for invoking these external scripts.
  Instead of `startSessionProcess` that takes a dozen argument all but
  three of which have defaults, we can use a construct like this:

  ```php
  $runner = $this->sessionRunner()
      ->max_execution_time(300)
      ->locking_enabled(true)
      ->lock_wait_time(-1)
      ->lock_expires(0)
      ->data($data)
      ->compression($name);

  // Invokes startSession.php with above args.
  $result = $runner->exec_fg();

  // Invokes regenerateSessionId.php with above args
  $new_id = $runner->regenerate_id();

  // Invokes getSessionData.php for this session ID.
  $data = $runner->get_data();
  ```

* Add a bit of logic to TestSuite to dump more information about the
  source of an assertion to make it easier to track down problems when
  we assert outside of a top level public `test_*` method.

* Create a few new assertions like `assertKeyExists` and
  `assertKeyMissing` which will generate much nicer assertions as
  opposed to

```php
$this->assertTrue($this->redis->exists($some_key));
```

* If our externally spawned session scripts fail output the exact call
  that was made along with all arguments as well as the output that we
  received to make it easier to narrow down.
  • Loading branch information
michael-grunder committed May 22, 2024
commit b2586105ff1ba92c500d4c53611ade96e58d7f33
30 changes: 14 additions & 16 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ class Redis_Cluster_Test extends Redis_Test {
];

protected static $_arr_node_map = [];
/**
* @var string
*/
protected $sessionPrefix = 'PHPREDIS_CLUSTER_SESSION:';

/**
* @var string
*/
protected $sessionSaveHandler = 'rediscluster';

/* Tests we'll skip all together in the context of RedisCluster. The
* RedisCluster class doesn't implement specialized (non-redis) commands
Expand Down Expand Up @@ -709,12 +700,14 @@ public function testAcl() {
public function testSession()
{
@ini_set('session.save_handler', 'rediscluster');
@ini_set('session.save_path', $this->getFullHostPath() . '&failover=error');
@ini_set('session.save_path', $this->sessionSavePath() . '&failover=error');

if (!@session_start()) {
return $this->markTestSkipped();
}
session_write_close();
$this->assertTrue($this->redis->exists('PHPREDIS_CLUSTER_SESSION:' . session_id()));

$this->assertKeyExists($this->sessionPrefix() . session_id());
}


Expand Down Expand Up @@ -748,16 +741,21 @@ public function testConnectionPool() {
ini_set('redis.pconnect.pooling_enabled', $prev_value);
}

protected function sessionPrefix(): string {
return 'PHPREDIS_CLUSTER_SESSION:';
}

protected function sessionSaveHandler(): string {
return 'rediscluster';
}

/**
* @inheritdoc
*/
protected function getFullHostPath()
{
$auth = $this->getAuthFragment();

protected function sessionSavePath(): string {
return implode('&', array_map(function ($host) {
return 'seed[]=' . $host;
}, self::$_arr_node_map)) . ($auth ? "&$auth" : '');
}, self::$_arr_node_map)) . '&' . $this->getAuthFragment();
}

/* Test correct handling of null multibulk replies */
Expand Down
Loading
0