HTTP Request ConnectionRefusedError



I am testing my API during my build process. From the logs I can see the API starts correctly but all http requests sent by my unit test fail with the error message:

ConnectionRefusedError: [Errno 111] Connection refused

Here is the configuration I have in config.yml for these two steps;

  - run:
      name: Start API
      command: |
        . gql/bin/activate
        cd example
      background: true

  - run:
      name: Run Tests
      command: |
        . gql/bin/activate
        nose2 --plugin nose2.plugins.junitxml --junit-xml -v

When I start the API locally on my machine and run the tests, everything runs fine. From this point I’m a little bit stuck and don’t know how to investigate:

  • Is the issue coming from the API which is actually not running in background?
  • Is the issue coming from the http requests?

Here is an example of build failing:


(Ideally when posting error messages, they are best supplied as text in a formatted block if possible. This is because images are not compatible with clipboards, search engines and screen-readers. Supplying an image additionally is fine. Read more here.)

Couple of things to try:

  • There have been some reports of unusual DNS behaviour recently in CircleCI. It looks like you’re listening on, so make sure your client is making requests on that IP and not on localhost.
  • Consider adding a sleep 5 at the start of your tests - perhaps the server has not fully settled down before you are trying to make connections
  • In your “Run Tests” section you could do a ps aux before your activate to see what is running