concurrent connection test #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run HTTP Server Tests | |
on: [push] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: Install ApacheBench | |
run: | | |
sudo apt-get install -y apache2-utils | |
- name: Start HTTP Server | |
run: | | |
python server.py --directory ./store/ & | |
shell: bash | |
- name: Wait for server to start | |
run: | | |
sleep 5 | |
- name: GET / | |
run: | | |
response=$(curl -si http://localhost:4221/ --output response.raw) | |
printf "HTTP/1.1 200 OK\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: Test concurrent connections with ApacheBench | |
run: | | |
ab -n 100 -c 10 http://localhost:4221/ | |
- name: GET non-existent | |
run: | | |
response=$(curl --output response.raw -si http://localhost:4221/non-existent) | |
printf "HTTP/1.1 404 Not Found\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: ECHO strawberry | |
run: | | |
response=$(curl --output response.raw -si http://localhost:4221/echo/strawberry) | |
printf "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 10\r\n\r\nstrawberry" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: GET user-agent | |
run: | | |
response=$(curl --output response.raw -si http://localhost:4221/user-agent -H "User-Agent: apple/mango-mango") | |
printf "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 17\r\n\r\napple/mango-mango" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: POST file | |
run: | | |
curl -si -X POST http://localhost:4221/files/pineapple_grape_grape_pineapple \ | |
-H "Content-Length: 69" \ | |
-H "Content-Type: application/octet-stream" \ | |
-d 'blueberry blueberry orange mango raspberry blueberry banana blueberry' \ | |
--output response.raw | |
printf "HTTP/1.1 201 Created\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: case insensitivity test | |
run: | | |
curl -si -X POST http://localhost:4221/files/pineapple_grape_grape_pineapple \ | |
-H "ConteNt-LEngth:69" \ | |
-H "Content-type :application/octet-stream" \ | |
-d 'blueberry blueberry orange mango raspberry blueberry banana blueberry' \ | |
--output response.raw | |
printf "HTTP/1.1 201 Created\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: HEAD a file | |
run: | | |
curl -sI http://localhost:4221/files/pineapple_grape_grape_pineapple \ | |
--output response.raw | |
printf "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Length: 69\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi | |
- name: gzip test 1/2 | |
run: | | |
curl --output response0.raw -si -H "Accept-Encoding: gzip" http://localhost:4221/echo/abc | |
head -n 5 response0.raw > response.raw | |
printf "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 23\r\nContent-Encoding: gzip\r\n\r\n" > expected.raw | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
fi | |
- name: gzip test 2/2 | |
run: | | |
echo "to be added: a test of the hex output" | |
- name: Compression not known | |
run: | | |
curl --output response0.raw -si -H "Accept-Encoding: this-isnt-real-lol" http://localhost:4221/echo/abc | |
head -n 1 response0.raw > response.raw | |
printf "HTTP/1.1 406 Not Acceptable\r\n" > expected.raw # as long as 406 is there | |
if ! diff response.raw expected.raw; then | |
echo "Test failed!" | |
exit 1 | |
fi |