chilio / laravel-dusk-ci

Docker Test suite for Laravel Dusk in gitlab CI
MIT License
159 stars 51 forks source link

Timeouts in gitlab ci/cd #69

Closed Swennet closed 2 years ago

Swennet commented 2 years ago

Hello, first of all sorry if this is unrelated to this package. I'm trying to use laravel-dusk-ci in conjunction with a Gitlab ci/cd pipeline.

My unit tests work fine using this package, but my browser tests (Dusk) receives multiple timeouts relating to what I think is the ChromeDriver failing.

I'm using the recommended settings for the ChromeDriver my DuskTestCase.php file.

namespace Tests;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
        // static::startChromeDriver();
    }

    /**
     * Create the RemoteWebDriver instance.
     *
     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }
}

My gitlab-ci.yml looks as follows, I specifically used php version 7.3 for this as suggested as one of the solutions in the documentation:

image: chilio/laravel-dusk-ci:php-7.3

services:
  - mysql:5.7

variables:
  MYSQL_DATABASE: homestead
  MYSQL_ROOT_PASSWORD: secret
  DB_HOST: mysql
  DB_USERNAME: root

stages:
  - test
  - deploy

unit_test:
  stage: test
  script:
    - composer install
    - cp .env.example .env
    - configure-laravel
    - start-nginx-ci-project
    - vendor/bin/phpunit

browser_test:
  stage: test
  script:
    - composer install
    - cp .env.example .env
    - configure-laravel
    - start-nginx-ci-project
    - chromedriver &
    - php artisan dusk

Upon running my browser_test I receive the following output in the gitlab ci/cd job terminal.

System Chrome version: 94
System Chromedriver version: 94.0
Laravel Chromedriver version: 2.45
Chromedriver shipped with your Laravel installation is NOT compatible with current system chrome version!
Don't worry, we are fixing this right now, and you will be able, to test your app anyway.
Read more, about running tests with system inbuilt chromedriver in laravel-dusk-ci docs.
Starting inbuilt Chromedriver (94.0).
Waiting for inbuilt Chromedriver to launch on port 9515...
Starting ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Chromedriver started succesfully.
$ start-nginx-ci-project
 * Starting nginx nginx
   ...done.
$ chromedriver &
$ php artisan dusk
Starting ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1634909533.900][SEVERE]: bind() failed: Address already in use (98)
IPv6 port not available. Exiting...
Warning: TTY mode requires /dev/tty to be read/writable.
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
[1634909547.238][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909547.241][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909557.242][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909567.247][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909567.251][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909577.251][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909587.256][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909587.260][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
E[1634909597.261][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909615.655][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909615.658][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909625.658][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909635.664][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909635.667][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
[1634909645.668][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909655.681][SEVERE]: Timed out receiving message from renderer: 10.000
[1634909655.685][WARNING]: screenshot failed, retrying timeout: Timed out receiving message from renderer: 10.000
E                                                                  2 / 2 (100%)[1634909665.685][SEVERE]: Timed out receiving message from renderer: 10.000
Time: 2.19 minutes, Memory: 18.00 MB
There were 2 errors:
1) Tests\Browser\LoginTest::testLoginAndLogout
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/4adecbcb71732c0e914e63d7886239fe/log with params: {"type":"browser"}
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/WebDriverOptions.php:166
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:369
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:161
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:162
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:78
/builds/mygitlab/myproject/tests/Browser/LoginTest.php:27
Caused by
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http GET to /session/4adecbcb71732c0e914e63d7886239fe/screenshot
Operation timed out after 30000 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:367
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:355
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:146
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:147
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:70
/builds/mygitlab/myproject/tests/Browser/LoginTest.php:27
2) Tests\Browser\RegistrationTest::testRegistrationFlow
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/72b15fbd659b839b5fa3ba2ab6f920e0/log with params: {"type":"browser"}
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:27
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/WebDriverOptions.php:166
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:369
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:161
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:162
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:78
/builds/mygitlab/myproject/tests/Browser/RegistrationTest.php:78
Caused by
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http GET to /session/72b15fbd659b839b5fa3ba2ab6f920e0/screenshot
Operation timed out after 30001 milliseconds with 0 bytes received
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:585
/builds/mygitlab/myproject/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:367
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Browser.php:355
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:146
/builds/mygitlab/myproject/vendor/laravel/framework/src/Illuminate/Support/Collection.php:475
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:147
/builds/mygitlab/myproject/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:70
/builds/mygitlab/myproject/tests/Browser/RegistrationTest.php:78
ERRORS!
Tests: 2, Assertions: 1, Errors: 2.
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
chilio commented 2 years ago

You should not try to run chromedriver for the second time, since it is already started. Therefore please remove

Swennet commented 2 years ago

I have commented out chromedriver & from my browser_test script. Upon running I'm no longer receiving the message about ChromDriver failing to start the second time, but I'm still receiving the exact same timeouts.

Some extra information:

Could this be the reason for any issues? Is this package incompatible with older Laravel versions?

chilio commented 2 years ago

For Laravel 5.8 you should use php-7.1 or old-stable images. I've updated readme since microbadger service is down and this information was not seen in documentation. Let me know if it helps.

Swennet commented 2 years ago

@chilio This indeed helped me fix the issues I had!

One problem I ran into using the php-7.1 package is that my composer.json was expecting php-7.2. I got around this issue by specifying my project's PHP version in the "config" section of my composer.json.

    "config": {
        "platform": {
            "php": "7.1.3"
        }
    },