grails geb -baseUrl option does not work for remote services
Asked Answered
A

2

11

I'm using the geb 0.9.2 plugin for grails 2.3.4

I want to run the functional tests separately from the service, on two separate hosts.

I have observed the following:

If I run the service on the same host, and execute:

grails test-app functional: -baseUrl=http://localhost:8080/foo/--non-interactive

then the tests are run against this already running service and pass.

If the service is not running, and I execute that same command, then a new service instance is started inside grails test-app and the tests are run against that. (This is unexpected to me)

If the service is running on a different host, at say http://other:16060/foo/ and I run:

grails test-app functional: -baseUrl=http://other:16060/foo/ --non-interactive

... then a local service is started and the tests are run against that rather than against the specified remote service. Again this is unexpected to me.

I can't find any documentation explaining this behaviour.

Is it possible to run test-app against a remotely running service?

(my recollection although I have not tested it recently is this behaviour was also the case with grails 2.2.2)

Antonietta answered 4/1, 2014 at 19:30 Comment(0)
A
2

This appears to be a grails bug (?feature).

Grails checks to see if the service is running by connecting to the service port.

If the service is not running, it starts a service.

The niggle is: The check to see if the service is running is always made against localhost/127.0.0.1 even if the baseUrl points to a different host.

I worked around it by starting a fake server on 127.0.0.1 using the unix nc tool. That is sufficient to make grails think the service is already running and not start up a new one. It then respects the baseUrl and tests the remote one.

Ugh.

Antonietta answered 28/4, 2014 at 12:6 Comment(0)
P
0

Passing a baseUrl argument is how you run it against a remote server so you are doing everything right there. The only reason it wouldn't is if you also pass in a -inline or -war flag as well.

Try turning off forked execution in your tests and see if that solves the issue, it may be that the argument is not being passed to the forked JVM.

http://grails.org/doc/2.3.x/guide/commandLine.html#forkedMode

Pterosaur answered 8/1, 2014 at 8:30 Comment(4)
I've set this: grails.project.fork = [ test: false ] and it looks, from pstree, that its running one java process with a bunch of threads. It still starts up a local in-JVM Tomcat with the app in it. I don't understand where in the grails source code this "don't run" is supposed to (not) happen. As far as I can see from FunctionalTestPhaseConfigurer, it will always start something?Antonietta
If I run nc -l -p 8080 on localhost and run the grails test command, it does not start a new container, and instead attempts to run the test against the not-webserver that is nc. I see the first HTTP request come into nc. So perhaps its ignoring the baseUrl entirely.Antonietta
@BenClifford: Did you resolve this? I'm encountering the same issue and cannot get grails to respect the baseUrl. it always starts up the app on localhost :(Salop
I did. Sorry for not writing a response. Its an ugly hack.Antonietta

© 2022 - 2024 — McMap. All rights reserved.