Skip to content

Conversation

mglaman
Copy link
Contributor

@mglaman mglaman commented Jul 4, 2017

No description provided.

@mglaman
Copy link
Contributor Author

mglaman commented Jul 4, 2017

This needs matching Javascript test.

@mglaman mglaman force-pushed the 2827721-add-to-cart-form-id branch from 6206312 to 5edc808 Compare July 6, 2017 20:44
Copy link

@wimleers wimleers left a comment

Choose a reason for hiding this comment

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

I think you can have slightly stronger test coverage, and hence stronger assurances in the future that the "add to cart" forms are actually being delivered via BigPipe :)

* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Sleep between 0.0 and 2.0 seconds.
Copy link

Choose a reason for hiding this comment

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

Why make this random? Why not just always 2 seconds? Or 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://www.drupal.org/node/2886614, there is a chance the forms could be built out of order. To ensure unique form IDs, we ended up using a static counter. If the forms are built out of order, this causes a bug in form submission. My goal is to reproduce the bug and test our assumed fix.

So I thought random times might cause the build to get weird. However by this time the form ID is known... so maybe slowdown happens elsewhere when rendering these formatter placeholders.

@@ -0,0 +1,12 @@
name: Commerce Cart Big Pipe
Copy link

Choose a reason for hiding this comment

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

EXCITING!

@@ -0,0 +1,12 @@
name: Commerce Cart Big Pipe
type: module
description: Provides a slow version of AddToCart form for testing Big Pipe streaming
Copy link

Choose a reason for hiding this comment

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

❤️

*/
function commerce_cart_big_pipe_module_implements_alter(&$implementations, $hook) {
if ($hook == 'entity_type_build') {
// commerce_cart_big_pipe_entity_type_build() needs to run after
Copy link

Choose a reason for hiding this comment

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

Specifying a module weight might be simpler than this.

$seen_ids[] = $form->getAttribute('id');
}
$this->assertSession()->responseHeaderNotEquals('BigPipe-Test-Placeholders', '<none>');
$this->assertSession()->responseHeaderEquals('BigPipe-Test-No-Js-Placeholders', '<none>');
Copy link

Choose a reason for hiding this comment

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

I'm not sure why you're testing these two things?

Copy link

Choose a reason for hiding this comment

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

And if you are, you probably want to test the specific value of this header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was some debugging, basically. But I am going to test the header, now!

/**
* Tests that the form IDs are unique.
*/
public function testUniqueAddToCartFormIds() {
Copy link

Choose a reason for hiding this comment

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

I think this test method is meant to test BigPipe-powered delivery?

I replied to your question on Twitter (https://twitter.com/wimleers/status/883262976576413696), but repeating here to prevent linkrot:

Recommendation:

  1. assert HTML placeholder
  2. wait for the BigPipe stop signal
  3. assert HTML placeholder has been replaced

See \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleClosingBodies_2678662() — waiting for the stop signal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With previous comment, the original issue was ensuring we had unique form IDs, then I also used it to debug BigPipe delivery.

@mglaman mglaman force-pushed the 2827721-add-to-cart-form-id branch from fa7ffb3 to cd17262 Compare July 8, 2017 03:44
@mglaman
Copy link
Contributor Author

mglaman commented Jul 8, 2017

Committed in f37464b

@mglaman mglaman closed this Jul 8, 2017
@mglaman mglaman deleted the 2827721-add-to-cart-form-id branch July 8, 2017 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants