-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for exclusive file lock (#340)
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3' | ||
|
||
services: | ||
backup: | ||
image: offen/docker-volume-backup:${TEST_VERSION:-canary} | ||
restart: always | ||
environment: | ||
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ? | ||
BACKUP_RETENTION_DAYS: '7' | ||
volumes: | ||
- app_data:/backup/app_data:ro | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
- ${LOCAL_DIR:-./local}:/archive | ||
|
||
offen: | ||
image: offen/offen:latest | ||
labels: | ||
- docker-volume-backup.stop-during-backup=true | ||
volumes: | ||
- app_data:/var/opt/offen | ||
|
||
volumes: | ||
app_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")" | ||
. ../util.sh | ||
current_test=$(basename $(pwd)) | ||
|
||
export LOCAL_DIR=$(mktemp -d) | ||
|
||
docker compose up -d --quiet-pull | ||
sleep 5 | ||
|
||
ec=0 | ||
|
||
docker compose exec -e BACKUP_RETENTION_DAYS=7 -e BACKUP_FILENAME=test.tar.gz backup backup & \ | ||
{ set +e; sleep 0.1; docker compose exec -e BACKUP_FILENAME=test2.tar.gz -e LOCK_TIMEOUT=1s backup backup; ec=$?;} | ||
|
||
if [ "$ec" = "0" ]; then | ||
fail "Subsequent invocation exited 0" | ||
fi | ||
pass "Subsequent invocation did not exit 0" | ||
|
||
sleep 5 | ||
|
||
if [ ! -f "${LOCAL_DIR}/test.tar.gz" ]; then | ||
fail "Could not find expected tar file" | ||
fi | ||
pass "Found expected tar file" | ||
|
||
if [ -f "${LOCAL_DIR}/test2.tar.gz" ]; then | ||
fail "Subsequent invocation was expected to fail but created archive" | ||
fi | ||
pass "Subsequent invocation did not create archive" |