-1

I am trying to configure a bitbucket CI pipeline to run tests.Stripping out the details I have a make file which looks as follows to run some form of integration tests.

test-e2e:
docker-compose -f ${DOCKER_COMPOSE_FILE} up -d ${APP_NAME} 
godog
docker-compose -f ${DOCKER_COMPOSE_FILE} down

Docker compose is a single webserver with ports exposed.

Pipeline looks as follows:

     - step: &integration-testing 
    name: Run integration tests script: # do this to make go module work with private repo 
    - apk add libc-dev py-pip python-dev libffi-dev openssl-dev gcc libc-dev make bash 
    - pip install docker-compose - git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/" 
    - go get github.com/onsi/ginkgo/ginkgo 
    - go get github.com/onsi/gomega/... 
    - go get github.com/DATA-DOG/godog/cmd/godog 
    - make build-only && make test-e2e 

I am facing two separate issues for both i have not been able to find a solution.

  1. Keep getting connection refused when the tests are run.

To elaborate above, the docker compose brings up a server with proper host:port mapping ("127.0.0.1:10077:10077"). The command godog is intended to run the tests by querying the server. This however always ends in connection refused.This link has a possible solution , so i am exploring that.

  1. The pipeline almost always runs commands before the container is up. I've tried fixing this by changing the invoke to.

     test-e2e:
      docker-compose -f ${DOCKER_COMPOSE_FILE} up -d ${APP_NAME} && sleep 10 && docker exec -i oracle-go godog && docker-compose -f ${DOCKER_COMPOSE_FILE} down
    

However the container is always brought up after the sleep (almost instantaneously).

Example:

Creating oracle-go ... 
Sleep 10
docker ps CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
docker exec -i oracle-go godog
Creating oracle-go ... done
Error response from daemon: Container 7bab5322203756b972e7f0a3c6e5827413279914a68c705221b8af7daadc1149 is not running

Please let me know if there is a way around it.

Bobo
  • 47
  • 1
  • 6

1 Answers1

0

If I understood your question correctly, you want to wait for the server to start before running tests.

Instead of manually sleeping, you should use wait-for-it.sh (or an alternative). See the relevant Docker docs for more information.

For example:

test-e2e:
  bash wait-for-it.sh <HOST>:<PORT> -- docker-compose -f ${DOCKER_COMPOSE_FILE} up -d ${APP_NAME} && docker exec -i oracle-go godog && docker-compose -f ${DOCKER_COMPOSE_FILE} down

Change <HOST> and <PORT> to your service's host name and port respectively. Alternatively, you could use wait-for-it.sh in your Docker Compose command or the like.

Neel Kamath
  • 1,188
  • 16
  • 34