@@ -6,9 +6,9 @@ NPM_INSTALL_OUTPUT_FILTER="up to date in|added [0-9]* packages, removed [0-9]* p
66ANSI_ESCAPE_PATTERN=" s/\x1b\[[0-9;]*[mK]//g"
77
88# Maximum number of characters to display from log files
9- SNAP_IN_LOG_MAX_CHARS=80000
10- DEVREV_SERVER_LOG_MAX_CHARS=40000
11- PROXY_SERVER_LOG_MAX_CHARS=20000
9+ SNAP_IN_LOG_MAX_CHARS=100000
10+ DEVREV_SERVER_LOG_MAX_CHARS=600000
11+ PROXY_SERVER_LOG_MAX_CHARS=30000
1212
1313# Function to print a log file, truncating it if it's too large
1414print_log_file () {
@@ -52,19 +52,13 @@ source "$EXEC_DIR/.env"
5252set +a # stop automatically exporting
5353
5454# Function to check and kill any Node process running on port 8000 (React development server)
55- check_and_kill_node_server () {
55+ check_and_kill_processed_on_port () {
5656 local port=${1:- 8000} # Default to port 8000 if no port is provided
5757 # Find process listening on specified port
5858 local pid=$( lsof -i :$port -t 2> /dev/null)
5959 if [ ! -z " $pid " ]; then
60- if ps -p $pid | grep -q " node" ; then
6160 printf " Found server running on port $port . Killing it...\n"
62- kill $pid 2> /dev/null
63- sleep 1 # Give the process time to terminate
64- if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
65- printf " Node server terminated.\n"
66- fi
67- fi
61+ kill -9 " $pid " 2> /dev/null
6862 fi
6963}
7064
@@ -84,10 +78,20 @@ get_children() {
8478
8579# Function to start the mock DevRev server
8680start_mock_devrev_server () {
87- python3 " $SCRIPT_DIR /mock_devrev_server.py" > " $MOCK_DEVREV_SERVER_LOG " 2>&1 &
81+ python3 -u " $SCRIPT_DIR /mock_devrev_server.py" > " $MOCK_DEVREV_SERVER_LOG " 2>&1 &
8882 MOCK_SERVER_PID=$!
89- sleep 2 # Give the server time to start
90- printf " \n"
83+
84+ # Wait until the mock DevRev server prints its startup line to the log
85+ while true ; do
86+ printf " Waiting for the DevRev server to start...\n"
87+ # If process already died, surface error and logs
88+ if grep -iq -E " Starting DevRev server on|Uvicorn running on" " $MOCK_DEVREV_SERVER_LOG " 2> /dev/null; then
89+ break
90+ fi
91+ sleep 0.1
92+ done
93+
94+ printf " DevRev server is up and running!\n\n"
9195}
9296
9397start_proxy_server () {
@@ -96,11 +100,19 @@ start_proxy_server() {
96100 printf " Error: rate_limiting_proxy.py file not found in $EXEC_DIR /rate_limiting_proxy.py. This file should exist (and should be adopted for 3rd party service's rate limiting response format).\n"
97101 exit 69
98102 fi
99- python3 " $EXEC_DIR /rate_limiting_proxy.py" > " $PROXY_SERVER_LOG " 2>&1 &
103+ # The -u flag is critical here to disable python's output buffering, ensuring logs are written immediately.
104+ python3 -u " $EXEC_DIR /rate_limiting_proxy.py" > " $PROXY_SERVER_LOG " 2>&1 &
100105 PROXY_SERVER_PID=$!
101- sleep 2 # Give the server time to start
102106
103- # Check if the proxy server started successfully.
107+ # Wait until the proxy server prints its startup line to the log
108+ while true ; do
109+ printf " Waiting for the proxy server to start...\n"
110+ if grep -iq -E " Starting proxy server on" " $PROXY_SERVER_LOG " 2> /dev/null; then
111+ break
112+ fi
113+ sleep 0.1
114+ done
115+
104116 if ! kill -0 " $PROXY_SERVER_PID " > /dev/null 2>&1 ; then
105117 wait " $PROXY_SERVER_PID "
106118 EXIT_CODE=$?
@@ -110,15 +122,16 @@ start_proxy_server() {
110122 exit 69
111123 fi
112124 fi
113- printf " \n"
125+
126+ printf " Proxy server is up and running!\n\n"
114127}
115128
116129# Cleanup function to ensure all processes are terminated
117130cleanup () {
118131 # Kill any running npm processes started by this script
119132 if [ ! -z " ${NPM_PID+x} " ]; then
120- pkill -P $NPM_PID 2> /dev/null
121- kill $NPM_PID 2> /dev/null
133+ pkill -9 - P $NPM_PID > /dev/null 2>&1
134+ kill -9 $NPM_PID > /dev/null 2>&1
122135 fi
123136
124137 # Kill React app and its children if they exist
@@ -127,12 +140,12 @@ cleanup() {
127140 get_children $SNAP_IN_PID
128141
129142 # Kill the main process
130- kill $SNAP_IN_PID 2> /dev/null
143+ kill -9 $SNAP_IN_PID > /dev/null 2>&1
131144
132145 # Kill all the subprocesses
133146 for pid in " ${processes_to_kill[@]} "
134147 do
135- kill $pid 2> /dev/null
148+ kill -9 $pid > /dev/null 2>&1
136149 done
137150
138151 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
@@ -142,15 +155,15 @@ cleanup() {
142155
143156 # Kill mock DevRev server if it exists
144157 if [ ! -z " ${MOCK_SERVER_PID+x} " ]; then
145- kill $MOCK_SERVER_PID 2> /dev/null
158+ kill -9 $MOCK_SERVER_PID > /dev/null 2>&1
146159 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
147160 printf " Mock DevRev server terminated!\n"
148161 fi
149162 fi
150163
151164 # Kill proxy server if it exists
152165 if [ ! -z " ${PROXY_SERVER_PID+x} " ]; then
153- kill $PROXY_SERVER_PID 2> /dev/null
166+ kill -9 $PROXY_SERVER_PID > /dev/null 2>&1
154167 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
155168 printf " Proxy server terminated!\n"
156169 fi
@@ -166,32 +179,15 @@ cleanup() {
166179trap cleanup EXIT SIGINT SIGTERM
167180
168181# Check for and kill any existing servers from previous runs
169- check_and_kill_node_server 8000
170- check_and_kill_node_server 8002
171-
172- # Ensure nothing is running on port 8003, then start the mock DevRev server
173- existing_pids=$( lsof -i :8003 -t 2> /dev/null)
174- if [ ! -z " $existing_pids " ]; then
175- printf " Killing existing process(es) on port 8003: %s\n" " $existing_pids "
176- for pid in $existing_pids ; do
177- kill $pid 2> /dev/null
178- done
179- sleep 1
180- fi
182+ check_and_kill_processed_on_port 8000
183+ check_and_kill_processed_on_port 8002
184+ check_and_kill_processed_on_port 8003
185+ check_and_kill_processed_on_port 8004
186+
181187start_mock_devrev_server
182188
183189# Set HTTPS_PROXY environment variable to point to proxy server
184190export HTTPS_PROXY=" http://localhost:8004"
185-
186- # Ensure nothing is running on port 8004, then start the proxy server
187- existing_pids_8004=$( lsof -i :8004 -t 2> /dev/null)
188- if [ ! -z " $existing_pids_8004 " ]; then
189- printf " Killing existing process(es) on port 8004: %s\n" " $existing_pids_8004 "
190- for pid in $existing_pids_8004 ; do
191- kill $pid 2> /dev/null
192- done
193- sleep 1
194- fi
195191start_proxy_server
196192
197193# Check if chef-cli binary exists at CHEF_CLI_PATH
@@ -207,9 +203,9 @@ if [ -z "$EXTRACTED_FILES_FOLDER_PATH" ]; then
207203fi
208204
209205# Check if EXTRACTED_FILES_FOLDER_PATH does not end with "node_$1/build"
210- if [[ " $EXTRACTED_FILES_FOLDER_PATH " != * " node_ $1 /extracted_files" ]]; then
206+ if [[ " $EXTRACTED_FILES_FOLDER_PATH " != * " node_build /extracted_files" ]]; then
211207 echo " Error: EXTRACTED_FILES_FOLDER_PATH should end with 'node_$1 /extracted_files'."
212- echo " Note: The value of EXTRACTED_FILES_FOLDER_PATH should be <path_to_directory_where_you_rendered_the_snap-in>/node_ $1 /extracted_files."
208+ echo " Note: The value of EXTRACTED_FILES_FOLDER_PATH should be <path_to_directory_where_you_rendered_the_snap-in>/node_build /extracted_files."
213209 exit 69 # EXIT_SERVICE_UNAVAILABLE
214210fi
215211
247243
248244# Check if the node subfolder exists
249245if [ -d " $NODE_SUBFOLDER " ]; then
250- # Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
251- find " $NODE_SUBFOLDER " -mindepth 1 ! -path " $NODE_SUBFOLDER /node_modules*" ! -path " $NODE_SUBFOLDER /build* " ! -name " package-lock.json " -exec rm -rf {} +
246+ # Find and delete all files and folders except "node_modules"
247+ find " $NODE_SUBFOLDER " -mindepth 1 ! -path " $NODE_SUBFOLDER /node_modules*" -exec rm -rf {} +
252248
253249 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
254- printf " Cleanup completed, keeping 'node_modules' and 'package-lock.json' .\n"
250+ printf " Cleanup completed, keeping 'node_modules'.\n"
255251 fi
256252else
257253 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
333329
334330# Check if the conformance tests node subfolder exists
335331if [ -d " $NODE_CONFORMANCE_TESTS_SUBFOLDER " ]; then
336- # Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
337- find " $NODE_CONFORMANCE_TESTS_SUBFOLDER " -mindepth 1 ! -path " $NODE_CONFORMANCE_TESTS_SUBFOLDER /node_modules*" ! -path " $NODE_CONFORMANCE_TESTS_SUBFOLDER /build* " ! -name " package-lock.json " -exec rm -rf {} +
332+ # Find and delete all files and folders except "node_modules"
333+ find " $NODE_CONFORMANCE_TESTS_SUBFOLDER " -mindepth 1 ! -path " $NODE_CONFORMANCE_TESTS_SUBFOLDER /node_modules*" -exec rm -rf {} +
338334
339335 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
340- printf " Cleanup completed, keeping 'node_modules' and 'package-lock.json' .\n"
336+ printf " Cleanup completed, keeping 'node_modules'.\n"
341337 fi
342338else
343339 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
367363
368364printf " \n#### Running conformance tests...\n"
369365
370- npm test -- --runInBand --setupFilesAfterEnv=" $SCRIPT_DIR /jest.setup.js" --detectOpenHandles 2>&1 | sed -E " $ANSI_ESCAPE_PATTERN "
366+ npm test -- --runInBand --setupFilesAfterEnv=" $SCRIPT_DIR /jest.setup.js" --detectOpenHandles --forceExit 2>&1 | sed -E " $ANSI_ESCAPE_PATTERN "
371367conformance_tests_result=$?
372368
373369printf " \n#### Output of the DevRev server log file:\n\n"
374370print_log_file " $MOCK_DEVREV_SERVER_LOG " " $DEVREV_SERVER_LOG_MAX_CHARS "
375371printf " \n#### Output of The Snap-In log file:\n"
376372print_log_file " $NODE_SUBFOLDER /app.log" " $SNAP_IN_LOG_MAX_CHARS "
377- printf " \n"
373+ # uncomment if you need the logs of the proxy server
374+ # printf "\n#### Output of the proxy server log file:\n\n"
375+ # print_log_file "$PROXY_SERVER_LOG" "$PROXY_SERVER_LOG_MAX_CHARS"
378376printf " \n"
379377
380378if [ $conformance_tests_result -ne 0 ]; then
381379 if [ " ${VERBOSE:- } " -eq 1 ] 2> /dev/null; then
382380 printf " Error: Conformance tests have failed.\n"
383381 fi
384382 exit 2
385- fi
383+ fi
0 commit comments