browserstack / browserstack-local-php

PHP bindings for BrowserStack Local
https://www.browserstack.com
MIT License
13 stars 10 forks source link

stop() Doesn't seem to be working inside a Docker container #21

Closed dfsoeten closed 5 years ago

dfsoeten commented 5 years ago

Hey there

I'm experiencing some issues with getting the client to stop after my tests have been run. If I spin up a clean Docker image of my application, and execute ps -ax inside of it I get the following as result:

PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 apache2 -DFOREGROUND
   17 ?        S      0:00 apache2 -DFOREGROUND
   18 ?        S      0:00 apache2 -DFOREGROUND
   19 ?        S      0:00 apache2 -DFOREGROUND
   20 ?        S      0:00 apache2 -DFOREGROUND
   21 ?        S      0:00 apache2 -DFOREGROUND
   22 ?        Rs     0:00 ps -ax

After I run my tests using the BrowserStackWebDriver helper that has been provided by the documentation here, the client is still running. The ps -ax output after the tests have been run:

PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 apache2 -DFOREGROUND
   16 ?        S      0:00 apache2 -DFOREGROUND
   17 ?        S      0:00 apache2 -DFOREGROUND
   18 ?        S      0:00 apache2 -DFOREGROUND
   19 ?        S      0:00 apache2 -DFOREGROUND
   20 ?        S      0:00 apache2 -DFOREGROUND
   55 ?        Ssl    0:00 BrowserStackLocal -logFile /var/www/html/local.log <key> -daemonInstance
   76 ?        S      0:00 apache2 -DFOREGROUND
   78 ?        S      0:00 apache2 -DFOREGROUND
   79 ?        S      0:00 apache2 -DFOREGROUND
   80 ?        S      0:00 apache2 -DFOREGROUND
   81 ?        S      0:00 apache2 -DFOREGROUND
  105 ?        Rs     0:00 ps -ax

My conclusion is that the stop() method is not quite working as expected, I have double checked and even removed the surrounding if case (if($this->bs_local->isRunning())) to double check this.

If I try to re-run the tests without completely restarting my app container I get the following error message, hence I'm investigating this:

Do not run Composer as root/super user! See https://getcomposer.org/root for details
> php vendor/bin/codecept run 'behavioral'
Codeception PHP Testing Framework v2.5.5
Powered by PHPUnit 7.5.9 by Sebastian Bergmann and contributors.
Running with seed: 

In Local.php line 125:

  Either another browserstack local client is running on your machine or some  
   server is listening on port 45691                                           

run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--phpunit-xml [PHPUNIT-XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--seed SEED] [--] [<suite> [<test>]]

Script php vendor/bin/codecept run handling the test event returned with error code 1

Any ideas?

Edit: I would like to prevent a "shotgun" solution for this issue as discussed here.

dfsoeten commented 5 years ago

I have applied the "shotgun" solution, which obviously seems to work: exec('kill ' . $this->bs_local->pid);

I would like to see a better solution for this problem in the future.

dfsoeten commented 5 years ago

To whom it might help in the future. The Browserstack binary, downloaded by the BrowserStack\LocalBinary, ended up in the /root directory of my Docker container. With no current way to manually specify a download location without messing with the HOME .env variable or the $_SERVER['HOMEDRIVE'] and '$_SERVER['HOMEPATH']' superglobals.

I dind't manage to get the right execution rights on that file, for whatever reason, hence why I tried moving the binary in the first place.