-
Notifications
You must be signed in to change notification settings - Fork 8
Tests: Fix Flaky Subscriber Checks #1183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
n7studios
wants to merge
6
commits into
main
Choose a base branch
from
tests-fix-check-subscriber
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+234
−69
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49311f8
Tests: Wait for subscriber
n7studios af4387a
Tests: Log API Requests
n7studios 76e3c52
Run specific tests
n7studios 71902d1
Reinstate all tests
n7studios 7929f39
Merge branch 'main' into tests-fix-check-subscriber
n7studios c29bf35
Revert apiCheckSubscriberDoesNotExist
n7studios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Kit API Recorder | ||
| * Description: Records Kit API requests and responses in an option, for end to end tests to assert against. | ||
| * | ||
| * @package ConvertKit | ||
| * @author ConvertKit | ||
| */ | ||
|
|
||
| // Record Kit API requests and responses. | ||
| add_action( | ||
| 'http_api_debug', | ||
| function ( $response, $context, $transport, $parsed_args, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | ||
|
|
||
| // Bail if this isn't a request to the Kit API. | ||
| if ( strpos( $url, 'https://api.kit.com/' ) !== 0 ) { | ||
| return; | ||
| } | ||
|
|
||
| // Build the request path, excluding the API version and any query parameters. | ||
| $path = (string) wp_parse_url( $url, PHP_URL_PATH ); | ||
| $path = ltrim( str_replace( '/v4/', '', $path ), '/' ); | ||
| $query = array(); | ||
| parse_str( (string) wp_parse_url( $url, PHP_URL_QUERY ), $query ); | ||
|
|
||
| // Decode the request body, which is JSON encoded for POST, PUT and DELETE requests. | ||
| $body = array(); | ||
| if ( ! empty( $parsed_args['body'] ) ) { | ||
| $body = is_string( $parsed_args['body'] ) ? json_decode( $parsed_args['body'], true ) : $parsed_args['body']; | ||
| } | ||
|
|
||
| // Fetch the existing log. | ||
| $log = get_option( 'kit_api_log', array() ); | ||
| if ( ! is_array( $log ) ) { | ||
| $log = array(); | ||
| } | ||
|
|
||
| // Append this request and its response to the log. | ||
| $log[] = array( | ||
| 'method' => isset( $parsed_args['method'] ) ? $parsed_args['method'] : 'GET', | ||
| 'path' => $path, | ||
| 'query' => $query, | ||
| 'body' => is_array( $body ) ? $body : array(), | ||
| 'code' => is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response ), | ||
| 'error' => is_wp_error( $response ) ? $response->get_error_message() : '', | ||
| 'response' => is_wp_error( $response ) ? array() : (array) json_decode( wp_remote_retrieve_body( $response ), true ), | ||
| ); | ||
|
|
||
| update_option( 'kit_api_log', $log, false ); | ||
| }, | ||
| 10, | ||
| 5 | ||
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry stops as soon as the subscriber has any tag, but line 291 then asserts the first tag is
$tagID, so I think that if another tag lands first, you exit the retry early and fail immediately.