feat: 注释掉 test-cache-state.yml 中的过期测试部分,以便于后续功能调整和优化,保持代码整洁性。

This commit is contained in:
Lyda
2025-08-21 13:36:42 +08:00
parent 210d257b44
commit 1299feac14

View File

@@ -365,226 +365,226 @@ jobs:
fi fi
# 过期时间测试 # 过期时间测试
test-expiry: # test-expiry:
if: ${{ inputs.test_scope == 'expiry' || inputs.test_scope == 'full' }} # if: ${{ inputs.test_scope == 'expiry' || inputs.test_scope == 'full' }}
runs-on: ubuntu-node-20 # runs-on: ubuntu-node-20
steps: # steps:
- name: 检出代码 # - name: 检出代码
uses: actions/checkout@v4 # uses: actions/checkout@v4
- name: 测试基础过期功能 - 短期缓存 # - name: 测试基础过期功能 - 短期缓存
id: short-expiry # id: short-expiry
uses: actions/xgj/cache-state@v1 # uses: actions/xgj/cache-state@v1
with: # with:
state-key: 'short-expiry-test-${{ github.run_id }}' # state-key: 'short-expiry-test-${{ github.run_id }}'
state-value: 'short-value' # state-value: 'short-value'
default-value: 'default-short' # default-value: 'default-short'
expiry-seconds: '120' # 2分钟 # expiry-seconds: '120' # 2分钟
cache-prefix: ${{ inputs.test_prefix }} # cache-prefix: ${{ inputs.test_prefix }}
- name: 验证短期缓存设置 # - name: 验证短期缓存设置
run: | # run: |
echo "🕐 短期缓存测试结果:" # echo "🕐 短期缓存测试结果:"
echo "状态值: ${{ steps.short-expiry.outputs.state-value }}" # echo "状态值: ${{ steps.short-expiry.outputs.state-value }}"
echo "缓存命中: ${{ steps.short-expiry.outputs.cache-hit }}" # echo "缓存命中: ${{ steps.short-expiry.outputs.cache-hit }}"
echo "过期状态: ${{ steps.short-expiry.outputs.expired }}" # echo "过期状态: ${{ steps.short-expiry.outputs.expired }}"
echo "缓存键: ${{ steps.short-expiry.outputs.cache-key }}" # echo "缓存键: ${{ steps.short-expiry.outputs.cache-key }}"
# 验证缓存键包含时间窗口永不过期缓存键格式Linux-test-state-short-expiry-test-1038有过期时间格式Linux-test-state-short-expiry-test-1038-12345 # # 验证缓存键包含时间窗口永不过期缓存键格式Linux-test-state-short-expiry-test-1038有过期时间格式Linux-test-state-short-expiry-test-1038-12345
# 检查是否有额外的时间窗口后缀在run_id之后 # # 检查是否有额外的时间窗口后缀在run_id之后
if [[ "${{ steps.short-expiry.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "${{ steps.short-expiry.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ 缓存键包含时间窗口标识" # echo "✅ 缓存键包含时间窗口标识"
else # else
echo "❌ 缓存键缺少时间窗口标识: ${{ steps.short-expiry.outputs.cache-key }}" # echo "❌ 缓存键缺少时间窗口标识: ${{ steps.short-expiry.outputs.cache-key }}"
echo "期望格式: Linux-test-state-short-expiry-test-{run_id}-{time_window}" # echo "期望格式: Linux-test-state-short-expiry-test-{run_id}-{time_window}"
exit 1 # exit 1
fi # fi
- name: 测试永不过期缓存 # - name: 测试永不过期缓存
id: no-expiry # id: no-expiry
uses: actions/xgj/cache-state@v1 # uses: actions/xgj/cache-state@v1
with: # with:
state-key: 'no-expiry-test-${{ github.run_id }}' # state-key: 'no-expiry-test-${{ github.run_id }}'
state-value: 'permanent-value' # state-value: 'permanent-value'
default-value: 'default-permanent' # default-value: 'default-permanent'
expiry-seconds: '0' # 永不过期 # expiry-seconds: '0' # 永不过期
cache-prefix: ${{ inputs.test_prefix }} # cache-prefix: ${{ inputs.test_prefix }}
- name: 验证永不过期缓存 # - name: 验证永不过期缓存
run: | # run: |
echo "♾️ 永不过期缓存测试结果:" # echo "♾️ 永不过期缓存测试结果:"
echo "状态值: ${{ steps.no-expiry.outputs.state-value }}" # echo "状态值: ${{ steps.no-expiry.outputs.state-value }}"
echo "缓存命中: ${{ steps.no-expiry.outputs.cache-hit }}" # echo "缓存命中: ${{ steps.no-expiry.outputs.cache-hit }}"
echo "过期状态: ${{ steps.no-expiry.outputs.expired }}" # echo "过期状态: ${{ steps.no-expiry.outputs.expired }}"
echo "缓存键: ${{ steps.no-expiry.outputs.cache-key }}" # echo "缓存键: ${{ steps.no-expiry.outputs.cache-key }}"
# 验证缓存键不包含时间窗口永不过期应该只有一个数字后缀run_id而不是两个数字后缀 # # 验证缓存键不包含时间窗口永不过期应该只有一个数字后缀run_id而不是两个数字后缀
if [[ "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]] && [[ ! "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]] && [[ ! "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ 永不过期缓存键格式正确" # echo "✅ 永不过期缓存键格式正确"
else # else
echo "❌ 永不过期缓存键格式错误: ${{ steps.no-expiry.outputs.cache-key }}" # echo "❌ 永不过期缓存键格式错误: ${{ steps.no-expiry.outputs.cache-key }}"
echo "期望格式: Linux-test-state-no-expiry-test-{run_id}(只有一个数字后缀)" # echo "期望格式: Linux-test-state-no-expiry-test-{run_id}(只有一个数字后缀)"
exit 1 # exit 1
fi # fi
# 验证过期状态 # # 验证过期状态
if [[ "${{ steps.no-expiry.outputs.expired }}" == "false" ]]; then # if [[ "${{ steps.no-expiry.outputs.expired }}" == "false" ]]; then
echo "✅ 永不过期缓存过期状态正确" # echo "✅ 永不过期缓存过期状态正确"
else # else
echo "❌ 永不过期缓存不应显示为过期" # echo "❌ 永不过期缓存不应显示为过期"
exit 1 # exit 1
fi # fi
- name: 测试不同过期时间的缓存键差异 # - name: 测试不同过期时间的缓存键差异
run: | # run: |
echo "🔍 测试不同过期时间的缓存键生成..." # echo "🔍 测试不同过期时间的缓存键生成..."
# 记录当前时间窗口 # # 记录当前时间窗口
CURRENT_TIME=$(date +%s) # CURRENT_TIME=$(date +%s)
WINDOW_120=$((CURRENT_TIME / 120)) # WINDOW_120=$((CURRENT_TIME / 120))
WINDOW_300=$((CURRENT_TIME / 300)) # WINDOW_300=$((CURRENT_TIME / 300))
echo "当前时间: ${CURRENT_TIME}" # echo "当前时间: ${CURRENT_TIME}"
echo "120秒窗口: ${WINDOW_120}" # echo "120秒窗口: ${WINDOW_120}"
echo "300秒窗口: ${WINDOW_300}" # echo "300秒窗口: ${WINDOW_300}"
# 分析已测试的缓存键格式 # # 分析已测试的缓存键格式
echo "" # echo ""
echo "📋 已测试的缓存键格式分析:" # echo "📋 已测试的缓存键格式分析:"
echo "短期缓存键: ${{ steps.short-expiry.outputs.cache-key }}" # echo "短期缓存键: ${{ steps.short-expiry.outputs.cache-key }}"
echo "永不过期键: ${{ steps.no-expiry.outputs.cache-key }}" # echo "永不过期键: ${{ steps.no-expiry.outputs.cache-key }}"
# 提取缓存键的最后两个数字段 # # 提取缓存键的最后两个数字段
SHORT_KEY="${{ steps.short-expiry.outputs.cache-key }}" # SHORT_KEY="${{ steps.short-expiry.outputs.cache-key }}"
NO_EXPIRY_KEY="${{ steps.no-expiry.outputs.cache-key }}" # NO_EXPIRY_KEY="${{ steps.no-expiry.outputs.cache-key }}"
# 使用sed提取最后的数字段 # # 使用sed提取最后的数字段
SHORT_LAST_NUM=$(echo "${SHORT_KEY}" | sed 's/.*-\([0-9]*\)$/\1/') # SHORT_LAST_NUM=$(echo "${SHORT_KEY}" | sed 's/.*-\([0-9]*\)$/\1/')
NO_EXPIRY_LAST_NUM=$(echo "${NO_EXPIRY_KEY}" | sed 's/.*-\([0-9]*\)$/\1/') # NO_EXPIRY_LAST_NUM=$(echo "${NO_EXPIRY_KEY}" | sed 's/.*-\([0-9]*\)$/\1/')
echo "短期缓存最后数字: ${SHORT_LAST_NUM}" # echo "短期缓存最后数字: ${SHORT_LAST_NUM}"
echo "永不过期最后数字: ${NO_EXPIRY_LAST_NUM}" # echo "永不过期最后数字: ${NO_EXPIRY_LAST_NUM}"
# 如果时间窗口不同,说明过期时间影响了缓存键 # # 如果时间窗口不同,说明过期时间影响了缓存键
if [[ ${WINDOW_120} != ${WINDOW_300} ]]; then # if [[ ${WINDOW_120} != ${WINDOW_300} ]]; then
echo "✅ 不同过期时间产生不同的时间窗口" # echo "✅ 不同过期时间产生不同的时间窗口"
else # else
echo " 当前时间点两个时间窗口相同(正常情况)" # echo " 当前时间点两个时间窗口相同(正常情况)"
fi # fi
- name: 测试额外的过期时间缓存键 # - name: 测试额外的过期时间缓存键
id: extra-expiry-test # id: extra-expiry-test
uses: actions/xgj/cache-state@v1 # uses: actions/xgj/cache-state@v1
with: # with:
state-key: 'extra-expiry-validation' # state-key: 'extra-expiry-validation'
state-value: 'extra-value' # state-value: 'extra-value'
default-value: 'extra-default' # default-value: 'extra-default'
expiry-seconds: '300' # expiry-seconds: '300'
action: 'set' # action: 'set'
cache-prefix: ${{ inputs.test_prefix }} # cache-prefix: ${{ inputs.test_prefix }}
- name: 验证额外过期测试的缓存键格式 # - name: 验证额外过期测试的缓存键格式
run: | # run: |
echo "🔍 验证额外过期测试缓存键:" # echo "🔍 验证额外过期测试缓存键:"
echo "额外过期测试键: ${{ steps.extra-expiry-test.outputs.cache-key }}" # echo "额外过期测试键: ${{ steps.extra-expiry-test.outputs.cache-key }}"
# 验证这个缓存键是否有时间窗口 # # 验证这个缓存键是否有时间窗口
if [[ "${{ steps.extra-expiry-test.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "${{ steps.extra-expiry-test.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ 额外过期测试缓存键包含时间窗口" # echo "✅ 额外过期测试缓存键包含时间窗口"
else # else
echo "❌ 额外过期测试缓存键缺少时间窗口: ${{ steps.extra-expiry-test.outputs.cache-key }}" # echo "❌ 额外过期测试缓存键缺少时间窗口: ${{ steps.extra-expiry-test.outputs.cache-key }}"
fi # fi
- name: 测试过期状态判断 # - name: 测试过期状态判断
id: expiry-check # id: expiry-check
uses: actions/xgj/cache-state@v1 # uses: actions/xgj/cache-state@v1
with: # with:
state-key: 'non-existent-expiry-test' # state-key: 'non-existent-expiry-test'
default-value: 'fallback-value' # default-value: 'fallback-value'
expiry-seconds: '60' # expiry-seconds: '60'
action: 'get' # action: 'get'
cache-prefix: ${{ inputs.test_prefix }} # cache-prefix: ${{ inputs.test_prefix }}
- name: 验证过期状态判断 # - name: 验证过期状态判断
run: | # run: |
echo "🔎 过期状态判断测试结果:" # echo "🔎 过期状态判断测试结果:"
echo "状态值: ${{ steps.expiry-check.outputs.state-value }}" # echo "状态值: ${{ steps.expiry-check.outputs.state-value }}"
echo "缓存命中: ${{ steps.expiry-check.outputs.cache-hit }}" # echo "缓存命中: ${{ steps.expiry-check.outputs.cache-hit }}"
echo "过期状态: ${{ steps.expiry-check.outputs.expired }}" # echo "过期状态: ${{ steps.expiry-check.outputs.expired }}"
echo "使用默认值: ${{ steps.expiry-check.outputs.used-default }}" # echo "使用默认值: ${{ steps.expiry-check.outputs.used-default }}"
echo "缓存键: ${{ steps.expiry-check.outputs.cache-key }}" # echo "缓存键: ${{ steps.expiry-check.outputs.cache-key }}"
# 验证缓存键包含时间窗口 # # 验证缓存键包含时间窗口
if [[ "${{ steps.expiry-check.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "${{ steps.expiry-check.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ 过期状态测试缓存键包含时间窗口" # echo "✅ 过期状态测试缓存键包含时间窗口"
else # else
echo "❌ 过期状态测试缓存键缺少时间窗口: ${{ steps.expiry-check.outputs.cache-key }}" # echo "❌ 过期状态测试缓存键缺少时间窗口: ${{ steps.expiry-check.outputs.cache-key }}"
exit 1 # exit 1
fi # fi
# 因为是新的状态键,应该返回默认值 # # 因为是新的状态键,应该返回默认值
if [[ "${{ steps.expiry-check.outputs.state-value }}" == "fallback-value" ]]; then # if [[ "${{ steps.expiry-check.outputs.state-value }}" == "fallback-value" ]]; then
echo "✅ 过期测试返回了正确的默认值" # echo "✅ 过期测试返回了正确的默认值"
else # else
echo "❌ 过期测试没有返回默认值,实际值: ${{ steps.expiry-check.outputs.state-value }}" # echo "❌ 过期测试没有返回默认值,实际值: ${{ steps.expiry-check.outputs.state-value }}"
exit 1 # exit 1
fi # fi
# 检查是否正确标记为使用默认值 # # 检查是否正确标记为使用默认值
if [[ "${{ steps.expiry-check.outputs.used-default }}" == "true" ]]; then # if [[ "${{ steps.expiry-check.outputs.used-default }}" == "true" ]]; then
echo "✅ 正确标记使用了默认值" # echo "✅ 正确标记使用了默认值"
else # else
echo "❌ 没有正确标记使用默认值: ${{ steps.expiry-check.outputs.used-default }}" # echo "❌ 没有正确标记使用默认值: ${{ steps.expiry-check.outputs.used-default }}"
exit 1 # exit 1
fi # fi
# 对于不存在的缓存且设置了过期时间过期状态应该是false因为缓存本身就不存在 # # 对于不存在的缓存且设置了过期时间过期状态应该是false因为缓存本身就不存在
if [[ "${{ steps.expiry-check.outputs.cache-hit }}" == "false" && "${{ steps.expiry-check.outputs.expired }}" == "false" ]]; then # if [[ "${{ steps.expiry-check.outputs.cache-hit }}" == "false" && "${{ steps.expiry-check.outputs.expired }}" == "false" ]]; then
echo "✅ 正确处理不存在的缓存过期状态" # echo "✅ 正确处理不存在的缓存过期状态"
else # else
echo " 过期状态: ${{ steps.expiry-check.outputs.expired }},缓存命中: ${{ steps.expiry-check.outputs.cache-hit }}" # echo " 过期状态: ${{ steps.expiry-check.outputs.expired }},缓存命中: ${{ steps.expiry-check.outputs.cache-hit }}"
echo " 不存在的缓存不应标记为过期,而是未命中" # echo " 不存在的缓存不应标记为过期,而是未命中"
fi # fi
- name: 测试各种过期时间值 # - name: 测试各种过期时间值
run: | # run: |
echo "⏱️ 过期时间功能总结..." # echo "⏱️ 过期时间功能总结..."
echo "" # echo ""
echo "📋 已完成的过期时间测试:" # echo "📋 已完成的过期时间测试:"
echo "✅ 短期缓存 (120秒): ${{ steps.short-expiry.outputs.cache-key }}" # echo "✅ 短期缓存 (120秒): ${{ steps.short-expiry.outputs.cache-key }}"
echo "✅ 永不过期 (0秒): ${{ steps.no-expiry.outputs.cache-key }}" # echo "✅ 永不过期 (0秒): ${{ steps.no-expiry.outputs.cache-key }}"
echo "✅ 额外测试 (300秒): ${{ steps.extra-expiry-test.outputs.cache-key }}" # echo "✅ 额外测试 (300秒): ${{ steps.extra-expiry-test.outputs.cache-key }}"
echo "✅ 过期状态判断 (60秒): ${{ steps.expiry-check.outputs.cache-key }}" # echo "✅ 过期状态判断 (60秒): ${{ steps.expiry-check.outputs.cache-key }}"
echo "" # echo ""
echo "🔍 缓存键格式验证:" # echo "🔍 缓存键格式验证:"
# 验证所有带过期时间的缓存键都有时间窗口 # # 验证所有带过期时间的缓存键都有时间窗口
KEYS_WITH_EXPIRY=( # KEYS_WITH_EXPIRY=(
"${{ steps.short-expiry.outputs.cache-key }}" # "${{ steps.short-expiry.outputs.cache-key }}"
"${{ steps.extra-expiry-test.outputs.cache-key }}" # "${{ steps.extra-expiry-test.outputs.cache-key }}"
"${{ steps.expiry-check.outputs.cache-key }}" # "${{ steps.expiry-check.outputs.cache-key }}"
) # )
for key in "${KEYS_WITH_EXPIRY[@]}"; do # for key in "${KEYS_WITH_EXPIRY[@]}"; do
if [[ "$key" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "$key" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ $key (包含时间窗口)" # echo "✅ $key (包含时间窗口)"
else # else
echo "❌ $key (缺少时间窗口)" # echo "❌ $key (缺少时间窗口)"
fi # fi
done # done
# 验证永不过期的缓存键 # # 验证永不过期的缓存键
NO_EXPIRY_KEY="${{ steps.no-expiry.outputs.cache-key }}" # NO_EXPIRY_KEY="${{ steps.no-expiry.outputs.cache-key }}"
if [[ "$NO_EXPIRY_KEY" =~ -[0-9]+$ ]] && [[ ! "$NO_EXPIRY_KEY" =~ -[0-9]+-[0-9]+$ ]]; then # if [[ "$NO_EXPIRY_KEY" =~ -[0-9]+$ ]] && [[ ! "$NO_EXPIRY_KEY" =~ -[0-9]+-[0-9]+$ ]]; then
echo "✅ $NO_EXPIRY_KEY (永不过期只有run_id)" # echo "✅ $NO_EXPIRY_KEY (永不过期只有run_id)"
else # else
echo "❌ $NO_EXPIRY_KEY (永不过期格式错误)" # echo "❌ $NO_EXPIRY_KEY (永不过期格式错误)"
fi # fi
echo "" # echo ""
echo "🎯 过期时间功能测试完成!" # echo "🎯 过期时间功能测试完成!"
# 删除功能测试 # 删除功能测试
test-delete-operations: test-delete-operations: