1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Delete stale fixtures with bin/storage destroy

Summary:
When a PhabricatorTestCase dies after creating storage fixtures, it leaves
those storage fixtures around.  This doesn't happen often, but when it does
happen it's a pain to cleanup.  The --unittest-fixtures option helps automate
that cleanup.

Test Plan:
Ran it with --dryrun, then for real.  Became overwhelmed with a Zen like peace
after regarding the tidiness and beauty of SHOW DATABASES.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3858
This commit is contained in:
Edward Speyer 2012-10-31 18:36:38 -07:00
parent ae616e82d3
commit fe8351c930
2 changed files with 24 additions and 4 deletions

View file

@ -23,7 +23,14 @@ final class PhabricatorStorageManagementDestroyWorkflow
$this
->setName('destroy')
->setExamples('**destroy** [__options__]')
->setSynopsis('Permanently destroy all storage and data.');
->setSynopsis('Permanently destroy all storage and data.')
->setArguments(
array(
array(
'name' => 'unittest-fixtures',
'help' => "Restrict **destroy** operations to databases created ".
"by PhabricatorTestCase test fixtures.",
)));
}
public function execute(PhutilArgumentParser $args) {
@ -50,8 +57,20 @@ final class PhabricatorStorageManagementDestroyWorkflow
$api = $this->getAPI();
$patches = $this->getPatches();
$databases = $api->getDatabaseList($patches);
$databases[] = $api->getDatabaseName('meta_data');
if ($args->getArg('unittest-fixtures')) {
$conn = $api->getConn(null, false);
$databases = queryfx_all(
$conn,
'SELECT DISTINCT(TABLE_SCHEMA) AS db '.
'FROM INFORMATION_SCHEMA.TABLES '.
'WHERE TABLE_SCHEMA LIKE %>',
PhabricatorTestCase::NAMESPACE_PREFIX);
$databases = ipull($databases, 'db');
} else {
$databases = $api->getDatabaseList($patches);
$databases[] = $api->getDatabaseName('meta_data');
}
foreach ($databases as $database) {
if ($is_dry) {
echo "DRYRUN: Would drop database '{$database}'.\n";

View file

@ -18,6 +18,7 @@
abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
const NAMESPACE_PREFIX = 'phabricator_unittest_';
/**
* If true, put Lisk in process-isolated mode for the duration of the tests so
@ -132,7 +133,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
protected function newStorageFixture() {
$bytes = Filesystem::readRandomCharacters(24);
$name = 'phabricator_unittest_'.$bytes;
$name = self::NAMESPACE_PREFIX.$bytes;
return new PhabricatorStorageFixtureScopeGuard($name);
}