Make WordPress Core

Opened 5 months ago

Last modified 2 months ago

#63914 new task (blessed)

Reassess the need for the external-http tests

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Tests in the external-http group are flakey because they rely on actual network requests over HTTP. There's no mocking in place. Server errors (HTTP 5XX) and more recently an increase in the frequency of HTTP 429 responses from wordpress.org will cause the tests to fail.

Let's reassess the tests in this group and question exactly what it is that each test is asserting.

As an example, the Tests_HTTP_Functions::test_head_404() test performs a HEAD request to a non-existent URL and then verifies that the response is not a WP_Error and that the response code is 404.

What exactly is this verifying though?

  • If it's verifying the correct population of the HTTP response code then that should be handled by test coverage on WP_HTTP_Requests_Response and a mocked up \WpOrg\Requests\Response instance. No need to perform a real HTTP request.
  • If it's verifying specifically that a 404 response doesn't result in a WP_Error instance being returned by wp_remote_*() then can we do that without performing an actual HTTP request? It should be possible with a test-only transport class which returns a mocked raw HTTP response.

Of course we need to be careful not to remove or reduce coverage where it's needed, but I'm positive we can remove many of the actual HTTP requests from these tests (and move them out of the external-http group).

Change History (2)

This ticket was mentioned in PR #9722 on WordPress/wordpress-develop by @johnbillion.


5 months ago
#1

  • Keywords has-patch has-unit-tests added

#2 @johnbillion
2 months ago

#42076 was marked as a duplicate.

Note: See TracTickets for help on using tickets.