feat(ticket): implement LoadTestTicketDatasetService for generating load test datasets
- Added LoadTestTicketDatasetService to prepare disposable scanner tickets and generate a Postman importable dataset.
- Introduced console command `load-test🎟️prepare` for executing the dataset preparation.
- Updated README documentation with usage instructions for the load test command.
- Enhanced Postman collection generation script to include new parameters.
- Created tests for the load test command to ensure proper functionality and validation.
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
||||
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
||||
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
||||
use App\Domains\Ticket\Services\LoadTestTicketDatasetService;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
@@ -24,6 +26,79 @@ Schedule::command('reservations:expire')
|
||||
->everyMinute()
|
||||
->withoutOverlapping();
|
||||
|
||||
Artisan::command(
|
||||
'load-test:tickets:prepare
|
||||
{tenant : Código de un tenant dedicado con prefijo loadtest-}
|
||||
{--tickets=1000 : Cantidad de tickets válidos}
|
||||
{--scanners=10 : Cantidad de identidades scanner}
|
||||
{--owners=100 : Cantidad de propietarios de tickets}
|
||||
{--catalog-item= : Producto estándar con tickets habilitados}
|
||||
{--variant= : Variante opcional que define la vigencia}
|
||||
{--run= : Identificador opcional de la ejecución}
|
||||
{--output= : Ruta relativa dentro del disco local}',
|
||||
function (LoadTestTicketDatasetService $datasetService): int {
|
||||
if (! app()->environment(['local', 'testing', 'staging', 'homo', 'homologation'])) {
|
||||
$this->error('Este comando sólo puede ejecutarse en local u homologación.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$requestedOutput = filled($this->option('output'))
|
||||
? ltrim((string) $this->option('output'), '/\\')
|
||||
: null;
|
||||
|
||||
if ($requestedOutput !== null
|
||||
&& ($requestedOutput === '' || str_contains(str_replace('\\', '/', $requestedOutput), '../'))) {
|
||||
$this->error('La ruta de salida debe permanecer dentro del disco local.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
$dataset = $datasetService->prepare(
|
||||
(string) $this->argument('tenant'),
|
||||
(int) $this->option('tickets'),
|
||||
(int) $this->option('scanners'),
|
||||
(int) $this->option('owners'),
|
||||
filled($this->option('catalog-item')) ? (int) $this->option('catalog-item') : null,
|
||||
filled($this->option('variant')) ? (int) $this->option('variant') : null,
|
||||
filled($this->option('run')) ? (string) $this->option('run') : null,
|
||||
);
|
||||
} catch (Throwable $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$relativePath = $requestedOutput !== null
|
||||
? $requestedOutput
|
||||
: "load-tests/{$dataset['run_id']}.postman.json";
|
||||
$payload = json_encode($dataset['rows'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
if (! is_string($payload) || ! Storage::disk('local')->put($relativePath, $payload.PHP_EOL)) {
|
||||
$this->error('No se pudo escribir el dataset.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('Dataset de carga generado.');
|
||||
$this->table(['Dato', 'Valor'], [
|
||||
['run_id', $dataset['run_id']],
|
||||
['tenant', $dataset['tenant_code']],
|
||||
['catalog_item_id', $dataset['catalog_item_id']],
|
||||
['variant_id', $dataset['variant_id'] ?? 'sin variante (vigencia irrestricta)'],
|
||||
['tickets', $dataset['tickets']],
|
||||
['scanners', $dataset['scanners']],
|
||||
['owners', $dataset['owners']],
|
||||
['archivo', Storage::disk('local')->path($relativePath)],
|
||||
]);
|
||||
$this->warn('El archivo contiene tokens secretos. No lo subas al repositorio.');
|
||||
$this->comment("Limpieza: php artisan tenants:reset-transactions {$dataset['tenant_code']}");
|
||||
|
||||
return self::SUCCESS;
|
||||
},
|
||||
)->purpose('Prepare disposable scanner tickets and a Postman performance dataset');
|
||||
|
||||
Artisan::command(
|
||||
'tenants:reset-transactions
|
||||
{tenant : Código del tenant que se limpiará}
|
||||
|
||||
Reference in New Issue
Block a user