aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/config/EtcdConfigTest.php
Commit message (Collapse)AuthorAgeFilesLines
* Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-101-0/+1
| | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* Merge "config: Use stale cache instead of hard fail on "no retry" fetch error"jenkins-bot2024-05-211-1/+7
|\
| * config: Use stale cache instead of hard fail on "no retry" fetch errorTimo Tijhof2024-05-051-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Inspired by investigation for T349376 and T346971, although not currently known to happen in production. If the backend fetch fails with an error and an HTTP status code that tells us not to re-try again in the same process, this shouldn't affect whether or not we use the stale data. Due to this line doing an early return for non-retryable errors, it was bypassing the code below this where is_array results in stale cache being used. Note that $data is only re-assigned from the cache hit in case of a non-error etcd response. The added test fails (expected: from-cache-expired, actual: error) if the EtcdConfig change is not applied. Change-Id: I9b85c206d929706d692bb46efe034be943156031
* | Add namespace and deprecation alias to MultiHttpClientEbrahim Byagowi2024-05-201-0/+1
|/ | | | | | | | | This patch introduces a namespace declaration for the Wikimedia\Http to MultiHttpClient and establishes a class alias marked as deprecated since version 1.43. Bug: T353458 Change-Id: I4ebc1a3b496de08b2b430301da376578d13fcfe6
* config: Abstract test matrix for EtcdConfigTimo Tijhof2024-03-271-191/+107
| | | | | | | This is in prep for the next change which improves an existing scenario, and also encourages and makes easier to add other scenarios. Change-Id: I8610b7eb19502cb76da46891f1f85ba911f79567
* tests: Add replacement for assertions deprecated in PHPUnit 9.6Daimona Eaytoy2024-02-231-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | expectWarning() and friends have been deprecated in PHPUnit 9.6, and removed in PHPUnit 10. Unfortunately, there is no simple replacement because PHPUnit no longer converts them to exceptions in the first place. In fact, Sebastian Bergmann explicitly stated that he does not consider the use case of > a library developer to verify a code block warns its consumer when > certain action is performed worth supporting. So, add an ad-hoc replacement for all the deprecated methods. This is quite ugly, but it's simple enough given the low number of usages. On the bright side, this new method does not halt the test when the warning is triggered. This seems to align with the developers' expectation, seen in a few existing tests, that any code following the notice will be executed. Bug: T342110 Change-Id: I214abfed4280834840c115777ed78eb0a5570da9
* Bump codesniffer to 42.0.0Amir Sarabadani2023-09-271-2/+2
| | | | | | Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray. Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
* config: replace unused Logger in EtcdConfig with native trigger_errorTimo Tijhof2023-09-261-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | Introduced in 9b459d29e0 (I60914d31c2, T156924) and later extended in cde44feba3 (Ic5bdcb0cae). There is no details about the fatal error in Logstash, because EtcdConfig is by design a standalone class for use prior to any service wiring, site configuration, or logger Spi can be used. That's why EtcdConfig::setLogger() is unused and thus even the "error" level messages go nowhere (NullLogger). Rewrite these messages to instead surface via the native PHP error log, the same way that our first-party and third-party standalone libraries do, and as we do with deprecation warnings already. Given that there isn't a way to inject this into MultiHttpClient, we lose that visibility. However, not really because again setLogger was never called in practice. And, the only error message MultiHttpClient logs is the HTTP request failure, which is already returned by $this->http->run() as $rerr to EtcdConfig and logged by this patch. Bug: T346971 Change-Id: I227ead395513877da88dd8b8abbd5ba7be25d5c7
* Namespace Config-related classes under \MediaWiki\ConfigJames D. Forrester2023-09-211-2/+4
| | | | | Bug: T166010 Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
* config: Widen `@covers` annotations in unit testsTimo Tijhof2023-07-241-63/+3
| | | | | | | | | | | | | | | | | | | | | | | Follows-up I7555c9b6b510, I6d845bdfbb80, I69b5385868, I4c7d826c7e, I1287f3979ab, which widened the `@covers` annotations of other suites: > We lose useful coverage and spend valuable time keeping these tags > accurate through refactors (or worse, forget to do so). > > I've audited each test to confirm it is a general test of the > subject class, where adding any called methods would be an accepted > change, thus widening it is merely a no-op that clarifies intent > and reduces maintenance. I am not disabling the "only track coverage > of specified subject" benefits, nor am I claiming coverage in > in classes outside the subject under test. > > Tracking tiny details per-method wastes time in keeping references > in sync during refactors, time to realize (and fix) when people > inevitably don't keep them in sync, time lost in finding uncovered > code to write tests for only to realize it was already covered but > not yet claimed, etc. Change-Id: Ie3d6a2b4e79b6aa0dc1d2414a3ae7e2bad209c7b
* Replace trivial usa of mock builder with createMock() shortcutThiemo Kreuz2022-07-151-18/+6
| | | | | | | | | | | createMock() does the same, but is much easier to read. A small difference is that some of the replacements made in this patch didn't use disableOriginalConstructor() before. In case this was relevant we should see the respective test fail. If not we can save some CPU cycles and skip these constructors. Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
* Simplify DnsSrvDiscoverer interfaceDan Duvall2022-02-161-2/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor DnsSrvDiscoverer constructor to accept service, protocol, and domain as discrete arguments to better match the specifications outlined in RFC 2782 and make clearer the concerns and contract between the discoverer and the caller. The latter should not need to know about discovery details but only the service to be discovered and the scope of that discovery (the domain). Domain is now optional where an omitted value results in discovery relative to the host's configured search domain, supporting installations where full DNS based discovery is desired over explicit configuration. This makes the simplest use case: $servers = ( new DnsSrvDiscoverer( 'service' ) )->getServers(); Overall use of the interface is simplified by changing `getServers()` to unconditionally sort results by priority according to RFC 2872 and return a simplified result of host/port tuples (the only data relevant in primary discovery use cases). This makes the handling of discovery fallback simpler since the caller can construct a default without having to populate all response record details. Example $dsd = new DnsSrvDiscoverer( $service, $proto, $host ); $servers = $dsd->getServers() ?: [ [ $host, $defaultPort ] ]; A `getRecords()` method is provided as public to allow a caller to obtain details on the response (and do its own sorting) should that be needed. Added an optional `$resolver` argument to the constructor (which defaults to `dns_get_record`) to make the class implementation more testable, and wrote functional tests. EtcdConfig has been refactored to reflect the new usage of DnsSrvDiscoverer and now sets the discoverer as a property in the constructor to allow for mocking in tests. Implemented tests for etcd DNS SRV discovery within EtcdConfig. Bug: T296771 Change-Id: Idbd60049853439f96ff6045e01aa03014b4e587f
* phpunit: Mass-replace setMethods with onlyMethods and adjustDaimona Eaytoy2021-04-161-10/+10
| | | | | | | | | | | | Ended up using grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g' special-casing setMethods( null ) -> onlyMethods( [] ) and then manual fix of failing test (from PS2 onwards). Bug: T278010 Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
* Cleanup of old PHPUnit usage, part 2Max Semenik2019-10-041-2/+2
| | | | | | Bug: T192167 Bug: T234597 Change-Id: Ifec7f02f64d6613dbfa1878007f68c2e411a83dc
* Move unit tests, round IIIAmir Sarabadani2019-07-091-0/+618
| | | | | | Depends-On: I16691fc8ac063705ba0c2bc63b96c4534ca8660b Bug: T87781 Change-Id: I5e1ab06e3decef6cc6090551d54dc4314ab9314a
* Revert "Separate MediaWiki unit and integration tests"Legoktm2019-06-131-621/+0
| | | | | | | | This reverts commit 0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9. Reason for revert: Broke postgres tests. Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
* Separate MediaWiki unit and integration testsMáté Szabó2019-06-131-0/+621
This changeset implements T89432 and related tickets and is based on exploration done at the Prague Hackathon. The goal is to identify tests in MediaWiki core that can be run without having to install & configure MediaWiki and its dependencies, and provide a way to execute these tests via the standard phpunit entry point, allowing for faster development and integration with existing tooling like IDEs. The initial set of tests that met these criteria were identified using the work Amir did in I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory under phpunit/ and organized into a separate test suite. The environment for this suite is set up via a PHPUnit bootstrap file without a custom entry point. You can execute these tests by running: $ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml Bug: T89432 Bug: T87781 Bug: T84948 Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d