2
2
3
3
# Script to run integration tests locally
4
4
5
+ # Check if debug mode is enabled
6
+ DEBUG_ENV=" "
7
+ if [ " $1 " = " debug" ]; then
8
+ DEBUG_ENV=" NODE_DEBUG=mysql,net,stream"
9
+ echo " Debug mode enabled. Debug logs will be displayed."
10
+ fi
11
+
5
12
# Check if Docker is installed
6
13
if ! command -v docker & > /dev/null; then
7
14
echo " Docker is not installed. Please install Docker to run the integration tests."
@@ -38,17 +45,46 @@ for i in {1..30}; do
38
45
fi
39
46
done
40
47
48
+ # Add a more robust check to ensure MySQL is fully ready for connections
49
+ echo " Verifying MySQL connection stability..."
50
+ connection_success=false
51
+ for i in {1..5}; do
52
+ echo " Connection test $i /5..."
53
+ if ! $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SELECT 1;" & > /dev/null; then
54
+ echo " MySQL connection test failed. Waiting a bit longer..."
55
+ sleep 2
56
+ else
57
+ echo " Connection test successful."
58
+ connection_success=true
59
+ break
60
+ fi
61
+ done
62
+
63
+ if [ " $connection_success " = false ]; then
64
+ echo " Warning: All connection tests failed. Proceeding anyway, but tests might fail."
65
+ fi
66
+
67
+ # Final stabilization delay
68
+ echo " Waiting for MySQL to stabilize..."
69
+ sleep 5
70
+
41
71
# Show MySQL configuration for debugging
42
- echo " MySQL configuration:"
43
- $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%timeout%';"
44
- $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%max_connections%';"
45
- $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%max_allowed_packet%';"
72
+ if [ " $1 " = " debug" ]; then
73
+ echo " MySQL configuration:"
74
+ $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%timeout%';"
75
+ $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%max_connections%';"
76
+ $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " SHOW VARIABLES LIKE '%max_allowed_packet%';"
77
+ fi
78
+
79
+ # Prepare the database for tests
80
+ echo " Preparing test database..."
81
+ $DOCKER_COMPOSE exec -T mysql mysql -uroot -ppassword -e " DROP DATABASE IF EXISTS serverless_mysql_test; CREATE DATABASE serverless_mysql_test;"
46
82
47
83
# Run the integration tests
48
84
echo " Running integration tests..."
49
85
(
50
86
(
51
- sleep 60
87
+ sleep 90 # Increased timeout for tests
52
88
echo " Tests are taking too long, killing process..."
53
89
pkill -P $$ || true
54
90
for pid in $( ps -o pid= --ppid $$ ) ; do
@@ -58,13 +94,28 @@ echo "Running integration tests..."
58
94
) &
59
95
WATCHDOG_PID=$!
60
96
61
- echo " Starting tests with process ID: $$ "
62
- MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_DATABASE=serverless_mysql_test MYSQL_USER=root MYSQL_PASSWORD=password NODE_DEBUG=mysql,net,stream npm run test:integration
97
+ if [ " $1 " = " debug" ]; then
98
+ echo " Starting tests with process ID: $$ "
99
+ fi
100
+
101
+ # Add connection retry parameters to MySQL connection
102
+ MYSQL_HOST=127.0.0.1 \
103
+ MYSQL_PORT=3306 \
104
+ MYSQL_DATABASE=serverless_mysql_test \
105
+ MYSQL_USER=root \
106
+ MYSQL_PASSWORD=password \
107
+ MYSQL_CONNECT_TIMEOUT=10000 \
108
+ MYSQL_RETRY_COUNT=3 \
109
+ env $DEBUG_ENV npm run test:integration
110
+
63
111
TEST_EXIT_CODE=$?
64
112
65
113
echo " Tests completed with exit code: $TEST_EXIT_CODE "
66
114
67
- echo " Killing watchdog process: $WATCHDOG_PID "
115
+ if [ " $1 " = " debug" ]; then
116
+ echo " Killing watchdog process: $WATCHDOG_PID "
117
+ fi
118
+
68
119
kill $WATCHDOG_PID 2> /dev/null || true
69
120
70
121
exit $TEST_EXIT_CODE
@@ -75,7 +126,9 @@ echo "Cleaning up..."
75
126
$DOCKER_COMPOSE down
76
127
77
128
# Make sure no node processes are left hanging
78
- echo " Checking for hanging Node.js processes..."
79
- ps aux | grep node | grep -v grep || true
129
+ if [ " $1 " = " debug" ]; then
130
+ echo " Checking for hanging Node.js processes..."
131
+ ps aux | grep node | grep -v grep || true
132
+ fi
80
133
81
134
exit 0
0 commit comments