Skip to content

Commit

Permalink
Merge pull request #382 from dantol29/slombard/web-286-fix-test-for-p…
Browse files Browse the repository at this point in the history
…arallel-requests-to-the-cgi

tests(parallel cgi): fix the test to send requests in parallel
  • Loading branch information
dantol29 authored May 21, 2024
2 parents 6ec0939 + abe64e2 commit fd91b8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions tests/parallel_cgi/duration_ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,35 @@
# done


#!/bin/bash

URL="http://127.0.0.1:8080/cgi-bin/duration_ts.cgi"
temp_file=$(mktemp)

# Send requests and collect the times
for i in {1..3}; do
echo "Sending request $i..."
response=$(curl -s -H "Host: www.development_site" $URL)
start_time=$(echo "$response" | grep -o 'Start time: [0-9.]*' | grep -o '[0-9.]*')
end_time=$(echo "$response" | grep -o 'End time: [0-9.]*' | grep -o '[0-9.]*')

if [[ -n "$start_time" && -n "$end_time" ]]; then
echo "$start_time Request $i: Start time = $start_time" >> "$temp_file"
echo "$end_time Request $i: End time = $end_time" >> "$temp_file"
else
echo "Failed to parse timestamps from request $i response"
fi
{
response=$(stdbuf -o0 curl -s -H "Host: www.development_site" $URL)
start_time=$(echo "$response" | grep -o 'Start time: [0-9.]*' | grep -o '[0-9.]*')
end_time=$(echo "$response" | grep -o 'End time: [0-9.]*' | grep -o '[0-9.]*')

if [[ -n "$start_time" && -n "$end_time" ]]; then
echo "$start_time Request $i: Start time = $start_time" >> "$temp_file"
echo "$end_time Request $i: End time = $end_time" >> "$temp_file"
else
echo "Failed to parse timestamps from request $i response"
fi
} &
done

# Wait for all background jobs to finish
wait

# Sort and print the times
sort -n "$temp_file" | while read -r line; do
echo "$line"
done

# Clean up temporary file
rm "$temp_file"

2 changes: 1 addition & 1 deletion var/www.development_site/cgi-bin/duration_ts.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import time
from datetime import datetime

# Define the duration of the counter in seconds
duration = 2
duration = 6

# Print the HTTP header
print("Content-Type: text/html")
Expand Down

0 comments on commit fd91b8b

Please sign in to comment.