Skip to content

Autosave: Improve E2E test reliability by consuming synchronous data and bailing on save failure#17679

Merged
gziolo merged 4 commits into
masterfrom
fix/e2e-autosave
Oct 3, 2019
Merged

Autosave: Improve E2E test reliability by consuming synchronous data and bailing on save failure#17679
gziolo merged 4 commits into
masterfrom
fix/e2e-autosave

Conversation

@mcsf

@mcsf mcsf commented Oct 1, 2019

Copy link
Copy Markdown
Contributor

Description

Recently-merged #17501 and #17503 greatly expanded the reach of autosaving and its E2E test coverage. These tests have been remarkably unreliable, especially on Travis, something which this PR sought to fix, and does fix in two main ways.

Terminology preamble

A local autosave is an action — or its resulting object — performed on the client, the object then residing in window.sessionStorage. A remote autosave is a special kind of WordPress post revision saved on the WordPress site itself. Local autosaves are cheaper but more volatile, and can be performed more frequently, whereas remote autosaves are persisted across clients for a given WordPress user. Currently, per #17500, remote autosaves should take precedence over local ones._

Fixes

  1. How LocalAutosaveMonitor waits for remote autosave data.
  • Until now, although we were requesting the entire remote autosave entity inside LocalAutosaveMonitor's useAutosaveNotice, we only cared about the existence or absence of a remote autosave for the current post. useAutosaveNotice was requesting the entire remote entity because there were plans in Autosave: fix conflict between remote and local autosaves #17501 to inspect and compare local and remote autosave objects, a requirement which was later dropped. This data needs to be resolved through the core data store.

  • In contrast, the editor setting autosave is immediately available upon editor initialisation. It only contains an editLink property that links to a remote autosave's revision page, but most importantly it's an indication of whether there is a remote autosave available for the current post.

  • Later on, if we choose to reconcile remote and local autosaves with more sophistication, this could possibly be done based on recency of autosave — in which case we could might still get away with editor settings if the server provides this information (e.g. timestamp) inside the autosave object.

  • This change should hopefully provide a more reliable page-loading experience for autosave's E2E tests.

  1. How the shouldn't conflict with server-side autosave test bails under unexpected circumstances.
  • Despite the changes described in 1., a particular test would still frequently fail. Debugging led to the conclusion that the test's forced remote autosaves might be failing for unknown reasons.

  • This remote autosave failure is independent from the test's scope, which is to make sure that, concurrent remote and local autosaves for the current post, the editor will only show a notice to recover from the remote one.

  • Thus, the temporary solution here is to let the test bail if, upon editor reload, it looks like there is no remote autosave available.

How has this been tested?

E2E tests have been run extensively, and Travis should reliably green-light this branch.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@mcsf mcsf added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Oct 1, 2019
@gziolo

gziolo commented Oct 1, 2019

Copy link
Copy Markdown
Member

Travis isn't flattered with the proposed changes:
https://travis-ci.com/WordPress/gutenberg/jobs/240704049#L1010

It's surprising that there are no notices found.


await page.reload();
await page.reload( { waitUntil: [ 'domcontentloaded', 'networkidle2' ] } );
await sleep( 2 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does it need to wait 2 seconds after reload?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was playing with reliability, expecting the failures to be related to a longer-than-expected data resolution for remote autosaves after the page has loaded.

With that in mind I just pushed 307f95a, which I'm more hopeful about. However, as I was waiting for Travis I just saw a test failing locally. (ノ°Д°)ノ︵ ┻━┻.

@mcsf mcsf force-pushed the fix/e2e-autosave branch from 307f95a to eea8069 Compare October 1, 2019 14:33
@gziolo

gziolo commented Oct 1, 2019

Copy link
Copy Markdown
Member

Can you describe what the issue is and how you think it could be solved? Do you know why does this particular test fail? I can help debugging tomorrow.

@mcsf

mcsf commented Oct 1, 2019

Copy link
Copy Markdown
Contributor Author

Can you describe what the issue is and how you think it could be solved? Do you know why does this particular test fail? I can help debugging tomorrow.

Sure, and thanks for offering help.

From the logs, it seems that autosaving on the server occasionally just fails… because editorSettings.autosave should be available immediately upon page load, since it's provided by the server:

https://github.com/WordPress/WordPress/blob/099eb0578eecf79b7f25968011264c9e5d8014ba/wp-admin/edit-form-blocks.php#L302-L307

https://github.com/WordPress/WordPress/blob/099eb0578eecf79b7f25968011264c9e5d8014ba/wp-admin/edit-form-blocks.php#L385-L388

So this last change was a desperate attempt at retrying autosaving on the server.

mcsf added 3 commits October 2, 2019 14:18
* Until now, although we were requesting the entire autosave entity
inside `LocalAutosaveMonitor`'s `useAutosaveNotice`, we only care about
the existence or absence of an autosave for the current post.

* `useAutosaveNotice` was requesting the entire entity because there
were plans in #17501 to compare local and remote autosave objects, a
requirement which was later dropped.

* In contrast, the editor setting `autosave` is immediately available
upon editor initialisation.

* Later on, _if_ we choose to reconcile remote and local autosaves with
more sophistication, this could possibly be done based on recency of
autosave -- in which case we could might still get away with editor
settings if the server provides this information inside the `autosave`
object.

* This change should hopefully provide a more reliable page-loading
experience for autosave's E2E tests.
@mcsf mcsf force-pushed the fix/e2e-autosave branch from b723919 to abf8644 Compare October 2, 2019 13:41
@mcsf mcsf force-pushed the fix/e2e-autosave branch from abf8644 to fec779f Compare October 2, 2019 15:37
@mcsf mcsf changed the title Tests: Autosave: Allow extra reloading time for autosave notices Autosave: Improve E2E test reliability by consuming synchronous data and bailing on save failure Oct 2, 2019
// autosaved. The reasons for this are still unknown. Since this is
// unrelated to *local* autosave, until we can understand them, we'll
// drop this test's expectations if we don't have an autosave object
// available.

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.

For me, we should just skip the test in this case instead of making it inconsistent.

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.

ideally, we find the real issue though :) @jasmussen had the issue while working on some PRs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I will work on it today.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you both!

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.

+1+1

@aduth aduth Feb 13, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this worked on?

Still see the code:

// FIXME: Occasionally, upon reload, there is no server-provided
// autosave value available, despite our having previously explicitly
// autosaved. The reasons for this are still unknown. Since this is
// unrelated to *local* autosave, until we can understand them, we'll
// drop this test's expectations if we don't have an autosave object
// available.
const stillHasRemoteAutosave = await page.evaluate(
() =>
window.wp.data.select( 'core/editor' ).getEditorSettings()
.autosave
);
if ( ! stillHasRemoteAutosave ) {
return;
}

Could we track it in an issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It wasn't, and it still feels nebulous.

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like a ton of work to improve the stability of this test. Major props for investing so much time to fully understand what the underlaying issue is.

I re-triggered Travis 3 times and it confirms that this fix is solid.

I don't want to block this PR with my own testing. Let's get this in and I will do my own experiments of the stable master branch. The reliability of the tests is the most important as it increases the confidence that Travis is useful :)

@gziolo gziolo merged commit a706b42 into master Oct 3, 2019
@gziolo gziolo deleted the fix/e2e-autosave branch October 3, 2019 08:29
@gziolo

gziolo commented Oct 3, 2019

Copy link
Copy Markdown
Member

My further explorations performed in #17749 didn't help so far. We probably need to investigate whether autosave works properly in all cases. We might replicate what's used in one of the test where we intercept requests to gather more data where the issues might originate. See my related comment: #17749 (comment).

@mcsf

mcsf commented Oct 3, 2019 via email

Copy link
Copy Markdown
Contributor Author

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

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants