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