Skip to content

Commit 74adaa2

Browse files
committed
Updated conformance tests scripts.
1 parent 9ce3a48 commit 74adaa2

File tree

2 files changed

+75
-31
lines changed

2 files changed

+75
-31
lines changed

test_scripts/run_conformance_tests_cypress.sh

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
NPM_INSTALL_OUTPUT_FILTER="up to date in|added [0-9]* packages, removed [0-9]* packages, and changed [0-9]* packages in|removed [0-9]* packages, and changed [0-9]* packages in|added [0-9]* packages in|removed [0-9]* packages in"
44

5+
# Function to check and kill any Node process running on port 3000 (React development server)
6+
check_and_kill_node_server() {
7+
# Find process listening on port 3000
8+
local pid=$(lsof -i :3000 -t 2>/dev/null)
9+
if [ ! -z "$pid" ]; then
10+
if ps -p $pid -o comm= | grep -q "node"; then
11+
printf "Found Node server running on port 3000. Killing it...\n"
12+
kill $pid 2>/dev/null
13+
sleep 1 # Give the process time to terminate
14+
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
15+
printf "Node server terminated.\n"
16+
fi
17+
fi
18+
fi
19+
}
20+
521
# Function to get all child processes of a given PID and store them in a list
622
get_children() {
723
local parent_pid=$1
@@ -16,6 +32,43 @@ get_children() {
1632
done
1733
}
1834

35+
# Cleanup function to ensure all processes are terminated
36+
cleanup() {
37+
# Kill any running npm processes started by this script
38+
if [ ! -z "${NPM_PID+x}" ]; then
39+
pkill -P $NPM_PID 2>/dev/null
40+
kill $NPM_PID 2>/dev/null
41+
fi
42+
43+
# Kill React app and its children if they exist
44+
if [ ! -z "${REACT_APP_PID+x}" ]; then
45+
local processes_to_kill=()
46+
get_children $REACT_APP_PID
47+
48+
# Kill the main process
49+
kill $REACT_APP_PID 2>/dev/null
50+
51+
# Kill all the subprocesses
52+
for pid in "${processes_to_kill[@]}"
53+
do
54+
kill $pid 2>/dev/null
55+
done
56+
57+
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
58+
printf "React app is terminated!\n"
59+
fi
60+
fi
61+
62+
# Remove temporary files if they exist
63+
[ -f "$build_output" ] && rm "$build_output" 2>/dev/null
64+
}
65+
66+
# Set up trap to call cleanup function on script exit, interrupt, or termination
67+
trap cleanup EXIT SIGINT SIGTERM
68+
69+
# Check for and kill any existing Node server from previous runs
70+
check_and_kill_node_server
71+
1972
# Check if build folder name is provided
2073
if [ -z "$1" ]; then
2174
printf "Error: No build folder name provided.\n"
@@ -109,6 +162,7 @@ BROWSER=none npm start -- --no-open > app.log 2>&1 &
109162

110163
# Capture the process ID of the npm start command
111164
REACT_APP_PID=$!
165+
NPM_PID=$(pgrep -P $REACT_APP_PID npm)
112166

113167
# Wait for the "compiled successfully!" message in the log file
114168
while true; do
@@ -168,28 +222,9 @@ if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
168222
printf "Running Cypress conformance tests...\n"
169223
fi
170224

171-
BROWSERSLIST_IGNORE_OLD_DATA=1 npx cypress run --config video=false 2>/dev/null
225+
BROWSERSLIST_IGNORE_OLD_DATA=1 npx cypress run --browser=chrome --config video=false 2>/dev/null
172226
cypress_run_result=$?
173227

174-
# Initialize an empty array to hold the PIDs
175-
processes_to_kill=()
176-
177-
# Start the recursive search from the given parent PID
178-
get_children $REACT_APP_PID
179-
180-
# Kill the main process
181-
kill $REACT_APP_PID
182-
183-
# Kill all the subprocesses
184-
for pid in "${processes_to_kill[@]}"
185-
do
186-
kill $pid
187-
done
188-
189-
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
190-
printf "React app is terminated!\n"
191-
fi
192-
193228
if [ $cypress_run_result -ne 0 ]; then
194229
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
195230
printf "Error: Cypress conformance tests have failed.\n"

test_scripts/run_conformance_tests_golang.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424

2525
# Check if the go build subfolder exists
2626
if [ -d "$GO_BUILD_SUBFOLDER" ]; then
27-
# Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
27+
# Find and delete all files and folders
2828
find "$GO_BUILD_SUBFOLDER" -mindepth 1 -exec rm -rf {} +
2929

3030
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
@@ -48,22 +48,31 @@ if [ $? -ne 0 ]; then
4848
exit 2
4949
fi
5050

51-
# Execute all Go lang conformance tests in the build folder
52-
printf "Compiling Golang conformance tests...\n\n"
51+
echo "Runinng go get in the build folder..."
52+
go get
5353

54-
output=$(go test -c $current_dir/$2/conformance_test.go 2>&1)
55-
exit_code=$?
54+
cd "$current_dir/$2" 2>/dev/null
5655

57-
# If there was an error, print the output and exit with the error code
58-
if [ $exit_code -ne 0 ]; then
59-
echo "$output"
60-
exit $exit_code
56+
if [ $? -ne 0 ]; then
57+
printf "Error: Conformance tests folder '$current_dir/$2' does not exist.\n"
58+
exit 2
6159
fi
6260

63-
# Execute all Go lang conformance tests in the build folder
61+
echo "Checking for go.mod in conformance test directory..."
62+
if [ -f "go.mod" ]; then
63+
echo "Running go get in conformance test directory..."
64+
go get
65+
else
66+
echo "No go.mod found in conformance test directory, skipping go get"
67+
fi
68+
69+
# Move back to build directory
70+
cd "$current_dir/$GO_BUILD_SUBFOLDER" 2>/dev/null
71+
72+
# Execute Go lang conformance tests
6473
printf "Running Golang conformance tests...\n\n"
6574

66-
output=$(./main.test 2>&1)
75+
output=$(go run $current_dir/$2/conformance_tests.go 2>&1)
6776
exit_code=$?
6877

6978
# If there was an error, print the output and exit with the error code

0 commit comments

Comments
 (0)