When developing with Vagrant/VirtualBox, I use port-forwarding to access Drupal running inside the guest. If I run tests extended from WebTestBase, the internal browser uses the port-forwarded address and not the internal address.
For example, if I have Drupal running in the guest under port 80, I access it through another port, say 38000.
When running the tests, code like:
$this->drupalLogin($admin_user);
will fail, with a result:
GET http://localhost:38000/user/login returned 0 (0 bytes).
Expected behaviour:
The test should succeed, using the correct port.
I'd guess it's a bug in UrlGenerator, but I could be wrong.
Comments
Comment #1
daffie commentedComment #2
Anonymous (not verified) commentedCurrently seeing similar results using Drupal 7 with Vagrant + Virtualbox. In my case it is running on port 80 inside the vagrant box, with port forwarding on all interfaces to allow the host OS to hit 8080. Everything else works but tests fail consistently.
Appears that 8080 is not active within the vagrant box. Might have to try an internal port forward next time I need to do this.
Comment #3
Anonymous (not verified) commentedFound a solution to this:
- On OSX some extra magic happens so this only seems to affect Linux as a host OS
- The problem is both name resolution and port number mapping
Inside the vagrant box:
1) Add /etc/hosts entry so name is resolvable:
vi /etc/hosts
127.0.0.1 mysitename.local2) As root/sudo add a new iptables rule:
iptables -t nat -I OUTPUT -p tcp --dport 8080 -j REDIRECT --to-port 80(nat/forwarding may need to be enabled before doing this)
Comment #12
quietone commentedTriaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.
This looks like it belongs in the testing component, phpunit.
Comment #17
quietone commentedThe only reports of this problem are from 8 years ago, at least, on this issue. Given that tests would be failing if this were still a problem for devs I reckon this has been resolved. And there a work around is given in #3.
If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!