Skip to content

Commit e7df505

Browse files
authored
Postgres Unish fixes (#3826)
* A postgres test fix and better error reporting * Adjust time of crontab
1 parent 9065f93 commit e7df505

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ workflows:
149149
triggers:
150150
- schedule:
151151
# Uses UTC timezone.
152-
cron: "17 21 * * *"
152+
cron: "35 15 * * *"
153153
filters:
154154
branches:
155155
only:

src/Sql/SqlPgsql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function dbExists()
9393
$db_spec_no_db = $dbSpec;
9494
unset($db_spec_no_db['database']);
9595
$sql_no_db = new SqlPgsql($db_spec_no_db, $this->getOptions());
96-
$query = "SELECT 1 AS result FROM pg_database WHERE datname='\''$database'\'''";
96+
$query = "SELECT 1 AS result FROM pg_database WHERE datname='$database'";
9797
$process = Drush::process($sql_no_db->connect() . ' -t -c ' . $query);
9898
$process->setSimulated(false);
9999
$process->run();

tests/functional/SqlConnectCreateTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function testSqlConnect()
3434
$this->markTestSkipped('sql-connect test does not recognize database type in ' . self::getDbUrl());
3535
}
3636

37+
if ($db_driver == 'pgsql') {
38+
$this->markTestSkipped('Postgres prepends PGPASSFILE=/var/www/html/sandbox/tmp/drush_[RANDOM] and that file got deleted already.');
39+
}
40+
3741
// Issue a query and check the result to verify the connection.
3842
$this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_SUCCESS, $this->webroot());
3943
$output = $this->getOutput();
@@ -50,7 +54,7 @@ public function testSqlConnect()
5054
$this->drush('sql-create');
5155

5256
// Try to execute a query. This should give a "table not found" error.
53-
$this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_ERROR);
57+
$this->execute($connectionString . ' ' . $shell_options . ' "SELECT uid FROM users where uid = 1;"', self::EXIT_ERROR, $this->webroot());
5458

5559
// We should still be able to run 'core-status' without getting an
5660
// error, although Drupal should not bootstrap any longer.

tests/unish/CommandUnishTestCase.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ abstract class CommandUnishTestCase extends UnishTestCase
1818
*/
1919
protected $coverage_data = [];
2020

21-
/**
22-
* Process of last executed command.
23-
*
24-
* @var Process
25-
*/
26-
private $process;
27-
2821
/**
2922
* Default timeout for commands.
3023
*
@@ -144,32 +137,6 @@ public function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = n
144137
}
145138
}
146139

147-
/**
148-
* Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException
149-
*
150-
* @return string
151-
*/
152-
public function buildProcessMessage()
153-
{
154-
$error = sprintf(
155-
"%s\n\nExit Code: %s(%s)\n\nWorking directory: %s",
156-
$this->process->getCommandLine(),
157-
$this->process->getExitCode(),
158-
$this->process->getExitCodeText(),
159-
$this->process->getWorkingDirectory()
160-
);
161-
162-
if (!$this->process->isOutputDisabled()) {
163-
$error .= sprintf(
164-
"\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
165-
$this->process->getOutput(),
166-
$this->process->getErrorOutput()
167-
);
168-
}
169-
170-
return $error;
171-
}
172-
173140
/**
174141
* Invoke drush in via execute().
175142
*

tests/unish/UnishTestCase.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ abstract class UnishTestCase extends TestCase
1717
const UNISH_EXITCODE_USER_ABORT = 75; // Same as DRUSH_EXITCODE_USER_ABORT
1818
const INTEGRATION_TEST_ENV = 'default';
1919

20+
/**
21+
* Process of last executed command.
22+
*
23+
* @var Process
24+
*/
25+
protected $process;
26+
2027
/**
2128
* A list of Drupal sites that have been recently installed. They key is the
2229
* site name and values are details about each site.
@@ -553,7 +560,7 @@ public function createSettings($subdir)
553560
file_put_contents($settingsPath, $settingsContents);
554561
}
555562
/**
556-
* Assemble (and optionally install) one or more Drupal sites using a single codebase.
563+
* Prepare (and optionally install) one or more Drupal sites using a single codebase.
557564
*
558565
* It is no longer supported to pass alternative versions of Drupal or an alternative install_profile.
559566
*/
@@ -668,11 +675,15 @@ protected function installSut($uri = self::INTEGRATION_TEST_ENV, $optionsFromTes
668675
'yes' => true,
669676
'quiet' => true,
670677
];
678+
if ($level = $this->logLevel()) {
679+
$options[$level] = true;
680+
}
671681
$process = new SiteProcess($sutAlias, [self::getDrush(), 'site:install', 'testing', 'install_configure_form.enable_update_status_emails=NULL'], $options);
672682
// Set long timeout because Xdebug slows everything.
673683
$process->setTimeout(0);
684+
$this->process = $process;
674685
$process->run();
675-
$this->assertTrue($process->isSuccessful(), 'Could not install SUT. Options: ' . var_export($optionsFromTest, true) . "\nStdout:\n" . $process->getOutput() . "\n\nStderr:\n" . $process->getErrorOutput());
686+
$this->assertTrue($process->isSuccessful(), $this->buildProcessMessage());
676687

677688
// Give us our write perms back.
678689
chmod($this->webroot() . "/sites/$uri", 0777);
@@ -700,4 +711,30 @@ public static function setEnv(array $vars)
700711
$_SERVER[$k]= (string) $v;
701712
}
702713
}
714+
715+
/**
716+
* Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException
717+
*
718+
* @return string
719+
*/
720+
public function buildProcessMessage()
721+
{
722+
$error = sprintf(
723+
"%s\n\nExit Code: %s(%s)\n\nWorking directory: %s",
724+
$this->process->getCommandLine(),
725+
$this->process->getExitCode(),
726+
$this->process->getExitCodeText(),
727+
$this->process->getWorkingDirectory()
728+
);
729+
730+
if (!$this->process->isOutputDisabled()) {
731+
$error .= sprintf(
732+
"\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
733+
$this->process->getOutput(),
734+
$this->process->getErrorOutput()
735+
);
736+
}
737+
738+
return $error;
739+
}
703740
}

0 commit comments

Comments
 (0)