Serialize rule writes and add tests

This commit is contained in:
2026-04-17 10:21:37 +08:00
parent 66c25b06a7
commit eb8c76492c
7 changed files with 682 additions and 35 deletions

View File

@@ -3,9 +3,31 @@ set -euo pipefail
: "${PERSIST_MOCK_LOG:=/tmp/persist-mock.log}"
: "${PERSIST_MOCK_FAIL:=0}"
: "${PERSIST_MOCK_DELAY_SECS:=0}"
: "${PERSIST_MOCK_ACTIVE_DIR:=}"
: "${PERSIST_MOCK_FAIL_ON_CONCURRENT:=0}"
printf '%s %s\n' "$(basename -- "$0")" "$*" >>"${PERSIST_MOCK_LOG}"
cleanup() {
[[ -n ${PERSIST_MOCK_ACTIVE_DIR} ]] || return 0
rmdir "${PERSIST_MOCK_ACTIVE_DIR}" 2>/dev/null || true
}
if [[ -n ${PERSIST_MOCK_ACTIVE_DIR} ]]; then
if ! mkdir "${PERSIST_MOCK_ACTIVE_DIR}" 2>/dev/null; then
if [[ ${PERSIST_MOCK_FAIL_ON_CONCURRENT} == 1 ]]; then
exit 1
fi
else
trap cleanup EXIT
fi
fi
if [[ ${PERSIST_MOCK_DELAY_SECS} != 0 ]]; then
sleep "${PERSIST_MOCK_DELAY_SECS}"
fi
if [[ ${PERSIST_MOCK_FAIL} == 1 ]]; then
exit 1
fi