1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Add "--force" and "--quickly" flags to bin/lipsum

Summary:
Ref T12319.

  - Lipsum can trash an install by creating a lot of junk that's hard to get rid of, so we're cautious about letting you run it. Add a `--force` flag if you're sure you know what you're doing. This makes the edit/test cycle a bit easier when actually writing Lipsum generators.
  - Lipsum normally sleeps for a second before creating objects, to give users more control over how much stuff they create and limit the amount of damage caused by mistakes. Sometimes, you want to generate a LOT of stuff because you want to reproduce a performance/scale issue (like T12319). Add a `--quickly` flag to generate objects as fast as possible.
  - When loading random users (used as authors, assignees, etc), also load user settings so we can `ConduitCall` with them.
  - Allow generators to return a PHID instead of an actual object (more convenient for Conduit-based generators).

Test Plan:
  - With next change, ran `lipsum generate badges --force --quickly`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12319

Differential Revision: https://secure.phabricator.com/D17421
This commit is contained in:
epriestley 2017-02-27 05:10:25 -08:00
parent 99bcf5f112
commit 3b8ccb0b78
2 changed files with 40 additions and 18 deletions

View file

@ -45,6 +45,7 @@ abstract class PhabricatorTestDataGenerator extends Phobject {
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($user_phid))
->needUserSettings(true)
->executeOne();
}
@ -115,5 +116,4 @@ abstract class PhabricatorTestDataGenerator extends Phobject {
return $this->loadOneRandom('PhabricatorUser');
}
}

View file

@ -10,6 +10,17 @@ final class PhabricatorLipsumGenerateWorkflow
->setSynopsis(pht('Generate synthetic test objects.'))
->setArguments(
array(
array(
'name' => 'force',
'short' => 'f',
'help' => pht(
'Generate objects without prompting for confirmation.'),
),
array(
'name' => 'quickly',
'help' => pht(
'Generate objects as quickly as possible.'),
),
array(
'name' => 'args',
'wildcard' => true,
@ -34,6 +45,9 @@ final class PhabricatorLipsumGenerateWorkflow
->execute();
$argv = $args->getArg('args');
$is_force = $args->getArg('force');
$is_quickly = $args->getArg('quickly');
$all = 'all';
if (isset($all_generators[$all])) {
@ -125,20 +139,22 @@ final class PhabricatorLipsumGenerateWorkflow
'Selected generators: %s.',
implode(', ', mpull($generators, 'getGeneratorName'))));
echo tsprintf(
"**<bg:yellow> %s </bg>** %s\n",
pht('WARNING'),
pht(
'This command generates synthetic test data, including user '.
'accounts. It is intended for use in development environments '.
'so you can test features more easily. There is no easy way to '.
'delete this data or undo the effects of this command. If you run '.
'it in a production environment, it will pollute your data with '.
'large amounts of meaningless garbage that you can not get rid of.'));
if (!$is_force) {
echo tsprintf(
"**<bg:yellow> %s </bg>** %s\n",
pht('WARNING'),
pht(
'This command generates synthetic test data, including user '.
'accounts. It is intended for use in development environments so '.
'you can test features more easily. There is no easy way to delete '.
'this data or undo the effects of this command. If you run it in a '.
'production environment, it will pollute your data with large '.
'amounts of meaningless garbage that you can not get rid of.'));
$prompt = pht('Are you sure you want to generate piles of garbage?');
if (!phutil_console_confirm($prompt, true)) {
return;
$prompt = pht('Are you sure you want to generate piles of garbage?');
if (!phutil_console_confirm($prompt, true)) {
return;
}
}
echo tsprintf(
@ -148,10 +164,10 @@ final class PhabricatorLipsumGenerateWorkflow
'Generating synthetic test objects forever. '.
'Use ^C to stop when satisfied.'));
$this->generate($generators);
$this->generate($generators, $is_quickly);
}
protected function generate(array $generators) {
protected function generate(array $generators, $is_quickly) {
$viewer = $this->getViewer();
foreach ($generators as $generator) {
@ -178,7 +194,11 @@ final class PhabricatorLipsumGenerateWorkflow
continue;
}
$object_phid = $object->getPHID();
if (is_string($object)) {
$object_phid = $object;
} else {
$object_phid = $object->getPHID();
}
$handles = $viewer->loadHandles(array($object_phid));
@ -189,7 +209,9 @@ final class PhabricatorLipsumGenerateWorkflow
$handles[$object_phid]->getTypeName(),
$handles[$object_phid]->getFullName()));
sleep(1);
if (!$is_quickly) {
sleep(1);
}
}
}