Skip to content

Commit

Permalink
(tests) Update benchmark scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Jan 3, 2025
1 parent c530c44 commit 68ff402
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 30 deletions.
1 change: 1 addition & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# and we don't want it basing its assumptions on testsuite code when checking the main code.
$cfg['directory_list'][] = 'tests/phpunit';
$cfg['directory_list'][] = 'tests/common';
$cfg['directory_list'][] = 'tests/benchmark';

# PHPUnit classes, etc. Should be parsed, but not analyzed.
$cfg['directory_list'][] = $IP . '/tests';
Expand Down
14 changes: 12 additions & 2 deletions tests/benchmarks/ModerationBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2023 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,10 +20,20 @@
* Parent class for benchmark scripts.
*/

require_once __DIR__ . '/../common/ModerationTestUtil.php';
namespace MediaWiki\Moderation\Tests;

use CommentStoreComment;
use ContentHandler;
use Maintenance;
use MediaWiki\MediaWikiServices;
use MediaWiki\Moderation\ModerationCompatTools;
use MediaWiki\Moderation\ModerationNewChange;
use MediaWiki\Revision\SlotRecord;
use Status;
use Title;
use User;

require_once __DIR__ . '/../common/ModerationTestUtil.php';

abstract class ModerationBenchmark extends Maintenance {
/**
Expand Down
14 changes: 10 additions & 4 deletions tests/benchmarks/approveAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,15 @@
* Benchmark: how fast is ApproveAll on Special:Moderation?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/approveAll.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/approveAll.php
*/

namespace MediaWiki\Moderation\Tests;

use DeferredUpdates;
use MediaWiki\Moderation\ModerationCompatTools;
use User;
use Wikimedia\Assert\Assert;
use Wikimedia\IPUtils;

require_once __DIR__ . '/ModerationBenchmark.php';
Expand Down Expand Up @@ -98,12 +104,12 @@ public function doActualWork( $i ) {
// Run the DeferredUpdates
DeferredUpdates::doUpdates();

Wikimedia\Assert\Assert::postcondition(
Assert::postcondition(
( strpos( $html, '(moderation-approved-ok: ' . $this->getEditsPerUser() . ')' ) !== false ),
'ApproveAll failed'
);
}
}

$maintClass = 'BenchmarkApproveAll';
$maintClass = BenchmarkApproveAll::class;
require RUN_MAINTENANCE_IF_MAIN;
12 changes: 8 additions & 4 deletions tests/benchmarks/approveEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,13 @@
* Benchmark: how fast is Approve on Special:Moderation?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/approveEdit.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/approveEdit.php
*/

namespace MediaWiki\Moderation\Tests;

use Wikimedia\Assert\Assert;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkApproveEdit extends ModerationBenchmark {
Expand Down Expand Up @@ -65,12 +69,12 @@ public function doActualWork( $i ) {
'token' => $this->getUser()->getEditToken()
] );

Wikimedia\Assert\Assert::postcondition(
Assert::postcondition(
( strpos( $html, '(moderation-approved-ok: 1)' ) !== false ),
'Approve failed'
);
}
}

$maintClass = 'BenchmarkApproveEdit';
$maintClass = BenchmarkApproveEdit::class;
require RUN_MAINTENANCE_IF_MAIN;
10 changes: 7 additions & 3 deletions tests/benchmarks/formatTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@

/**
* @file
* Benchmark: how fast is TimestampTools)?
* Benchmark: how fast is TimestampTools::format()?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/formatTimestamp.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/formatTimestamp.php
*/

require_once __DIR__ . '/ModerationBenchmark.php';
namespace MediaWiki\Moderation\Tests;

use IContextSource;
use MediaWiki\Moderation\TimestampTools;
use RequestContext;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkFormatTimestamp extends ModerationBenchmark {

Expand Down
12 changes: 8 additions & 4 deletions tests/benchmarks/queueEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,13 @@
* Benchmark: how fast are edits queued for moderation?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/queueEdit.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/queueEdit.php
*/

namespace MediaWiki\Moderation\Tests;

use Wikimedia\Assert\Assert;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkQueueEdit extends ModerationBenchmark {
Expand All @@ -36,12 +40,12 @@ public function doActualWork( $i ) {
'Test summary ' . $i
);

Wikimedia\Assert\Assert::postcondition(
Assert::postcondition(
( $status->getMessage()->getKey() == 'moderation-edit-queued' ),
'Edit not queued'
);
}
}

$maintClass = 'BenchmarkQueueEdit';
$maintClass = BenchmarkQueueEdit::class;
require RUN_MAINTENANCE_IF_MAIN;
14 changes: 9 additions & 5 deletions tests/benchmarks/queueMove.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,13 +20,17 @@
* Benchmark: how fast are moves queued for moderation?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/queueMove.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/queueMove.php
*/

require_once __DIR__ . '/ModerationBenchmark.php';
namespace MediaWiki\Moderation\Tests;

use MediaWiki\MediaWikiServices;
use MediaWiki\Page\MovePageFactory;
use Title;
use Wikimedia\Assert\Assert;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkQueueMove extends ModerationBenchmark {
/** @var MovePageFactory */
Expand Down Expand Up @@ -70,12 +74,12 @@ public function doActualWork( $i ) {
);
$status = $mp->move( $this->getUser(), 'Reason for moving #' . $i );

Wikimedia\Assert\Assert::postcondition(
Assert::postcondition(
( $status->getMessage()->getKey() == 'moderation-move-queued' ),
'Move not queued'
);
}
}

$maintClass = 'BenchmarkQueueMove';
$maintClass = BenchmarkQueueMove::class;
require RUN_MAINTENANCE_IF_MAIN;
8 changes: 5 additions & 3 deletions tests/benchmarks/renderSpecial.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,11 @@
* Benchmark: how fast is HTML of Special:Moderation generated?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/renderSpecial.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/renderSpecial.php
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkRenderSpecial extends ModerationBenchmark {
Expand Down Expand Up @@ -67,5 +69,5 @@ public function doActualWork( $i ) {
}
}

$maintClass = 'BenchmarkRenderSpecial';
$maintClass = BenchmarkRenderSpecial::class;
require RUN_MAINTENANCE_IF_MAIN;
14 changes: 9 additions & 5 deletions tests/benchmarks/showEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Extension:Moderation - MediaWiki extension.
Copyright (C) 2018-2024 Edward Chernenko.
Copyright (C) 2018-2025 Edward Chernenko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,13 @@
* Benchmark: how fast is Show on Special:Moderation?
*
* Usage:
* php maintenance/runScript.php extensions/Moderation/tests/benchmarks/showEdit.php
* php maintenance/run.php `pwd`/extensions/Moderation/tests/benchmarks/showEdit.php
*/

namespace MediaWiki\Moderation\Tests;

use Wikimedia\Assert\Assert;

require_once __DIR__ . '/ModerationBenchmark.php';

class BenchmarkShowEdit extends ModerationBenchmark {
Expand Down Expand Up @@ -50,7 +54,7 @@ public function beforeBenchmark( $numberOfLoops ) {
$this->fastEdit( $this->getTestTitle(), self::TEXT_BEFORE );
$this->id = $this->fastQueue( $this->getTestTitle(), self::TEXT_AFTER );

$this->getUser()->addGroup( 'moderator' );
$this->becomeModerator();
}

/**
Expand All @@ -62,12 +66,12 @@ public function doActualWork( $i ) {
'modid' => $this->id
] );

Wikimedia\Assert\Assert::postcondition(
Assert::postcondition(
( strpos( $html, 'Text before</del>' ) !== false ),
'Unexpected output from modaction=show'
);
}
}

$maintClass = 'BenchmarkShowEdit';
$maintClass = BenchmarkShowEdit::class;
require RUN_MAINTENANCE_IF_MAIN;

0 comments on commit 68ff402

Please sign in to comment.