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

DT-1194: Environment Detector getSubclassResults Outside DRUPAL_ROOT #3994

Closed
mikemadison13 opened this issue Jan 29, 2020 · 5 comments · Fixed by #4017
Closed

DT-1194: Environment Detector getSubclassResults Outside DRUPAL_ROOT #3994

mikemadison13 opened this issue Jan 29, 2020 · 5 comments · Fixed by #4017
Labels
Bug Something isn't working

Comments

@mikemadison13
Copy link
Contributor

mikemadison13 commented Jan 29, 2020

BLT: 11.1.1
Environment: Linux (Azure Pipelines) for CI, Linux (Lando) locally

Describe the bug
When running Drupal VM, BLT seems to have no issue managing configuration for Behat that works locally and in the CI container(s).

However, when running Lando locally, I haven't figured out a way to manage CI so that my Behat tests work locally AND in CI.

In particular, the issue comes down to the project.local.hostname variable. When I have my blt.yml set to "local.${project.machine_name}.com", this works in the CI container. However, it doesn't locally (since the lando paradigm is different). If I change this to be the proper lando paradigm "${project.machine_name}.lndo.ste:8000", it works locally, but not in the CI.

I have attempted to use the ci.blt.yml file to override this, but it doesn't seem to work as intended.

Scenarios:

  1. blt.yml has the "whatever.local.com" and ci.blt.yml has project.local.hostname: 127.0.0.1:8888, everything works in cl (but not locally)
  2. blt.yml has "whatever.lndo.ste:8000" and ci.blt.yml has project.local.hostname: 127.0.0.1:8888, it doesn't work in ci (but does locally)
  3. blt.yml has whatever.lndo.ste:8000 and ci.blt.yml has project.local.hostname: whatever.local.com and/or a project.local.uri: whatever.local.com the server doesn't respond and timeout.

It seems like we need a way to define project.local set of config AND a project.ci set of config, so that I can have different paths for the different environments. If project.ci isn't specified, I would expect it to default to local.

On the output side, there are a few things that happen.

  • The server doesn't start or respond. This is usually an endless string of
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
�[37;46;1m[info]�[39;49;22m Waiting for response from http://localhost:9222...
  • The server starts, but then isn't reachable by the tests:
[37;46;1m[Testing\Behat]�[39;49;22m Running behat �[32m --format pretty /home/vsts/work/1/s/tests/behat --colors --no-interaction --stop-on-failure --strict --config /home/vsts/work/1/s/tests/behat/local.yml --profile local --tags '~ajax&&~experimental&&~lightningextension' -v�[39m
�[36m@api�[39m
�[1mFeature:�[22m Baseline Tests

  �[1mScenario:�[22m Ensure Site is Accessible           �[30m# features/Base.feature:3�[39m
    �[31mGiven I am on "�[39m�[31;1m/�[39;22m�[31m"�[39m                           �[30m# Drupal\DrupalExtension\Context\MinkContext::visit()�[39m
�[31m      GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: whatever.lndo.ste (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185
      Stack trace:
      #0 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(149): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
      #1 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(102): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
      #2 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
      #3 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
      #4 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
      #5 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(37): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
      #6 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Middleware.php(36): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
      #7 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(54): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
      #8 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Middleware.php(60): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
      #9 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/HandlerStack.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
      #10 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Client.php(277): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
      #11 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Client.php(125): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
      #12 /home/vsts/work/1/s/vendor/guzzlehttp/guzzle/src/Client.php(131): GuzzleHttp\Client->requestAsync('GET', Object(GuzzleHttp\Psr7\Uri), Array)
      #13 /home/vsts/work/1/s/vendor/fabpot/goutte/Goutte/Client.php(180): GuzzleHttp\Client->request('GET', 'http://whatever.lnd...', Array)
      #14 /home/vsts/work/1/s/vendor/symfony/browser-kit/Client.php(318): Goutte\Client->doRequest(Object(Symfony\Component\BrowserKit\Request))
      #15 /home/vsts/work/1/s/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php(144): Symfony\Component\BrowserKit\Client->request('GET', 'http://whatever.lnd...', Array, Array, Array)
      #16 /home/vsts/work/1/s/vendor/behat/mink/src/Session.php(148): Behat\Mink\Driver\BrowserKitDriver->visit('http://whatever.lnd...')
      #17 /home/vsts/work/1/s/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php(131): Behat\Mink\Session->visit('http://whatever.lnd...')
      #18 /home/vsts/work/1/s/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php(49): Behat\MinkExtension\Context\RawMinkContext->visitPath('/')
      #19 [internal function]: Behat\MinkExtension\Context\MinkContext->visit('/')
      #20 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(103): call_user_func_array(Array, Array)
      #21 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php(59): Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #22 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(140): Behat\Testwork\Call\Handler\RuntimeCallHandler->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #23 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Call/CallCenter.php(96): Behat\Testwork\Call\CallCenter->handleCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #24 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(125): Behat\Testwork\Call\CallCenter->makeCall(Object(Behat\Behat\Definition\Call\DefinitionCall))
      #25 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeStepTester.php(73): Behat\Behat\Tester\Runtime\RuntimeStepTester->testDefinition(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), Object(Behat\Behat\Definition\SearchResult), false)
      #26 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableStepTester.php(74): Behat\Behat\Tester\Runtime\RuntimeStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
      #27 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/TickingStepTester.php(59): Behat\Behat\Hook\Tester\HookableStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
      #28 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingStepTester.php(73): Behat\Behat\EventDispatcher\Tester\TickingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
      #29 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/StepContainerTester.php(59): Behat\Behat\EventDispatcher\Tester\EventDispatchingStepTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\StepNode), false)
      #30 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeScenarioTester.php(76): Behat\Behat\Tester\StepContainerTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #31 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableScenarioTester.php(74): Behat\Behat\Tester\Runtime\RuntimeScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #32 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingScenarioTester.php(103): Behat\Behat\Hook\Tester\HookableScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #33 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/IsolatingScenarioTester.php(69): Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester->test(Object(Behat\Behat\Context\Environment\InitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #34 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Tester/Runtime/RuntimeFeatureTester.php(84): Behat\Behat\Tester\Runtime\IsolatingScenarioTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), Object(Behat\Gherkin\Node\ScenarioNode), false)
      #35 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/Hook/Tester/HookableFeatureTester.php(72): Behat\Behat\Tester\Runtime\RuntimeFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
      #36 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Behat/EventDispatcher/Tester/EventDispatchingFeatureTester.php(71): Behat\Behat\Hook\Tester\HookableFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
      #37 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeSuiteTester.php(63): Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Gherkin\Node\FeatureNode), false)
      #38 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Hook/Tester/HookableSuiteTester.php(73): Behat\Testwork\Tester\Runtime\RuntimeSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
      #39 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingSuiteTester.php(72): Behat\Testwork\Hook\Tester\HookableSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
      #40 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Tester/Runtime/RuntimeExercise.php(71): Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester->test(Object(Behat\Behat\Context\Environment\UninitializedContextEnvironment), Object(Behat\Testwork\Specification\GroupedSpecificationIterator), false)
      #41 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/EventDispatcher/Tester/EventDispatchingExercise.php(70): Behat\Testwork\Tester\Runtime\RuntimeExercise->test(Array, false)
      #42 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Ordering/OrderedExercise.php(80): Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(Array, false)
      #43 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(149): Behat\Testwork\Ordering\OrderedExercise->test(Array, false)
      #44 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Tester/Cli/ExerciseController.php(108): Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(Object(Symfony\Component\Console\Input\ArgvInput), Array)
      #45 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Cli/Command.php(63): Behat\Testwork\Tester\Cli\ExerciseController->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #46 /home/vsts/work/1/s/vendor/symfony/console/Command/Command.php(255): Behat\Testwork\Cli\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #47 /home/vsts/work/1/s/vendor/symfony/console/Application.php(982): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #48 /home/vsts/work/1/s/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Behat\Testwork\Cli\Command), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #49 /home/vsts/work/1/s/vendor/behat/behat/src/Behat/Testwork/Cli/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #50 /home/vsts/work/1/s/vendor/symfony/console/Application.php(148): Behat\Testwork\Cli\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
      #51 /home/vsts/work/1/s/vendor/behat/behat/bin/behat(34): Symfony\Component\Console\Application->run()
      #52 {main}�[39m
    �[36mThen the response status code should be �[39m�[36;1m200�[39;22m�[36m�[39m �[30m# Drupal\DrupalExtension\Context\MinkContext::assertResponseStatus()�[39m
@mikemadison13 mikemadison13 added the Bug Something isn't working label Jan 29, 2020
@mikemadison13 mikemadison13 changed the title Local vs. CI Behat Configuration Local vs. CI Behat Configuration w/ Lando & ADS VM Jan 29, 2020
@danepowell
Copy link
Contributor

@mikemadison13 as I recall the primary concern here was that ci.blt.yml wasn't working, but I saw your test PR and it looks like it works as expected. Is there something else we can do to reproduce this?

@danepowell danepowell added the Awaiting response Maintainer needs more info label Feb 13, 2020
@mikemadison13
Copy link
Contributor Author

@danepowell I find it highly suspect that I have had this issue on two projects but can't reproduce it on canary. Let me set upaa new project and document step by step and we can set what shakes out.

@mikemadison13
Copy link
Contributor Author

mikemadison13 commented Feb 13, 2020

I think I have figured out part of the reason for the problem here. As far as I can tell, the Environment Detector does not work for the Behat command. If you have a look at https://github.com/acquia/blt/blob/11.x/src/Robo/Common/EnvironmentDetector.php#L350

if (!defined('DRUPAL_ROOT')) {
      // Do nothing if called outside of a Drupal bootstrap.
      return [];
}

I have confirmed that while trying to getSubclassResults during the blt tests command, it blows up because DRUPAL_ROOT isn't defined. If I hardcode my local environment and tell it that it is "CI" then it properly uses ci.blt.yml to set the environment to CI and my hostname is properly set to the 127.0.0.1 address.

@mikemadison13
Copy link
Contributor Author

mikemadison13 commented Feb 13, 2020

Admittedly this is hacked out, but something like this (to provide a fallback for non-Drupal commands like the Behat one) DOES seem to work.

if (!defined('DRUPAL_ROOT')) {
  $path = __DIR__ . "../../../../../../../docroot/autoload.php";
}
else {
  $path = DRUPAL_ROOT . '/autoload.php';
}
  $autoloader = require $path;

The question is, if DRUPAL_ROOT is undefined, is there a way to reliably figure out where the docroot is? Starting nested down inside of BLT and working up 6 directories is, theoretically sound (but again, horribly messy).

@mikemadison13
Copy link
Contributor Author

I can confirm that patching my BLT with the above code does allow the getSubclassResults to function and identify the Azure server. Now I'm back into the 500 response on the webserver issue :(

@mikemadison13 mikemadison13 removed the Awaiting response Maintainer needs more info label Feb 13, 2020
@mikemadison13 mikemadison13 changed the title Local vs. CI Behat Configuration w/ Lando & ADS VM Environment Detector getSubclassResults Outside DRUPAL_ROOT Feb 13, 2020
danepowell added a commit to danepowell/blt that referenced this issue Feb 19, 2020
danepowell added a commit to danepowell/blt that referenced this issue Feb 19, 2020
@danepowell danepowell changed the title Environment Detector getSubclassResults Outside DRUPAL_ROOT DT-1194: Environment Detector getSubclassResults Outside DRUPAL_ROOT Feb 20, 2020
@danepowell danepowell added this to the Backlog milestone Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
2 participants