E2e tests, am I unable to connect to a service container via websockets?

Hi, I have a server infrastructure that’s moderately complex. It looks like this:

jobs:
  run-tests:
    name: run-tests
    runs-on: ubuntu-latest

    services:
      [database]
      [redis]
      websockets:
        image: [...]
        env:
          SERVER_ADDRESS: 'websockets:9999'

    steps:
      - [build Rails server]
      - [run Capybara tests]

When my e2e tests run, I get the following message from the browser for anything using websockets:

WebSocket connection to 'ws://websockets:9999/' failed: Connection closed before receiving a handshake response

Is anyone else encountering this or does anyone have any advice? I’ve got like three quarters of my e2e tests working, but there’s just little things involving session and websocket handling that have had me sidelined for weeks ;_;

On which host is the test that produced that error message running? If it’s running on the runner VM you need to either publish a server port (and then access it via localhost), or figure out the IP address using docker inspect or similar commands. Name resolution for the service containers works only within the Docker network.

Or you could use a job container, which should then be on the same network. :wink:

Thank you so much for responding!

It actually is running inside of a job container, I was just trying to avoid posting too many implementation details here.

jobs:
  run-tests:
    name: run-tests
    runs-on: ubuntu-latest
    container: ruby:2.6-slim

    services:
      [database]
      [redis]
      websockets:
        image: [...]
        env:
          SERVER_ADDRESS: 'websockets:9999'

    steps:
      - [build Rails server]
      - [run Capybara tests]

    env:
      WEBSOCKET_ADDRESS: 'ws://websockets:9999'

Unfortunately, even with the job container, I’m still seeing issues. Is there any chance the ws protocol part is getting in the way?

Maybe? I had initially interpreted the error message you shared as the socket being unreachable, but at a closer look it could also refer to an (early) protocol error. What I’d do from here:

  • Use something extremely simple to test the name resolution, just to make sure it works right (e.g. ping websockets).
  • Run a minimal websocket test on that server. Nothing specific to your application yet, just to make sure the protocol basics work.
  • Check if any part of your application actually requires wss:// (TLS-encrypted websocket).
1 Like