Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 8

test http server in github actions

My library is about http server. I want to test it with github actions.

The code in my yml file looks like this:

jobs:
  linux:
    runs-on: ubuntu-18.04
    steps:
      - name: build
        run: |
          nohup start-http-server 8000 &
          curl http://127.0.0.1:8000/

The server can be started successfully, but curl fails.

 

I also tested with python and it failed again:

jobs:
  linux:
     runs-on: ubuntu-18.04
    steps:
      - name: build
        run: |
          nohup python -m SimpleHTTPServer &
          curl http://127.0.0.1:8000/

What should I do?

7 Replies
Highlighted
GitHub Partner
Message 2 of 8

Re: test http server in github actions

Can you share your repository with us? So that we can check the full configurations of your workflow and the detailed debug logs of the workflow run to analyze the root cause.

In addition, did you try the same commands on your local Linux machine (or VM) to see if they can work as expected?

Highlighted
Copilot Lvl 3
Message 3 of 8

Re: test http server in github actions

Is here, a very simple demo:

https://github.com/ygj6/verify/blob/master/.github/workflows/main.yml

I have tried it on my local computer and everything works fine.

Thanks.

Highlighted
Pilot Lvl 1
Message 4 of 8

Re: test http server in github actions

I've looked at the workflow log at https://github.com/ygj6/verify/runs/441227761, an I think here's your problem (from the Python process):

socket.error: [Errno 13] Permission denied

According to the workflow file you're trying to bind port 80 as a non-root user, which is not allowed. I'd recommend using another port (>1000). If port 80 is required for some reason you could try running your job in a container, or the relevant command with sudo.

Highlighted
Copilot Lvl 3
Message 5 of 8

Re: test http server in github actions

Thank you for your reply.

I tried 80, 8000 and other ports and they all failed.

Highlighted
Pilot Lvl 1
Message 6 of 8

Re: test http server in github actions

In your latest run (https://github.com/ygj6/verify/runs/445583346) the "permission denied" error from Python is gone at least.

 

My guess is that Curl tries to connect (and fails) before the Python server is ready to accept connections. In the previous log the Curl error also appeared before Python reported its own problem. To check if that's the issue you could try adding something like "sleep 5" between the commands. If that helps I'd recommend replacing the fixed sleep with something that actually waits for the service to be ready.

Highlighted
Copilot Lvl 3
Message 7 of 8

Re: test http server in github actions

It's ok when I add `sleep 5`. Thank you,  @airtower-luna  @BrightRan  and @ethomson 

Highlighted
GitHub Staff
Message 8 of 8

Re: test http server in github actions

Putting that in the background and running curl will basically hit that immediately.  Are you sure that your server actually is able to start and bind to the port before you try to hit it?  Does a `sleep` help?