mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-30 03:26:47 -05:00
amend tests and add parser
This commit is contained in:
+84
-27
@@ -3,10 +3,10 @@ set -eo pipefail
|
||||
|
||||
# mysql_log logs messages with a timestamp and optional color formatting.
|
||||
# Arguments:
|
||||
# $1 - Log type (e.g., Note, Warn, ERROR)
|
||||
# $1 - Log type (e.g., Note, Warn, ERROR, Debug)
|
||||
# $@ - Log message (if empty, reads from stdin)
|
||||
# Output:
|
||||
# Prints a formatted log line to stdout or stderr, with color for Warn and ERROR.
|
||||
# Prints a formatted log line to stdout or stderr, with color for Warn, ERROR, and Debug.
|
||||
mysql_log() {
|
||||
local type="$1"
|
||||
shift
|
||||
@@ -17,24 +17,30 @@ mysql_log() {
|
||||
local color_reset="\033[0m"
|
||||
local color
|
||||
case "$type" in
|
||||
Warn) color="\033[1;33m" ;; # yellow
|
||||
ERROR) color="\033[1;31m" ;; # red
|
||||
Warning) color="\033[1;33m" ;; # yellow
|
||||
ERROR) color="\033[1;31m" ;; # red
|
||||
Debug) color="\033[1;34m" ;; # blue
|
||||
*) color="" ;;
|
||||
esac
|
||||
printf '%b%s [%s] [Entrypoint]: %s%b\n' "$color" "$dt" "$type" "$text" "$color_reset"
|
||||
}
|
||||
|
||||
# _dbg logs a message of type 'Debug' using mysql_log.
|
||||
_dbg() {
|
||||
mysql_log Debug "$@"
|
||||
}
|
||||
|
||||
# mysql_note logs a message of type 'Note' using mysql_log.
|
||||
mysql_note() {
|
||||
mysql_log Note "$@"
|
||||
}
|
||||
|
||||
# mysql_warn logs a message of type 'Warn' using mysql_log and writes to stderr.
|
||||
# mysql_warn logs a message of type 'Warning' using mysql_log and writes to stderr.
|
||||
mysql_warn() {
|
||||
mysql_log Warn "$@" >&2
|
||||
mysql_log Warning "$@" >&2
|
||||
}
|
||||
|
||||
# mysql_error logs a message of type 'ERROR' using mysql_log, write to stderr, prints a container removal hint, and
|
||||
# mysql_error logs a message of type 'ERROR' using mysql_log, writes to stderr, prints a container removal hint, and
|
||||
# exits with status 1.
|
||||
mysql_error() {
|
||||
mysql_log ERROR "$@" >&2
|
||||
@@ -42,6 +48,48 @@ mysql_error() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# dolt_log parses piped messages from `dolt sql-server` into the same format as mysql_log. Excludes debug as it can
|
||||
# de-sync log output. Users are provided the DOLT_RAW environment variable to disable the parser.
|
||||
dolt_log() {
|
||||
local color_reset="\033[0m"
|
||||
local color level msg dt
|
||||
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
# Skip empty lines
|
||||
[ -z "$line" ] && continue
|
||||
|
||||
# Extract timestamp (after time="..."), fallback empty if missing
|
||||
dt="${line#time=\"}"
|
||||
dt="${dt%%\"*}"
|
||||
|
||||
# Extract level (e.g. info, warn, error)
|
||||
level="${line#*level=}"
|
||||
level="${level%% *}"
|
||||
|
||||
# Extract msg=... (handle quoted or unquoted)
|
||||
if [[ "$line" == *'msg="'* ]]; then
|
||||
msg="${line#*msg=\"}"
|
||||
msg="${msg%%\"*}"
|
||||
elif [[ "$line" == *'msg='* ]]; then
|
||||
msg="${line#*msg=}"
|
||||
else
|
||||
msg="(no message)"
|
||||
fi
|
||||
|
||||
# Map level → display label + color
|
||||
case "${level,,}" in
|
||||
warn|warning) level="Warning"; color="\033[1;33m" ;; # yellow
|
||||
error) level="ERROR"; color="\033[1;31m" ;; # red
|
||||
debug) level="Debug"; color="\033[1;34m" ;; # blue
|
||||
info) level="Info"; color="" ;; # default
|
||||
*) level="Info"; color="" ;;
|
||||
esac
|
||||
|
||||
printf '%b%s [%s] [Dolt] [Server]: %s%b\n' \
|
||||
"$color" "$dt" "$level" "$msg" "$color_reset"
|
||||
done
|
||||
}
|
||||
|
||||
# exec_mysql executes a SQL query using Dolt, retrying until it succeeds or a timeout is reached.
|
||||
# On timeout, it prints the provided error message prefix followed by the command output.
|
||||
# Containers and system resources can hang during startup, so this function helps ensure
|
||||
@@ -55,17 +103,27 @@ exec_mysql() {
|
||||
local error_message="$2"
|
||||
local show_output="${3:-0}"
|
||||
local timeout="${DOLT_SERVER_TIMEOUT:-300}"
|
||||
local start_time now output
|
||||
local start_time now output status
|
||||
|
||||
start_time=$(date +%s)
|
||||
|
||||
while true; do
|
||||
if output=$(dolt sql -q "$sql_command" 2>&1); then
|
||||
if [ -n "$sql_command" ]; then
|
||||
output=$(dolt sql -q "$sql_command" 2>&1)
|
||||
status=$?
|
||||
else
|
||||
set +e # tmp disable to report error to user
|
||||
output=$(dolt sql < /dev/stdin 2>&1 | (grep -iE "Error|error" || true))
|
||||
status=$?
|
||||
set -e
|
||||
fi
|
||||
|
||||
if [ $status -eq 0 ]; then
|
||||
[ "$show_output" -eq 1 ] && echo "$output"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if echo "$output" | grep -qi "syntax error"; then
|
||||
if echo "$output" | grep -qiE "Error [0-9]+ \([A-Z0-9]+\)"; then
|
||||
mysql_error "$error_message$output"
|
||||
fi
|
||||
|
||||
@@ -80,6 +138,7 @@ exec_mysql() {
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
CONTAINER_DATA_DIR="/var/lib/dolt"
|
||||
INIT_COMPLETED="$CONTAINER_DATA_DIR/.init_completed"
|
||||
DOLT_CONFIG_DIR="/etc/dolt/doltcfg.d"
|
||||
@@ -171,9 +230,8 @@ get_config_file_path_if_exists() {
|
||||
# e.g., docker_process_init_files /always-initdb.d/*
|
||||
# Processes initializer files based on file extensions.
|
||||
docker_process_init_files() {
|
||||
mysql_note "Running init script...s"
|
||||
local f sql
|
||||
|
||||
echo
|
||||
for f; do
|
||||
case "$f" in
|
||||
*.sh)
|
||||
@@ -191,28 +249,24 @@ docker_process_init_files() {
|
||||
;;
|
||||
*.sql)
|
||||
mysql_note "$0: running $f"
|
||||
sql=$(cat "$f")
|
||||
exec_mysql "$sql" "Failed to execute $f: "
|
||||
exec_mysql "" "Failed to load $f: " < "$f"
|
||||
;;
|
||||
*.sql.bz2)
|
||||
mysql_note "$0: running $f"
|
||||
sql=$(bunzip2 -c "$f")
|
||||
exec_mysql "$sql" "Failed to execute $f: "
|
||||
bunzip2 -c "$f" | exec_mysql "" "Failed to load $f: " 1
|
||||
;;
|
||||
*.sql.gz)
|
||||
mysql_note "$0: running $f"
|
||||
sql=$(gunzip -c "$f")
|
||||
exec_mysql "$sql" "Failed to execute $f: "
|
||||
gunzip -c "$f" | exec_mysql "" "Failed to load $f: " 1
|
||||
;;
|
||||
*.sql.xz)
|
||||
mysql_note "$0: running $f"
|
||||
sql=$(xzcat "$f")
|
||||
exec_mysql "$sql" "Failed to execute $f: "
|
||||
xzcat "$f" | exec_mysql "" "Failed to load $f: " 1
|
||||
;;
|
||||
*.sql.zst)
|
||||
mysql_note "$0: running $f"
|
||||
sql=$(zstd -dc "$f")
|
||||
exec_mysql "$sql" "Failed to execute $f: "
|
||||
zstd -dc "$f" | exec_mysql "" "Failed to load $f: " 1
|
||||
;;
|
||||
*)
|
||||
mysql_warn "$0: ignoring $f"
|
||||
@@ -242,8 +296,8 @@ create_database_from_env() {
|
||||
database=$(get_env_var "DATABASE")
|
||||
|
||||
if [ -n "$database" ]; then
|
||||
mysql_note "Creating database '${database}'"
|
||||
exec_mysql "CREATE DATABASE IF NOT EXISTS \`$database\`;" "Failed to create database '$database': "
|
||||
mysql_note "Creating database '${database}'"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -319,18 +373,22 @@ dolt_server_initializer() {
|
||||
|
||||
SERVER_PID=-1
|
||||
|
||||
trap 'mysql_note "Caught Ctrl+C, shutting down Dolt server..."; [ $SERVER_PID -ne -1 ] && kill "$SERVER_PID"; exit 1' INT TERM
|
||||
trap '' SIGINT
|
||||
|
||||
while true; do
|
||||
if [ "$SERVER_PID" -eq -1 ] || ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
||||
[ "$SERVER_PID" -ne -1 ] && wait "$SERVER_PID" 2>/dev/null || true
|
||||
SERVER_PID=-1
|
||||
dolt sql-server --host=0.0.0.0 --port=3306 "$@" &
|
||||
if [ "${DOLT_RAW:-0}" -eq 1 ]; then
|
||||
dolt sql-server --host=0.0.0.0 --port=3306 "$@" 2>&1 &
|
||||
else
|
||||
dolt sql-server --host=0.0.0.0 --port=3306 "$@" 2>&1 | dolt_log &
|
||||
fi
|
||||
SERVER_PID=$!
|
||||
fi
|
||||
|
||||
if is_port_open "0.0.0.0" 3306; then
|
||||
mysql_note "Dolt server started successfully (PID=$SERVER_PID)"
|
||||
mysql_note "Dolt server started."
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -408,9 +466,8 @@ _main() {
|
||||
touch "$INIT_COMPLETED"
|
||||
fi
|
||||
|
||||
mysql_note "Server initialization complete!"
|
||||
mysql_note "Dolt init process done. Ready for connections."
|
||||
|
||||
# No need to relaunch, we wait for the background server process to exit and can still see the logs
|
||||
wait "$SERVER_PID"
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ FROM golang:1.25-bookworm AS build-from-source
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ARG DOLT_VERSION
|
||||
|
||||
# COPY doesn't support conditionals, so we rely on the path context to maybe have a dolt/ directory
|
||||
# to distinguish between source and binary builds using DOLT_VERSION=source too.
|
||||
COPY dolt*/go*/go.mod* /tmp/dolt/go/
|
||||
WORKDIR /tmp/dolt/go/
|
||||
|
||||
@@ -24,13 +26,12 @@ RUN if [ "$DOLT_VERSION" = "source" ]; then \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
fi
|
||||
|
||||
# Separate layers to avoid redundant downloads
|
||||
RUN if [ "$DOLT_VERSION" = "source" ]; then \
|
||||
go mod download; \
|
||||
fi
|
||||
|
||||
# COPY doesn't support conditionals, so we rely on the path context to maybe have a dolt/ directory
|
||||
# to distinguish between source and binary builds using DOLT_VERSION=source too.
|
||||
COPY dolt*/ /tmp/dolt/
|
||||
COPY dolt*/go/ /tmp/dolt/go/
|
||||
|
||||
RUN if [ "$DOLT_VERSION" = "source" ]; then \
|
||||
go build -o /usr/local/bin/dolt ./cmd/dolt && \
|
||||
|
||||
@@ -23,11 +23,10 @@ setup() {
|
||||
else
|
||||
echo "Using existing source-built image: $TEST_IMAGE"
|
||||
fi
|
||||
|
||||
docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker rm -f >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
teardown() {
|
||||
docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker stop >/dev/null 2>&1 || true
|
||||
docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker rm -f >/dev/null 2>&1 || true
|
||||
teardown_common
|
||||
}
|
||||
@@ -37,7 +36,7 @@ run_container() {
|
||||
name="$1"; shift
|
||||
docker run -d --name "$name" "$@" "$TEST_IMAGE" >/dev/null
|
||||
wait_for_log "$name" "Server ready. Accepting connections."
|
||||
wait_for_log "$name" "Server initialization complete!"
|
||||
wait_for_log "$name" "Dolt init process done. Ready for connections."
|
||||
|
||||
# Verify container is running
|
||||
run docker ps --filter "name=$name" --format "{{.Names}}"
|
||||
@@ -53,7 +52,7 @@ run_container_with_port() {
|
||||
port="$1"; shift
|
||||
docker run -d --name "$name" -p "$port:3306" "$@" "$TEST_IMAGE" >/dev/null
|
||||
wait_for_log "$name" "Server ready. Accepting connections."
|
||||
wait_for_log "$name" "Server initialization complete!"
|
||||
wait_for_log "$name" "Dolt init process done. Ready for connections."
|
||||
|
||||
# Verify container is running
|
||||
run docker ps --filter "name=$name" --format "{{.Names}}"
|
||||
@@ -86,7 +85,6 @@ wait_for_log() {
|
||||
i=0
|
||||
while [ $i -lt $timeout ]; do
|
||||
if docker logs "$name" 2>&1 | grep -q "$pattern"; then
|
||||
# Additional wait to ensure setup is complete
|
||||
sleep 1
|
||||
return 0
|
||||
fi
|
||||
@@ -576,13 +574,13 @@ GRANT ALL ON `plain_sql_db`.* TO 'plainsqluser'@'%';
|
||||
GRANT USAGE ON *.* TO 'plainsqluser'@'%';
|
||||
EOF
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "plain_sql_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE plain_sql_db; SELECT COUNT(*) as count FROM users_table;"
|
||||
run docker exec "$cname" dolt sql -q "USE plain_sql_db; SELECT COUNT(*) as count FROM users_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
|
||||
@@ -613,13 +611,13 @@ GRANT USAGE ON *.* TO 'gzipuser'@'%';
|
||||
EOF
|
||||
gzip "$temp_dir/01-init.sql"
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "gzip_sql_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE gzip_sql_db; SELECT COUNT(*) as count FROM products;"
|
||||
run docker exec "$cname" dolt sql -q "USE gzip_sql_db; SELECT COUNT(*) as count FROM products;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
|
||||
@@ -651,13 +649,13 @@ GRANT USAGE ON *.* TO 'bzip2user'@'%';
|
||||
EOF
|
||||
bzip2 "$temp_dir/01-init.sql"
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "bzip2_sql_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE bzip2_sql_db; SELECT SUM(total) as total FROM orders;"
|
||||
run docker exec "$cname" dolt sql -q "USE bzip2_sql_db; SELECT SUM(total) as total FROM orders;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "475.75" ]] || false
|
||||
|
||||
@@ -693,13 +691,13 @@ GRANT USAGE ON *.* TO 'xzuser'@'%';
|
||||
EOF
|
||||
xz "$temp_dir/01-init.sql"
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "xz_sql_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE xz_sql_db; SELECT COUNT(*) as count FROM inventory;"
|
||||
run docker exec "$cname" dolt sql -q "USE xz_sql_db; SELECT COUNT(*) as count FROM inventory;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "4" ]] || false
|
||||
|
||||
@@ -737,13 +735,13 @@ EOF
|
||||
zstd -q "$temp_dir/01-init.sql"
|
||||
rm -f "$temp_dir/01-init.sql" # zstd keeps original by default
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "zstd_sql_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE zstd_sql_db; SELECT COUNT(*) as count FROM employees;"
|
||||
run docker exec "$cname" dolt sql -q "USE zstd_sql_db; SELECT COUNT(*) as count FROM employees;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "5" ]] || false
|
||||
|
||||
@@ -759,102 +757,25 @@ EOF
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: large SQL file processing" {
|
||||
cname="${TEST_PREFIX}large-sql"
|
||||
|
||||
local temp_dir="/tmp/large-sql-test-$$"
|
||||
@test "docker-entrypoint: load employees database dump (.sql)" {
|
||||
cname="${TEST_PREFIX}employees-dump"
|
||||
local temp_dir="/tmp/employees-dump-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
# File 1: Create database, table, and insert rows 1-400 (2 batches of 200)
|
||||
cat > "$temp_dir/01-large-part1.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS large_test;
|
||||
USE large_test;
|
||||
CREATE TABLE bulk_data (id INT PRIMARY KEY, value VARCHAR(100), metadata TEXT);
|
||||
EOF
|
||||
curl -sL "https://raw.githubusercontent.com/datacharmer/test_db/master/load_employees.dump" -o "$temp_dir/load_employees.sql"
|
||||
sed -i '1iCREATE TABLE employees (id int, dob text, fn text, ln text, g text, dod text);' "$temp_dir/load_employees.sql"
|
||||
|
||||
for batch in {1..2}; do
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/01-large-part1.sql"
|
||||
start=$(( (batch - 1) * 200 + 1 ))
|
||||
end=$(( batch * 200 ))
|
||||
run_container_with_port "$cname" 3306 \
|
||||
-e DOLT_DATABASE=test \
|
||||
-v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/01-large-part1.sql"
|
||||
else
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger')," >> "$temp_dir/01-large-part1.sql"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# File 2: Insert rows 401-800 (2 batches of 200)
|
||||
cat > "$temp_dir/02-large-part2.sql" << 'EOF'
|
||||
USE large_test;
|
||||
EOF
|
||||
|
||||
for batch in {1..2}; do
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/02-large-part2.sql"
|
||||
start=$(( 400 + (batch - 1) * 200 + 1 ))
|
||||
end=$(( 400 + batch * 200 ))
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/02-large-part2.sql"
|
||||
else
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger')," >> "$temp_dir/02-large-part2.sql"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# File 3: Insert rows 801-1200 (2 batches of 200)
|
||||
cat > "$temp_dir/03-large-part3.sql" << 'EOF'
|
||||
USE large_test;
|
||||
EOF
|
||||
|
||||
for batch in {1..2}; do
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/03-large-part3.sql"
|
||||
start=$(( 800 + (batch - 1) * 200 + 1 ))
|
||||
end=$(( 800 + batch * 200 ))
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/03-large-part3.sql"
|
||||
else
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger')," >> "$temp_dir/03-large-part3.sql"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
docker run -d --name "$cname" -p 3306:3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d" "$TEST_IMAGE" >/dev/null
|
||||
|
||||
run docker ps --filter "name=$cname" --format "{{.Names}}"
|
||||
run docker exec "$cname" dolt sql -q "SHOW TABLES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ ^"$cname"$ ]] || false
|
||||
[[ "$output" =~ test.*employees ]] || false
|
||||
|
||||
wait_for_log "$cname" "Server initialization complete!" 45;
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
run docker exec "$cname" dolt sql -q "SELECT COUNT(*) > 0 AS has_rows FROM employees;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "large_test" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE large_test; SELECT COUNT(*) as count FROM bulk_data;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "1200" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE large_test; SELECT * FROM bulk_data WHERE id = 1;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "value_1" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE large_test; SELECT * FROM bulk_data WHERE id = 400;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "value_400" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE large_test; SELECT * FROM bulk_data WHERE id = 600;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "value_600" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE large_test; SELECT * FROM bulk_data WHERE id = 1200;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "value_1200" ]] || false
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
@@ -875,7 +796,7 @@ GRANT ALL PRIVILEGES ON *.* TO 'nautobot'@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_USER=nautobot -e DOLT_PASSWORD=nautobotpass -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 DOLT_USER=nautobot -e DOLT_PASSWORD=nautobotpass -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SELECT User, Host FROM mysql.user WHERE User='nautobot';"
|
||||
[ $status -eq 0 ]
|
||||
@@ -934,7 +855,7 @@ EOF
|
||||
|
||||
docker run -d --name "$cname" -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% "$LATEST_IMAGE" >/dev/null
|
||||
wait_for_log "$cname" "Server ready. Accepting connections."
|
||||
wait_for_log "$name" "Server initialization complete!"
|
||||
wait_for_log "$cname" "Dolt init process done. Ready for connections."
|
||||
|
||||
run docker exec "$cname" dolt version
|
||||
[ $status -eq 0 ]
|
||||
@@ -959,8 +880,8 @@ EOF
|
||||
docker build -f docker/serverDockerfile --build-arg DOLT_VERSION="$SPECIFIC_VERSION" -t "$SPECIFIC_IMAGE" .
|
||||
|
||||
docker run -d --name "$cname" -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% "$SPECIFIC_IMAGE" >/dev/null
|
||||
wait_for_log "$cname" "Server ready. Accepting connections."
|
||||
wait_for_log "$name" "Server initialization complete!"
|
||||
wait_for_log "$name" "Server ready. Accepting connections."
|
||||
wait_for_log "$name" "Dolt init process done. Ready for connections."
|
||||
|
||||
run docker exec "$cname" dolt version
|
||||
[ $status -eq 0 ]
|
||||
@@ -1012,7 +933,7 @@ EOF
|
||||
false
|
||||
fi
|
||||
|
||||
if ! wait_for_log "$cname-$cycle" "Server initialization complete!" 15; then
|
||||
if ! wait_for_log "$cname-$cycle" "Dolt init process done. Ready for connections." 15; then
|
||||
docker logs "$cname-$cycle"
|
||||
false
|
||||
fi
|
||||
@@ -1021,17 +942,15 @@ EOF
|
||||
for cycle in {1..40}; do
|
||||
run docker logs "$cname-$cycle" 2>&1
|
||||
[ $status -eq 0 ]
|
||||
# Should not contain ERROR messages
|
||||
if echo "$output" | grep -i "ERROR" >/dev/null; then
|
||||
echo "$output"
|
||||
false
|
||||
fi
|
||||
# Should contain success indicators
|
||||
if ! [[ "$output" =~ "Server initialization complete!" ]]; then
|
||||
if ! [[ "$output" =~ "Server ready. Accepting connections" ]]; then
|
||||
echo "$output"
|
||||
false
|
||||
fi
|
||||
if ! [[ "$output" =~ "Server ready. Accepting connections" ]]; then
|
||||
if ! [[ "$output" =~ "Dolt init process done. Ready for connections." ]]; then
|
||||
echo "$output"
|
||||
false
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user