diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2023-04-10 14:25:34 -0700 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2023-04-10 22:00:17 +0000 |
commit | 0075ebd83b49cee3edd86b3a40c2f89db3bd97f9 (patch) | |
tree | 9e924d4d7f5c18c214b593a46b1dbe2ae15a510f /tests/phpunit/includes/db/LBFactoryTest.php | |
parent | ca0e6ecc514f4a47f6bfee58290143e580b75021 (diff) | |
download | mediawikicore-0075ebd83b49cee3edd86b3a40c2f89db3bd97f9.tar.gz mediawikicore-0075ebd83b49cee3edd86b3a40c2f89db3bd97f9.zip |
objectcache,resourceloader,rdbms,jobqueue: Widen @covers annotations
Follows-up I4c7d826c7ec654b, I1287f3979aba1bf1.
We lose useful coverage and spend valuable time keeping these accurate
through refactors (or worse, forget to do so). The theoretically "bad"
accidental coverage is almost never actually bad.
Having said that, I'm not removing them wholesale (yet). I've audited
each of these specific files to confirm it is a general test of the
specified subject class, and also kept it limited to those specified
classes. That's imho more than 100% of the benefit for less than 1%
of the cost (more because `@covers` is more valuable than the fragile
and corrosive individual private method tracking in tests that
inevitably get out of date with no local incentive to keep them up to
date).
Cases like structure tests keep `@coversNothing` etc and we still don't
count coverage of other classes. There may be a handful of large
legacy classes where some methods are effectively class-like in
complexity and that's why it's good for PHPUnit to offer the precision
instrument but that doesn't meant we have to use that by-default for
everything.
I think best practice is to write good narrow unit tests, that reflect
how the code should be used in practice. Not to write bad tests and
hide part of its coverage within the same class or even namespace.
Fortunately, that's generally what we do already it's just that we
also kept these annotations still in many cases.
This wastes time to keep methods in sync, time to realize (and fix)
when other people inevitably didn't keep them in sync, time to find
uncovered code only to realize it is already covered, time for a less
experienced engineer to feel obligate to and do write a low quality
test to cover the "missing" branch in an unrealistic way, time wasted
in on-boarding by using such "bad" tests as example for how to use
the code and then having to unlearn it months/years later, loss of
telemetry in knowing what code actually isn't propertly tested due to
being masked by a bad test, and lost oppertunities to find actually
ununused/unreachable code and to think about how to instead structure
the code such that maybe that code can be removed.
------
Especially cases like LBFactoryTest.php were getting out of hand,
and in GlobalIdGeneratorTest.php we even resorted to reminding people
with inline comments to keep tags in sync.
Change-Id: I69b5385868cc6b451e5f2ebec9539694968bf58c
Diffstat (limited to 'tests/phpunit/includes/db/LBFactoryTest.php')
-rw-r--r-- | tests/phpunit/includes/db/LBFactoryTest.php | 51 |
1 files changed, 7 insertions, 44 deletions
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index 48cc8eef9ee9..80d86b3b0e28 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -1,7 +1,5 @@ <?php /** - * Holds tests for LBFactory abstract MediaWiki class. - * * 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 * the Free Software Foundation; either version 2 of the License, or @@ -39,9 +37,15 @@ use Wikimedia\TestingAccessWrapper; /** * @group Database + * @covers \Wikimedia\Rdbms\ChronologyProtector + * @covers \Wikimedia\Rdbms\DatabaseMysqlBase + * @covers \Wikimedia\Rdbms\DatabasePostgres + * @covers \Wikimedia\Rdbms\DatabaseSqlite + * @covers \Wikimedia\Rdbms\LBFactory * @covers \Wikimedia\Rdbms\LBFactory - * @covers \Wikimedia\Rdbms\LBFactorySimple * @covers \Wikimedia\Rdbms\LBFactoryMulti + * @covers \Wikimedia\Rdbms\LBFactorySimple + * @covers \Wikimedia\Rdbms\LoadBalancer */ class LBFactoryTest extends MediaWikiIntegrationTestCase { @@ -60,10 +64,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { ]; } - /** - * @covers \Wikimedia\Rdbms\LBFactory::getLocalDomainID() - * @covers \Wikimedia\Rdbms\LBFactory::resolveDomainID() - */ public function testLBFactorySimpleServer() { $servers = [ $this->getPrimaryServerConfig() ]; $factory = new LBFactorySimple( [ 'servers' => $servers ] ); @@ -394,10 +394,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { ] ); } - /** - * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection - * @covers \Wikimedia\Rdbms\DatabaseMysqlBase::doSelectDomain - */ public function testNiceDomains() { global $wgDBname; @@ -477,10 +473,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $factory->destroy(); } - /** - * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection - * @covers \Wikimedia\Rdbms\DatabaseMysqlBase::doSelectDomain - */ public function testTrickyDomain() { global $wgDBname; @@ -547,10 +539,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $factory->destroy(); } - /** - * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection - * @covers \Wikimedia\Rdbms\DatabaseMysqlBase::doSelectDomain - */ public function testInvalidSelectDB() { if ( wfGetDB( DB_PRIMARY )->databasesAreIndependent() ) { $this->markTestSkipped( "Not applicable per databasesAreIndependent()" ); @@ -571,10 +559,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $db->selectDomain( 'garbagedb' ); } - /** - * @covers \Wikimedia\Rdbms\DatabaseSqlite::doSelectDomain - * @covers \Wikimedia\Rdbms\DatabasePostgres::doSelectDomain - */ public function testInvalidSelectDBIndependent() { $dbname = 'unittest-domain'; // explodes if DB is selected $factory = $this->newLBFactoryMulti( @@ -596,10 +580,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $this->assertNotNull( $lb->getConnectionInternal( DB_PRIMARY, [], $lb::DOMAIN_ANY ) ); } - /** - * @covers \Wikimedia\Rdbms\DatabaseSqlite::doSelectDomain - * @covers \Wikimedia\Rdbms\DatabasePostgres::doSelectDomain - */ public function testInvalidSelectDBIndependent2() { $dbname = 'unittest-domain'; // explodes if DB is selected $factory = $this->newLBFactoryMulti( @@ -621,11 +601,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $db->selectDomain( 'garbage-db' ); } - /** - * @covers \Wikimedia\Rdbms\LoadBalancer::getConnection - * @covers \Wikimedia\Rdbms\LoadBalancer::redefineLocalDomain - * @covers \Wikimedia\Rdbms\DatabaseMysqlBase::doSelectDomain - */ public function testRedefineLocalDomain() { global $wgDBname; @@ -677,10 +652,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { } } - /** - * @covers \Wikimedia\Rdbms\LBFactory::makeCookieValueFromCPIndex() - * @covers \Wikimedia\Rdbms\LBFactory::getCPInfoFromCookieValue() - */ public function testCPPosIndexCookieValues() { $time = 1526522031; $agentId = md5( 'Ramsey\'s Loyal Presa Canario' ); @@ -746,10 +717,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { ); } - /** - * @covers \Wikimedia\Rdbms\LBFactory::setDomainAliases() - * @covers \Wikimedia\Rdbms\LBFactory::resolveDomainID() - */ public function testSetDomainAliases() { $lb = $this->newLBFactoryMulti(); $origDomain = $lb->getLocalDomainID(); @@ -766,10 +733,6 @@ class LBFactoryTest extends MediaWikiIntegrationTestCase { $this->assertEquals( "realdb-realprefix_", $lb->resolveDomainID( "alias-db-prefix_" ) ); } - /** - * @covers \Wikimedia\Rdbms\ChronologyProtector - * @covers \Wikimedia\Rdbms\LBFactory - */ public function testGetChronologyProtectorTouched() { $store = new HashBagOStuff; $lbFactory = $this->newLBFactoryMulti( [ |