Skip to content

Commit c8881b2

Browse files
author
michael stack
committed
Use MockS3Server instead of seaweedfs for ctest.
Avoid download of seaweedfs and the 25second startup. Preserve the try-another-port if expected is occupied. Preserve use of s3 if available.
1 parent 9f0744d commit c8881b2

File tree

10 files changed

+518
-371
lines changed

10 files changed

+518
-371
lines changed

fdbbackup/tests/s3_backup_test.sh

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Test backup and restore from s3.
44
#
55
# In the below we start a small FDB cluster, populate it with
6-
# some data and then start up a seaweedfs instance or use S3
6+
# some data and then start up MockS3Server or use S3
77
# if it is available. We then run a backup to 'S3' and then
88
# a restore. We verify the restore is the same as the original.
99
#
@@ -27,13 +27,16 @@ function cleanup {
2727
if type shutdown_fdb_cluster &> /dev/null; then
2828
shutdown_fdb_cluster
2929
fi
30-
if type shutdown_weed &> /dev/null; then
31-
shutdown_weed "${TEST_SCRATCH_DIR}"
30+
if type shutdown_mocks3 &> /dev/null; then
31+
shutdown_mocks3
3232
fi
3333
if type shutdown_aws &> /dev/null; then
3434
shutdown_aws "${TEST_SCRATCH_DIR}"
3535
fi
36+
37+
# Clean up encryption key file
3638
if [[ -n "${ENCRYPTION_KEY_FILE:-}" ]] && [[ -f "${ENCRYPTION_KEY_FILE}" ]]; then
39+
echo "Removing encryption key file: ${ENCRYPTION_KEY_FILE}"
3740
rm -f "${ENCRYPTION_KEY_FILE}"
3841
fi
3942
}
@@ -71,9 +74,6 @@ function backup {
7174
local local_credentials="${4}"
7275
local local_encryption_key_file="${5:-}"
7376

74-
# Backup to s3. Without the -k argument in the below, the backup gets
75-
# 'No restore target version given, will use maximum restorable version from backup description.'
76-
# TODO: Why is -k needed?
7777
local cmd_args=(
7878
"-C" "${local_scratch_dir}/loopback_cluster/fdb.cluster"
7979
"-t" "${TAG}" "-w"
@@ -113,7 +113,7 @@ function restore {
113113
local cmd_args=(
114114
"--dest-cluster-file" "${local_scratch_dir}/loopback_cluster/fdb.cluster"
115115
"-t" "${TAG}" "-w"
116-
"-r" "${url}"
116+
"-r" "${local_url}"
117117
"--log" "--logdir=${local_scratch_dir}"
118118
"--blob-credentials" "${local_credentials}"
119119
)
@@ -145,17 +145,12 @@ function test_s3_backup_and_restore {
145145
local local_build_dir="${4}"
146146
local local_encryption_key_file="${5:-}"
147147

148-
log "Load data"
149-
if ! load_data "${local_build_dir}" "${local_scratch_dir}"; then
150-
err "Failed loading data into fdb"
151-
return 1
152-
fi
153148
# Edit the url. Backup adds 'data' to the path. Need this url for
154149
# cleanup of test data.
155150
local edited_url=$(echo "${local_url}" | sed -e "s/ctest/data\/ctest/" )
156151
readonly edited_url
157152
if [[ "${USE_S3}" == "true" ]]; then
158-
# Run this rm only if s3. In seaweed, it would fail because
153+
# Run this rm only if s3. In MockS3Server, it would fail because
159154
# bucket doesn't exist yet (they are lazily created).
160155
local preclear_cmd=("${local_build_dir}/bin/s3client")
161156
preclear_cmd+=("${KNOBS[@]}")
@@ -169,6 +164,11 @@ function test_s3_backup_and_restore {
169164
return 1
170165
fi
171166
fi
167+
log "Load data"
168+
if ! load_data "${local_build_dir}" "${local_scratch_dir}"; then
169+
err "Failed loading data into fdb"
170+
return 1
171+
fi
172172
log "Run s3 backup"
173173
if ! backup "${local_build_dir}" "${local_scratch_dir}" "${local_url}" "${credentials}" "${local_encryption_key_file}"; then
174174
err "Failed backup"
@@ -197,7 +197,7 @@ function test_s3_backup_and_restore {
197197
local cleanup_cmd=("${local_build_dir}/bin/s3client")
198198
cleanup_cmd+=("${KNOBS[@]}")
199199

200-
# Only add TLS CA file for real S3, not SeaweedFS
200+
# Only add TLS CA file for real S3, not MockS3Server
201201
if [[ "${USE_S3}" == "true" ]]; then
202202
cleanup_cmd+=("--tls-ca-file" "${TLS_CA_FILE}")
203203
fi
@@ -369,7 +369,9 @@ while (( "$#" )); do
369369
done
370370

371371
# Set positional arguments in their proper place
372-
set -- "${PARAMS[@]}"
372+
if [ ${#PARAMS[@]} -ne 0 ]; then
373+
set -- "${PARAMS[@]}"
374+
fi
373375

374376
# Globals
375377
# TEST_SCRATCH_DIR gets set below. Tests should be their data in here.
@@ -382,17 +384,17 @@ readonly TAG="test_backup"
382384
# internal apple dev environments where S3 is available).
383385
readonly USE_S3="${USE_S3:-$( if [[ -n "${OKTETO_NAMESPACE+x}" ]]; then echo "true" ; else echo "false"; fi )}"
384386

385-
# Set KNOBS based on whether we're using real S3 or SeaweedFS
387+
# Set KNOBS based on whether we're using real S3 or MockS3Server
386388
if [[ "${USE_S3}" == "true" ]]; then
387389
# Use AWS KMS encryption for real S3
388390
KNOBS=("--knob_blobstore_encryption_type=aws:kms" "--knob_http_verbose_level=${HTTP_VERBOSE_LEVEL}")
389391
else
390-
# No encryption for SeaweedFS
392+
# No encryption for MockS3Server
391393
KNOBS=("--knob_http_verbose_level=${HTTP_VERBOSE_LEVEL}")
392394
fi
393395
readonly KNOBS
394396

395-
# Set TLS_CA_FILE only when using real S3, not for SeaweedFS
397+
# Set TLS_CA_FILE only when using real S3, not for MockS3Server
396398
if [[ "${USE_S3}" == "true" ]]; then
397399
# Try to find a valid TLS CA file if not explicitly set
398400
if [[ -z "${TLS_CA_FILE:-}" ]]; then
@@ -406,7 +408,7 @@ if [[ "${USE_S3}" == "true" ]]; then
406408
fi
407409
TLS_CA_FILE="${TLS_CA_FILE:-}"
408410
else
409-
# For SeaweedFS, don't use TLS
411+
# For MockS3Server, don't use TLS
410412
TLS_CA_FILE=""
411413
fi
412414
readonly TLS_CA_FILE
@@ -471,7 +473,7 @@ else
471473
fi
472474
readonly ENCRYPTION_KEY_FILE
473475

474-
# Set host, bucket, and blob_credentials_file whether seaweed or s3.
476+
# Set host, bucket, and blob_credentials_file whether MockS3Server or s3.
475477
readonly path_prefix="ctests"
476478
host=
477479
query_str=
@@ -502,30 +504,31 @@ if [[ "${USE_S3}" == "true" ]]; then
502504
export FDB_BLOB_CREDENTIALS="${blob_credentials_file}"
503505
export FDB_TLS_CA_FILE="${TLS_CA_FILE}"
504506
else
505-
log "Testing against seaweedfs"
506-
# Now source in the seaweedfs fixture so we can use its methods in the below.
507+
log "Testing against MockS3Server"
508+
# Now source in the mocks3 fixture so we can use its methods in the below.
507509
# shellcheck source=/dev/null
508-
if ! source "${cwd}/../../fdbclient/tests/seaweedfs_fixture.sh"; then
509-
err "Failed to source seaweedfs_fixture.sh"
510+
if ! source "${cwd}/../../fdbclient/tests/mocks3_fixture.sh"; then
511+
err "Failed to source mocks3_fixture.sh"
510512
exit 1
511513
fi
512-
if ! TEST_SCRATCH_DIR=$(create_weed_dir "${scratch_dir}"); then
513-
err "Failed create of the weed dir." >&2
514-
return 1
514+
if ! TEST_SCRATCH_DIR=$(mktemp -d "${scratch_dir}/mocks3_backup_test.XXXXXX"); then
515+
err "Failed create of the mocks3 test dir." >&2
516+
exit 1
515517
fi
516518
readonly TEST_SCRATCH_DIR
517-
if ! host=$( run_weed "${scratch_dir}" "${TEST_SCRATCH_DIR}"); then
518-
err "Failed to run seaweed"
519-
return 1
519+
if ! start_mocks3 "${build_dir}"; then
520+
err "Failed to start MockS3Server"
521+
exit 1
520522
fi
521-
readonly host
522-
readonly bucket="${SEAWEED_BUCKET}"
523-
readonly region="all_regions"
524-
# Reference a non-existent blob file (its ignored by seaweed)
523+
readonly host="${MOCKS3_HOST}:${MOCKS3_PORT}"
524+
readonly bucket="test-bucket"
525+
readonly region="us-east-1"
526+
# Create an empty blob credentials file (MockS3Server uses simple auth)
525527
readonly blob_credentials_file="${TEST_SCRATCH_DIR}/blob_credentials.json"
526-
# Let the connection to seaweed be insecure -- not-TLS -- because just awkward to set up.
528+
echo '{}' > "${blob_credentials_file}"
529+
# Let the connection to MockS3Server be insecure -- not-TLS
527530
query_str="bucket=${bucket}&region=${region}&secure_connection=0"
528-
# Set environment variables for SeaweedFS too
531+
# Set environment variables for MockS3Server
529532
export FDB_BLOB_CREDENTIALS="${blob_credentials_file}"
530533
fi
531534

fdbclient/tests/bulkload_test.sh

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash
22
#
3-
# Test bulkload. Uses S3 or seaweedfs if not available:
4-
# (https://github.com/seaweedfs/seaweedfs) as substitute.
3+
# Test bulkload. Uses S3 or MockS3Server if not available.
54
#
65
# In the below we start a small FDB cluster, populate it with
7-
# some data and then start up a seaweedfs instance. We
6+
# some data and then start up MockS3Server. We
87
# then run a bulkdump to 'S3' and then a restore. We verify
98
# the restore is the same as the original.
109
#
@@ -13,7 +12,8 @@
1312
# so you can manually rerun commands or peruse logs and data
1413
# under SCRATCH_DIR.
1514

16-
# Make sure cleanup on script exit.
15+
# Install signal traps. Depends on globals being set.
16+
# Calls the cleanup function.
1717
trap "exit 1" HUP INT PIPE QUIT TERM
1818
trap cleanup EXIT
1919

@@ -22,8 +22,8 @@ function cleanup {
2222
if type shutdown_fdb_cluster &> /dev/null; then
2323
shutdown_fdb_cluster
2424
fi
25-
if type shutdown_weed &> /dev/null; then
26-
shutdown_weed "${TEST_SCRATCH_DIR}"
25+
if type shutdown_mocks3 &> /dev/null; then
26+
shutdown_mocks3
2727
fi
2828
if type shutdown_aws &> /dev/null; then
2929
shutdown_aws "${TEST_SCRATCH_DIR}"
@@ -252,17 +252,17 @@ readonly HTTP_VERBOSE_LEVEL=2
252252
# internal apple dev environments where S3 is available).
253253
readonly USE_S3="${USE_S3:-$( if [[ -n "${OKTETO_NAMESPACE+x}" ]]; then echo "true" ; else echo "false"; fi )}"
254254

255-
# Set KNOBS based on whether we're using real S3 or SeaweedFS
255+
# Set KNOBS based on whether we're using real S3 or MockS3Server
256256
if [[ "${USE_S3}" == "true" ]]; then
257257
# Use AWS KMS encryption for real S3
258258
KNOBS=("--knob_blobstore_encryption_type=aws:kms" "--knob_http_verbose_level=${HTTP_VERBOSE_LEVEL}")
259259
else
260-
# No encryption for SeaweedFS
260+
# No encryption for MockS3Server
261261
KNOBS=("--knob_http_verbose_level=${HTTP_VERBOSE_LEVEL}")
262262
fi
263263
readonly KNOBS
264264

265-
# Set TLS_CA_FILE only when using real S3, not for SeaweedFS
265+
# Set TLS_CA_FILE only when using real S3, not for SeaweedFS or MockS3Server
266266
if [[ "${USE_S3}" == "true" ]]; then
267267
# Try to find a valid TLS CA file if not explicitly set
268268
if [[ -z "${TLS_CA_FILE:-}" ]]; then
@@ -276,7 +276,7 @@ if [[ "${USE_S3}" == "true" ]]; then
276276
fi
277277
TLS_CA_FILE="${TLS_CA_FILE:-}"
278278
else
279-
# For SeaweedFS, don't use TLS
279+
# For SeaweedFS and MockS3Server, don't use TLS
280280
TLS_CA_FILE=""
281281
fi
282282
readonly TLS_CA_FILE
@@ -362,28 +362,29 @@ if [[ "${USE_S3}" == "true" ]]; then
362362
export FDB_TLS_CA_FILE="${TLS_CA_FILE}"
363363
fi
364364
else
365-
log "Testing against seaweedfs"
366-
# Now source in the seaweedfs fixture so we can use its methods in the below.
365+
log "Testing against MockS3Server"
366+
# Now source in the mocks3 fixture so we can use its methods in the below.
367367
# shellcheck source=/dev/null
368-
if ! source "${cwd}/../../fdbclient/tests/seaweedfs_fixture.sh"; then
369-
err "Failed to source seaweedfs_fixture.sh"
368+
if ! source "${cwd}/../../fdbclient/tests/mocks3_fixture.sh"; then
369+
err "Failed to source mocks3_fixture.sh"
370370
exit 1
371371
fi
372-
if ! TEST_SCRATCH_DIR=$(create_weed_dir "${scratch_dir}"); then
373-
err "Failed create of the weed dir." >&2
372+
if ! TEST_SCRATCH_DIR=$(mktemp -d "${scratch_dir}/mocks3_bulkload_test.XXXXXX"); then
373+
err "Failed create of the mocks3 test dir." >&2
374374
exit 1
375375
fi
376376
readonly TEST_SCRATCH_DIR
377-
if ! host=$( run_weed "${scratch_dir}" "${TEST_SCRATCH_DIR}"); then
378-
err "Failed to run seaweed"
377+
if ! start_mocks3 "${build_dir}"; then
378+
err "Failed to start MockS3Server"
379379
exit 1
380380
fi
381-
readonly host
382-
readonly bucket="${SEAWEED_BUCKET}"
383-
readonly region="all_regions"
384-
# Reference a non-existent blob file (its ignored by seaweed)
381+
readonly host="${MOCKS3_HOST}:${MOCKS3_PORT}"
382+
readonly bucket="test-bucket"
383+
readonly region="us-east-1"
384+
# Create an empty blob credentials file (MockS3Server uses simple auth)
385385
readonly blob_credentials_file="${TEST_SCRATCH_DIR}/blob_credentials.json"
386-
# Let the connection to seaweed be insecure -- not-TLS -- because just awkward to set up.
386+
echo '{}' > "${blob_credentials_file}"
387+
# Let the connection to MockS3Server be insecure -- not-TLS
387388
query_str="bucket=${bucket}&region=${region}&secure_connection=0"
388389
fi
389390

fdbclient/tests/fdb_cluster_fixture.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ FDB_PIDS=()
1111

1212
# Shutdown all processes.
1313
function shutdown_fdb_cluster {
14-
# Kill all running fdb processes.
14+
# Kill all running fdb processes from tracked PIDs
1515
for (( i=0; i < "${#FDB_PIDS[@]}"; ++i)); do
16-
kill -9 "${FDB_PIDS[i]}" || true
16+
kill -9 "${FDB_PIDS[i]}" 2>/dev/null || true
1717
done
1818
}
1919

@@ -66,11 +66,25 @@ function start_fdb_cluster {
6666
# Restore exit on error.
6767
set -o errexit # a.k.a. set -e
6868
set -o noclobber
69-
# Set the global FDB_PIDS
70-
FDB_PIDS=($(grep -e "PIDS=" "${output}" | sed -e 's/PIDS=//' | xargs)) || true
69+
# Set the global FDB_PIDS with retry logic for robustness
70+
FDB_PIDS=()
71+
local retries=5
72+
for ((i=0; i<retries; i++)); do
73+
if [[ -f "${output}" ]]; then
74+
FDB_PIDS=($(grep -e "PIDS=" "${output}" | sed -e 's/PIDS=//' | xargs)) || true
75+
if [[ ${#FDB_PIDS[@]} -gt 0 ]]; then
76+
break
77+
fi
78+
fi
79+
echo "Retrying PID extraction (attempt $((i+1))/${retries})..."
80+
sleep 0.5
81+
done
82+
7183
# For debugging... on exit, it can complain: 'line 16: kill: Binary: arguments must be process or job IDs'
7284
if [[ -n "${FDB_PIDS[*]:-}" ]]; then
73-
echo "${FDB_PIDS[*]}"
85+
echo "Tracked FDB PIDs: ${FDB_PIDS[*]}"
86+
else
87+
echo "WARNING: No FDB PIDs found for tracking"
7488
fi
7589
if (( status == 0 )); then
7690
# Give the db a second to come healthy.

0 commit comments

Comments
 (0)