Skip to content
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

Add shm_size param to chrome container #172

Merged
merged 1 commit into from
May 10, 2024
Merged

Conversation

maurisrx
Copy link
Contributor

I kept getting invalid session ID errors when running Codeception acceptance JS tests. After searching for some answers, the chrome container turns out doesn't have enough shm size. When I set it in slic-stack.yml, the tests went through successfully.

The config allows users to set the value in a .env.slic.local file. The default value 256m the minimum value the tests went through successfully based on my tests. I tried 128m but it still got the errors.

Can you please let me know your thoughts?

Here is my codeception acceptancejs.suite.yml file for reference:

actor: AcceptanceJsTester
bootstrap: _bootstrap.php
step_decorators:
  - \Codeception\Step\AsJson
modules:
  enabled:
    - WPLoader
    - WPDb
    - WPWebDriver
    - \Helper\AcceptanceJs
  config:
    WPDb:
      dsn: "mysql:host=%WP_DB_HOST%;dbname=%WP_DB_NAME%"
      user: "%WP_DB_USER%"
      password: "%WP_DB_PASSWORD%"
      dump: tests/_data/dump.sql
      populate: true
      cleanup: true
      url: "%WP_URL%"
      tablePrefix: "%WP_TABLE_PREFIX%"
    WPLoader:
      loadOnly: true,
      wpRootFolder: "%WP_ROOT_FOLDER%"
      dbName: "%WP_DB_NAME%"
      dbHost: "%WP_DB_HOST%"
      dbUser: "%WP_DB_USER%"
      dbPassword: "%WP_DB_PASSWORD%"
    WPWebDriver:
      # We have to use a URL Chromedriver will be able to resolve.
      # See the `.env.dist` file for more information.
      url: "%WP_CHROMEDRIVER_URL%"
      # see codeception.dist.yml for the configuration
      adminUsername: "%WP_ADMIN_USERNAME%"
      adminPassword: "%WP_ADMIN_PASSWORD%"
      adminPath: "/wp-admin"
      browser: chrome
      host: "%CHROMEDRIVER_HOST%"
      port: "%CHROMEDRIVER_PORT%"
      window_size: false
      capabilities:
        chromeOptions:
          args:
            [
              "--headless",
              "--disable-gpu",
              "--proxy-server='direct://'",
              "--proxy-bypass-list=*",
              "--url-base=/wd/hub",
              "--no-sandbox",
              "--disable-dev-shm-usage"
            ]

Copy link
Contributor

@lucatume lucatume left a comment

Choose a reason for hiding this comment

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

Hi @maurisrx,

thanks for taking the time to report the issue and propose a solution.
I do not think there should be any problem setting the shm_size to a higher value.

I have some questions before, though:

  1. In your acceptancejs.suite.yml file, the WPWebDriver module configures Chrome with --disable-dev-shm-usage which should force Chrome not to depend on the allocated shm_size at all. Can you confirm removing the --disable-dev-shm-usage flag from the suite configuration and using the increased shm_size fixes the issue?
  2. Would you be able to provide an example of a test that is causing Chrome to run out of memory? If you cannot due to the code coming from a private project, could you provide some indications about how to reproduce the issue?

Let me know if I'm not reading things right or am missing some piece of information

@maurisrx
Copy link
Contributor Author

Thank you @lucatume for the reply.

Here are my answers to your questions:

In your acceptancejs.suite.yml file, the WPWebDriver module configures Chrome with --disable-dev-shm-usage which should force Chrome not to depend on the allocated shm_size at all. Can you confirm removing the --disable-dev-shm-usage flag from the suite configuration and using the increased shm_size fixes the issue?

Oddly even with --disable-dev-shm-usage option enabled, the test returns invalid session ID unless the shm_size is increased. The shm_size increase works with or without --disable-dev-shm-usage enabled. Even with the proposed 256m size, in some tests I encountered the same error so I have to increase it to 1g with the config.

Would you be able to provide an example of a test that is causing Chrome to run out of memory? If you cannot due to the code coming from a private project, could you provide some indications about how to reproduce the issue?

Here is my test code. It comes from a private repository so I just put it here so you can try to replicate it.

<?php
/**
 * AcceptanceJS test file.
 */

use AcceptanceJsTester;
use Tests\Base\CestCase;

/**
 * MetaBoxCest test class.
 */
class MetaBoxCest extends CestCase {
	/**
	 * Test "Details" metabox fields dynamic visibility.
	 *
	 * @param AcceptanceJsTester $i Test actor.
	 *
	 * @return void
	 */
	public function test_details_metabox_fields_dynamic_visibility( AcceptanceJsTester $i ): void {
		// Arrange.

		$i->disableTelemetry();

		// Act and Assert.

		$i->loginAsAdmin();
		$i->amOnAdminPage( 'post-new.php?post_type=custom_cpt' );
		$i->waitForDocumentReady();

		$i->selectOption( 'trigger', 'enroll_group' );
		$i->seeElement( '#group_id' );
		$i->dontSeeElement( '#course_id' );
        }
}

Please let me know if you need anything else.

@lucatume lucatume merged commit 478ddf6 into main May 10, 2024
@lucatume
Copy link
Contributor

Thanks for the PR, I've tested it locally and all is fine.

@lucatume lucatume deleted the maurisrx/chrome-shm branch May 10, 2024 09:24
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.

None yet

2 participants