Skip to content
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

Improve CI tests reliability for ImportCommandsTest #2346

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions tests/Functional/BackupCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testAutomaticBackupInfoEnableDisable()
$siteEnv = $this->getSiteEnv();

$this->terminus(sprintf('backup:automatic:disable %s', $siteEnv));
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($siteEnv) {
$this->assertCallbackResultEqualsInAttempts(function () use ($siteEnv) {
return $this->terminusJsonResponse(sprintf('backup:automatic:info %s', $siteEnv));
}, [
'daily_backup_hour' => null,
Expand All @@ -79,7 +79,7 @@ public function testAutomaticBackupInfoEnableDisable()
]);

$this->terminus(sprintf('backup:automatic:enable %s', $siteEnv));
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($siteEnv) {
$this->assertCallbackResultEqualsInAttempts(function () use ($siteEnv) {
// Count non-empty elements in the result which is expected to be exactly 3
// ("daily_backup_hour", "weekly_backup_day" and "expiry").
return count(array_filter($this->terminusJsonResponse(sprintf('backup:automatic:info %s', $siteEnv))));
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/EnvCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testCommitAndDiffStatCommands()
'additions' => '1',
],
];
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($siteEnv) {
$this->assertCallbackResultEqualsInAttempts(function () use ($siteEnv) {
return $this->terminusJsonResponse(sprintf('env:diffstat %s', $siteEnv));
}, $expectedDiff);

Expand All @@ -135,7 +135,7 @@ public function testCommitAndDiffStatCommands()
sleep(60);

// Check the diff - no diff is expected.
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($siteEnv) {
$this->assertCallbackResultEqualsInAttempts(function () use ($siteEnv) {
return $this->terminusJsonResponse(sprintf('env:diffstat %s', $siteEnv));
}, []);
}
Expand Down
11 changes: 5 additions & 6 deletions tests/Functional/ImportCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ public function testImportSiteCommand()
$this->assertNotEmpty($importedSiteInfo);

// Import the site from the archive file.
$this->terminus(
sprintf(
'import:site %s %s',
$this->importedSiteName,
'https://dev-site-archive-d7.pantheonsite.io/sites/default/files/site-archive-d7.tar.gz'
)
$siteImportCommand = sprintf(
'import:site %s %s',
$this->importedSiteName,
'https://dev-site-archive-d7.pantheonsite.io/sites/default/files/site-archive-d7.tar.gz'
);
$this->assertTerminusCommandSucceedsInAttempts($siteImportCommand);
sleep(60);

// Verify that the code and the database have been imported.
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/LockCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testLockCommands()

// Verify the lock is disabled.
$getLockInfoCommand = sprintf('lock:info %s', $this->getSiteEnv());
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($getLockInfoCommand) {
$this->assertCallbackResultEqualsInAttempts(function () use ($getLockInfoCommand) {
return $this->terminusJsonResponse($getLockInfoCommand);
}, [
'locked' => false,
Expand All @@ -48,7 +48,7 @@ public function testLockCommands()
$this->terminus($enableLockInfoCommand);

// Verify the lock is enabled.
$this->assertTerminusCommandResultEqualsInAttempts(function () use ($getLockInfoCommand) {
$this->assertCallbackResultEqualsInAttempts(function () use ($getLockInfoCommand) {
return $this->terminusJsonResponse($getLockInfoCommand);
}, [
'locked' => true,
Expand Down
10 changes: 5 additions & 5 deletions tests/Functional/TerminusTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ protected function terminusJsonResponse($command)
}

/**
* Asserts terminus command execution result is equal to the expected in multiple attempts.
* Asserts the callback result is equal to the expected value in multiple attempts.
*
* @param callable $callable
* The callable which provides the actual terminus command execution result.
* The callable to return an actual value.
* @param mixed $expected
* The expected result.
* The expected value.
* @param int $attempts
* The maximum number of attempts.
* @param int $intervalSeconds
* The interval between attempts in seconds.
*/
protected function assertTerminusCommandResultEqualsInAttempts(
protected function assertCallbackResultEqualsInAttempts(
callable $callable,
$expected,
int $attempts = 24,
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function assertTerminusCommandResultEqualsInAttempts(
*/
protected function assertTerminusCommandSucceedsInAttempts(string $command, int $attempts = 3): void
{
$this->assertTerminusCommandResultEqualsInAttempts(
$this->assertCallbackResultEqualsInAttempts(
fn() => static::callTerminus(sprintf('%s --yes', $command))[1],
0,
$attempts
Expand Down