Commit graph

17 commits

Author SHA1 Message Date
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
jenkins-bot
75c7d5356e Merge "config: Use stale cache instead of hard fail on "no retry" fetch error" 2024-05-21 16:29:09 +00:00
Ebrahim Byagowi
6e093bbe2d Add namespace and deprecation alias to MultiHttpClient
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
2024-05-20 00:32:45 +03:30
Timo Tijhof
5eb14300c2 config: Use stale cache instead of hard fail on "no retry" fetch error
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
2024-05-05 12:51:13 +00:00
Timo Tijhof
f5bd12e832 config: Abstract test matrix for EtcdConfig
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
2024-03-27 03:39:31 +00:00
Daimona Eaytoy
89f583625a tests: Add replacement for assertions deprecated in PHPUnit 9.6
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
2024-02-23 22:09:45 +01:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
Timo Tijhof
19bef9f6ed config: replace unused Logger in EtcdConfig with native trigger_error
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
2023-09-26 16:21:16 -04:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
Timo Tijhof
6d84e747b2 config: Widen @covers annotations in unit tests
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
2023-07-24 05:33:30 +01:00
Thiemo Kreuz
61ae7504df Replace trivial usa of mock builder with createMock() shortcut
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
2022-07-15 16:43:48 +00:00
Dan Duvall
aa5fdf9e6f Simplify DnsSrvDiscoverer interface
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
2022-02-16 15:00:45 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
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
2021-04-16 20:15:00 +02:00
Max Semenik
0f9cc78aba Cleanup of old PHPUnit usage, part 2
Bug: T192167
Bug: T234597
Change-Id: Ifec7f02f64d6613dbfa1878007f68c2e411a83dc
2019-10-04 21:47:46 -07:00
Amir Sarabadani
57261a926c Move unit tests, round III
Depends-On: I16691fc8ac063705ba0c2bc63b96c4534ca8660b
Bug: T87781
Change-Id: I5e1ab06e3decef6cc6090551d54dc4314ab9314a
2019-07-09 22:06:59 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
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
2019-06-13 22:56:31 +02:00
Renamed from tests/phpunit/includes/config/EtcdConfigTest.php (Browse further)