Skip to content

Blocks E2E: Fix db connection issues - #51658

Merged
WunderBart merged 16 commits into
trunkfrom
fix/e2e-db-connection-issue
Sep 30, 2024
Merged

WunderBart merged 16 commits into
trunkfrom
fix/e2e-db-connection-issue

Conversation

@WunderBart

@WunderBart WunderBart commented Sep 24, 2024 •

Copy link
Copy Markdown
Contributor

What?

Context: p1727172851985989/1726604625.727459-slack-C03CPM3UXDJ
Closes: #51101 (This test was more flaky than others because of this issue so it was skipped. This PR unskips it.)

Trying to fix an intermittent issue with E2E tests in CI, where a DB gets disconnected mid-suite, failing the job:

{
  code: 'wp_die',
  message: '<h1>Error establishing a database connection</h1>',
  data: { status: 500 },
  additional_errors: []
}

See #51658 (comment) for more details.

How to test

  1. Make sure Blocks E2E tests in CI pass.

@WunderBart
WunderBart force-pushed the fix/e2e-db-connection-issue branch from 75ab5aa to 94ba9ac Compare September 24, 2024 13:06
@github-actions github-actions Bot added the focus: monorepo infrastructure Issues and PRs related to monorepo tooling. label Sep 24, 2024
@github-actions

github-actions Bot commented Sep 24, 2024 •

Copy link
Copy Markdown
Contributor

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 2.38 MB

compressed-size-action

@WunderBart
WunderBart force-pushed the fix/e2e-db-connection-issue branch from c2cf57c to 6d3b05b Compare September 24, 2024 19:05
@github-actions github-actions Bot removed the focus: monorepo infrastructure Issues and PRs related to monorepo tooling. label Sep 25, 2024
@WunderBart
WunderBart force-pushed the fix/e2e-db-connection-issue branch from 6e926ca to 3fc11a7 Compare September 26, 2024 14:22
@github-actions github-actions Bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Sep 26, 2024
@WunderBart
WunderBart force-pushed the fix/e2e-db-connection-issue branch from 4b7849a to 411d45d Compare September 27, 2024 11:00
@WunderBart

WunderBart commented Sep 27, 2024 •

Copy link
Copy Markdown
Contributor Author

This issue is keeping me awake. After a bunch of failed attempts (see commit history), I thought I had it by disposing of the request cache – I figured we're running out of resources because we're making a lot of requests. Unfortunately, it failed again after a couple of reruns (debugging this one takes forever). I obviously tried replicating the issue locally, without luck. It always passes, even when running entire shards. Anyway, it's time to ask for some help. Here's what I've learned so far:

  • It breaks only in CI.

  • It can break a single test and return to normal in subsequent tests.

  • It can break halfway through the suite and stay broken until the next suite.

  • It's not tied to a specific test.

  • It's usually thrown within the product-collection.block_theme.spec.js suite.

    I can't see anything out of order with that suite, apart from the fact that it's the biggest one we have.

  • It always breaks within the beforeEach hook.

  • The error is always a 500 database disconnected one:

     {
       code: 'wp_die',
       message: '<h1>Error establishing a database connection</h1>',
       data: { status: 500 },
       additional_errors: []
     }
  • Before the 500 response is thrown (e.g., after trying to activate the plugin or navigate), a bunch of plugin activation requests from an unrelated suite (!!!) are made.

    This seems to be what leads to the failure, but I haven't yet found the culprit and it still doesn't make any sense to me. How is a different suite bleeding into this one??

Example of a failed run.

It usually happens within the shard no. 4, which runs the following suites in the following order:

  1. compatibility-layer.block_theme.spec.ts ✅ PASS
  2. extensibility-events.block_theme.spec.ts ✅ PASS
  3. inspector-controls.block_theme.spec.ts ✅ PASS
  4. product-collection.block_theme.spec.ts ❌ FAIL

The (currently) failing test is this one:

product-collection/product-collection.block_theme.spec.ts:1014 › Testing "usesReference" argument in "registerProductCollection" › Collection "My Custom Collection - Cart Context" should not show preview label in Product Catalog template

From the failed test's trace.zip, the network requests are as follows:

Screenshot 2024-09-27 at 11 57 06

The part that is completely out of order is the request to activate the product-collection-compatibility-layer plugin, which is only activated within the compatibility-layer.block_theme.spec.ts that has already passed three suites ago. Also, the register-product-collection-tester plugin activation should not be called multiple times if the first request was successful. Because of that, I thought it might be something with re-authorization where we repeat the request if the user is not yet authorized, but the requests are successful (until 500), so the user is authorized and yet they're still repeated.

Note

You can download the trace.zip and open it via https://trace.playwright.dev/ for further inspection.

As I write this, I’m in the process of cleaning up the numerous Product Collection E2E tests, particularly the product-collection.block_theme.spec.js file, and splitting them up further. These tests currently occupy the CI for the longest time, which is problematic. Many of them involve nested loops and are heavily parameterized, making them challenging to debug and follow. I’m working on simplifying things in the hope that I might either spot an issue or inadvertently fix it. If anyone has a better approach, I’m all ears! 🙏

The following issues might be related:

cc: @gigitux @adimoldovan @adamziel @kevin940726 @Mamaduka @talldan

I'm pinging some core folks as it might be related to the @wordpress/e2e-test-utils-playwright package.

@Mamaduka

Copy link
Copy Markdown
Contributor

I've not seen a similar error in the Gutenberg repo, but I started noticing tests marked as flaky due to the apiRequestContext.fetch: socket hang up error. I wonder if these are related.

@gigitux

gigitux commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

Thanks for working on this and for your great exploration, @WunderBart! 🙇

Did we try to use this patch and see if the issue disappears? In this way, we can ensure that the issue isn't related to WordPress.

@WunderBart

Copy link
Copy Markdown
Contributor Author

Did we try to use this patch and see if the issue disappears? In this way, we can ensure that the issue isn't related to WordPress.

@gigitux yep, tried it in 8a59383. The DB kept disconnecting, unfortunately :(

@Mamaduka

Copy link
Copy Markdown
Contributor

I think we need to narrow down the issue. Is this a problem with wp-env and CIs or the Playwright issue?

Unfortunately, I don't have enough expertise with wp-env; I only use it to run the tests.

cc @noahtallen

@gigitux

gigitux commented Sep 27, 2024 •

Copy link
Copy Markdown
Contributor

It could be a dumb thought but I noticed that the last time that we updated @wordpress/e2e-test-utils-playwright and @wordpress/env was two months ago.

If the 8a59383 didn't work, it means that could be some regression related to WordPress/WooCommerce?

I think we need to narrow down the issue.

💯 I agree!

@WunderBart
WunderBart marked this pull request as ready for review September 27, 2024 15:08
@woocommercebot
woocommercebot requested review from a team and louwie17 and removed request for a team September 27, 2024 15:08
@github-actions

github-actions Bot commented Sep 27, 2024 •

Copy link
Copy Markdown
Contributor

Hi @lanej0, @louwie17, @adimoldovan,

Apart from reviewing the code changes, please make sure to review the testing instructions and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@WunderBart

WunderBart commented Sep 27, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback so far, folks. I was trying to narrow it down but I just could not repro it locally yet. Will keep trying.

In the meantime, after the cleanup, I restarted the workflow several times, and the usual suspects didn't fail. Let's hope it stays like that. Marking this one as ready for review, let's see how it goes! 🙌

@WunderBart WunderBart added the Kirigami WC Store Editing (FSE) label Sep 27, 2024
@WunderBart WunderBart self-assigned this Sep 27, 2024
@WunderBart WunderBart added the focus: e2e tests Issues related to e2e tests label Sep 27, 2024
@github-actions github-actions Bot removed the focus: e2e tests Issues related to e2e tests label Sep 27, 2024

@lanej0 lanej0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustrating that it's one of those problems we can't nail down. No concerns from me, I merged trunk just to trigger another CI run and tests passed -- so 👍🏼 -- we'll just keep an eye out post-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kirigami WC Store Editing (FSE) plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flaky Test] does not render

5 participants