mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-25 18:49:36 -06:00
integration-tests/bats: sql-server.bats: Remove redundant max-connections behavior tests.
This commit is contained in:
@@ -2115,167 +2115,3 @@ EOF
|
||||
[[ "$output" =~ "br3 | true" ]] || false
|
||||
[[ "$output" =~ "main | false" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-server: test --max-connections and --back-log flags" {
|
||||
cd repo1
|
||||
# 3 connections allowed, everything else immediate failure.
|
||||
start_sql_server_with_args --max-connections 3 --back-log 0
|
||||
|
||||
# Start 3 long running connections.
|
||||
set +e # errors expected.
|
||||
pids=()
|
||||
for i in {1..3}; do
|
||||
dolt sql &
|
||||
pids+=($!)
|
||||
done
|
||||
|
||||
# Give the first 3 connections time to start/connect
|
||||
sleep 5
|
||||
|
||||
run dolt sql -q "select(1);"
|
||||
[ $status -ne 0 ]
|
||||
[[ "$output" =~ "bad connection" ]] || false
|
||||
|
||||
# Kill all the running shells
|
||||
for pid in "${pids[@]}"; do
|
||||
kill -9 "$pid"
|
||||
done
|
||||
}
|
||||
|
||||
@test "sql-server: test --max-connections 3 flag" {
|
||||
cd repo1
|
||||
|
||||
dolt sql -q "CREATE TABLE test_table (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
str VARCHAR(20)
|
||||
);"
|
||||
dolt commit -A -m "create test_table"
|
||||
|
||||
# 3 connections allowed, default back-log (50).
|
||||
start_sql_server_with_args --max-connections 3
|
||||
|
||||
set +e # errors expected.
|
||||
|
||||
# Start 3 long running connections.
|
||||
pids=()
|
||||
for i in {1..3}; do
|
||||
dolt sql &
|
||||
pids+=($!)
|
||||
done
|
||||
|
||||
sleep 1 # give all connections a chance to start
|
||||
|
||||
# These jobs will wait until there is a connection available. verify
|
||||
# by ensuring the inserts complete.
|
||||
dolt sql -q "insert into test_table (str) values ('test4223');" &
|
||||
second_to_last_pid=$!
|
||||
dolt sql -q "insert into test_table (str) values ('test9119');" &
|
||||
last_pid=$!
|
||||
|
||||
sleep 1
|
||||
|
||||
# Now have two jobs waiting for a connection.
|
||||
|
||||
# Kill all the running shells
|
||||
for pid in "${pids[@]}"; do
|
||||
kill -9 "$pid"
|
||||
done
|
||||
|
||||
wait "$second_to_last_pid"
|
||||
wait "$last_pid"
|
||||
|
||||
run dolt sql -q "select * from test_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "test4223" ]] || false
|
||||
[[ "$output" =~ "test9119" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-server: test --max-connections 3 and --back-log 1 flags" {
|
||||
cd repo1
|
||||
|
||||
dolt sql -q "CREATE TABLE test_table (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
str VARCHAR(20)
|
||||
);"
|
||||
dolt commit -A -m "create test_table"
|
||||
|
||||
# 3 connections allowed, 1 connection in back-log.
|
||||
start_sql_server_with_args --max-connections 3 --back-log 1
|
||||
|
||||
set +e # errors expected.
|
||||
# Start 3 long running connections.
|
||||
pids=()
|
||||
for i in {1..3}; do
|
||||
dolt sql &
|
||||
pids+=($!)
|
||||
done
|
||||
|
||||
# This job will wait until there is a connection available. verify
|
||||
# by ensuring the insert completes.
|
||||
dolt sql -q "insert into test_table (str) values ('test4223');" &
|
||||
last_pid=$!
|
||||
|
||||
sleep 1 # give all connections a chance to start
|
||||
|
||||
# This operation should fail immediately.
|
||||
run dolt sql -q "insert into test_table (str) values ('testxxxx');"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$stderr" =~ "bad connection" ]] || false
|
||||
|
||||
# Kill all the running shells
|
||||
for pid in "${pids[@]}"; do
|
||||
kill -9 "$pid"
|
||||
done
|
||||
|
||||
wait "$last_pid"
|
||||
|
||||
run dolt sql -q "select * from test_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "test4223" ]] || false
|
||||
[[ ! "$output" =~ "testxxxx" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "sql-server: test --max-connections-timeout 15s and --max-connections 3 flags" {
|
||||
skiponwindows "mysql client required"
|
||||
|
||||
cd repo1
|
||||
|
||||
export PORT=$( definePORT )
|
||||
|
||||
# Default is 60s, but I don't want to extend the test time for this.
|
||||
start_sql_server_with_args_no_port --max-connections-timeout=10s --max-connections=3 --back-log=10 --port=$PORT
|
||||
|
||||
# For this test we use the mysql client, which doesn't retry connections, but also seems to exit early
|
||||
# if we don't give it a query. So we use a sleep to hang the three connections. These will be killed, so
|
||||
# they won't run the full 30s.
|
||||
pids=()
|
||||
for i in {1..3}; do
|
||||
mysql -h 127.0.0.1 -P $PORT -u root -D repo1 -e "select sleep(30)" &
|
||||
pids+=($!)
|
||||
done
|
||||
|
||||
sleep 3
|
||||
|
||||
# Attempt to connect with a fourth connection - should fail after 10s. `run` caused a lot of variance in the test
|
||||
# time, so we avoid using it here.
|
||||
start_time=$(date +%s)
|
||||
set +e
|
||||
mysql -h 127.0.0.1 -P $PORT -u root > $BATS_TMPDIR/mysql.out
|
||||
status=$?
|
||||
end_time=$(date +%s)
|
||||
[ $status -ne 0 ]
|
||||
|
||||
# There is a high amount of variance in the time it takes to fail, so we just check that it is within a range
|
||||
# with a pretty high upper bound.
|
||||
elapsed_time=$((end_time - start_time))
|
||||
[[ $elapsed_time -lt 15 ]] || false
|
||||
[[ $elapsed_time -gt 9 ]] || false
|
||||
|
||||
run cat $BATS_TMPDIR/mysql.out
|
||||
[[ "$output" =~ "Lost connection to MySQL server at 'reading initial communication packet'" ]] || false
|
||||
|
||||
for pid in "${pids[@]}"; do
|
||||
kill "$pid" 2>/dev/null
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user