So I’m writing a basic http server in c++ for school. At the moment my service can receive a request and send a basic response. I’m writing a basic acceptance test with python requests and executing it in a shell script by running the webserver in the background and then running the python client. Locally (on Mac) running the tests it works fine, also on a custom ubuntu docker container, which is also used for my config.yml file.
But when running the tests on circleCI the client seems to be accepted but the GET request is not being received and the program hangs.
Does anyone know why this is and how to solve it?
Please not that the include code is still being developed so be kind
My config.yml:
version: 2
jobs:
build:
docker:
- image: "rynosaurusrex/ci_for_codam:webserv"
steps:
- checkout
- run:
name: Build
command: 'echo Building'
- run:
name: Unit-Test
command: "make test && ./unit_test"
- run:
name: Acceptance-Test
command: make acceptence
My basic python GET request:
import time
import requests
from requests import Session
from enum import Enum
class Colors:
OKGREEN = '\033[92m'
FAILRED = '\033[91m'
NATURAL = '\033[0m'
OK = 200
BAD_REQUEST = 400
NOT_FOUND = 404
URI_TOO_LONG = 414
TEAPOT = 418
NOT_IMPLEMENTED = 501
localhost = "http://localhost:80"
EXIT_CODE = 0
print("Connecting to server...")
r = requests.get(localhost)
print("Request send!")
if r.status_code != OK:
print(f"{Colors.FAILRED}[KO] {Colors.NATURAL} Get request on http://localhost:80")
EXIT_CODE = 1;
else:
print(f"{Colors.OKGREEN}[OK] {Colors.NATURAL} Get request on http://localhost:80")
# sleep so that the exit code is that of the python script and not the server
time.sleep(1)
exit(EXIT_CODE)
and my messy bash script to run everything:
#!/bin/bash
# the & runs a command/program in the background
./Webserver.out &
# Save the PID to kill the webserv
PID=$!
# sleep for 2 second to make sure the server has time to start up
sleep 2
# run the tests
# curl localhost:80
python3 acceptence_tests/TestClient.py
# save the return val of the tests for CI
T1=$?
kill $PID
exit $T1
So I print a few status updates when running the tests. When printing Accepted client on fd
the accept() call was succesful but the request doesn’t seem to be coming through, possible a handshake issue? As mentioned above, running this locally and directly in the container delivers the expected results, how does local ports work within CircleCI?
Thanks in advance!