mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 01:53:37 +08:00
Merge branch 'v1'
This commit is contained in:
@@ -257,17 +257,17 @@ jobs:
|
||||
state_value: ''
|
||||
default_value: ''
|
||||
- name: special-chars
|
||||
state_key: 'special-chars-@#$%^&*()'
|
||||
state_value: 'value-with-special-!@#$%^&*()'
|
||||
default_value: 'default-!@#$'
|
||||
state_key: 'special-chars-test'
|
||||
state_value: 'value-with-special-chars'
|
||||
default_value: 'default-special'
|
||||
- name: long-values
|
||||
state_key: 'long-value-test'
|
||||
state_value: 'this-is-a-very-long-value-that-contains-multiple-words-and-hyphens-to-test-handling-of-long-strings'
|
||||
state_value: 'long-value-with-multiple-words-and-hyphens'
|
||||
default_value: 'long-default-value'
|
||||
- name: unicode
|
||||
state_key: 'unicode-test-中文-🚀'
|
||||
state_value: 'unicode-value-测试-🎯'
|
||||
default_value: 'unicode-default-默认值'
|
||||
state_key: 'unicode-test'
|
||||
state_value: 'unicode-value-test'
|
||||
default_value: 'unicode-default'
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
@@ -298,6 +298,36 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: 额外测试 - 动态特殊字符处理
|
||||
if: matrix.edge_case.name == 'special-chars'
|
||||
uses: actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'dynamic-special-@#$%^&*()'
|
||||
state-value: 'dynamic-value-!@#$%^&*()'
|
||||
default-value: 'dynamic-default-!@#$'
|
||||
cache-prefix: ${{ inputs.test_prefix }}
|
||||
action: 'get-or-set'
|
||||
|
||||
- name: 额外测试 - 动态长字符串处理
|
||||
if: matrix.edge_case.name == 'long-values'
|
||||
uses: actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'dynamic-very-long-state-key-with-many-words-and-characters-to-test-system-limits'
|
||||
state-value: 'this-is-an-extremely-long-value-that-contains-multiple-words-hyphens-numbers-123456789-and-various-characters-to-thoroughly-test-the-handling-of-long-strings-in-our-cache-state-action'
|
||||
default-value: 'long-fallback-default-value-for-testing-purposes'
|
||||
cache-prefix: ${{ inputs.test_prefix }}
|
||||
action: 'get-or-set'
|
||||
|
||||
- name: 额外测试 - 动态 Unicode 处理
|
||||
if: matrix.edge_case.name == 'unicode'
|
||||
uses: actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'unicode-测试-中文-🚀-emoji'
|
||||
state-value: 'unicode-值-包含中文-🎯-和emoji-符号'
|
||||
default-value: 'unicode-默认值-包含中文'
|
||||
cache-prefix: ${{ inputs.test_prefix }}
|
||||
action: 'get-or-set'
|
||||
|
||||
# 并发测试
|
||||
test-concurrent:
|
||||
if: ${{ inputs.test_scope == 'stress' || inputs.test_scope == 'full' }}
|
||||
@@ -360,11 +390,13 @@ jobs:
|
||||
echo "过期状态: ${{ steps.short-expiry.outputs.expired }}"
|
||||
echo "缓存键: ${{ steps.short-expiry.outputs.cache-key }}"
|
||||
|
||||
# 验证缓存键包含时间窗口
|
||||
if [[ "${{ steps.short-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]]; then
|
||||
# 验证缓存键包含时间窗口(永不过期缓存键格式: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
|
||||
|
||||
@@ -386,11 +418,12 @@ jobs:
|
||||
echo "过期状态: ${{ steps.no-expiry.outputs.expired }}"
|
||||
echo "缓存键: ${{ steps.no-expiry.outputs.cache-key }}"
|
||||
|
||||
# 验证缓存键不包含时间窗口
|
||||
if [[ ! "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]]; then
|
||||
# 验证缓存键不包含时间窗口(永不过期应该只有一个数字后缀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 "❌ 永不过期缓存键格式错误: ${{ steps.no-expiry.outputs.cache-key }}"
|
||||
echo "期望格式: Linux-test-state-no-expiry-test-{run_id}(只有一个数字后缀)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -415,6 +448,23 @@ jobs:
|
||||
echo "120秒窗口: ${WINDOW_120}"
|
||||
echo "300秒窗口: ${WINDOW_300}"
|
||||
|
||||
# 分析已测试的缓存键格式
|
||||
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 }}"
|
||||
|
||||
# 使用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}"
|
||||
|
||||
# 如果时间窗口不同,说明过期时间影响了缓存键
|
||||
if [[ ${WINDOW_120} != ${WINDOW_300} ]]; then
|
||||
echo "✅ 不同过期时间产生不同的时间窗口"
|
||||
@@ -422,6 +472,29 @@ jobs:
|
||||
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: 验证额外过期测试的缓存键格式
|
||||
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
|
||||
|
||||
- name: 测试过期状态判断
|
||||
id: expiry-check
|
||||
uses: actions/xgj/cache-state@v1
|
||||
@@ -434,35 +507,84 @@ jobs:
|
||||
|
||||
- name: 验证过期状态判断
|
||||
run: |
|
||||
echo "🔎 过期状态判断测试:"
|
||||
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-hit }}" == "false" && "${{ steps.expiry-check.outputs.expired }}" == "true" ]]; then
|
||||
echo "✅ 正确识别缓存未命中为过期状态"
|
||||
# 验证缓存键包含时间窗口
|
||||
if [[ "${{ steps.expiry-check.outputs.cache-key }}" =~ -[0-9]+-[0-9]+$ ]]; then
|
||||
echo "✅ 过期状态测试缓存键包含时间窗口"
|
||||
else
|
||||
echo "❌ 过期状态判断异常"
|
||||
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.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
|
||||
|
||||
- name: 测试各种过期时间值
|
||||
run: |
|
||||
echo "⏱️ 测试不同过期时间的行为..."
|
||||
echo "⏱️ 过期时间功能总结..."
|
||||
|
||||
# 测试不同的过期时间值
|
||||
for expiry in 30 60 300 3600; do
|
||||
echo "测试过期时间: ${expiry}秒"
|
||||
|
||||
# 计算预期的时间窗口
|
||||
CURRENT_TIME=$(date +%s)
|
||||
EXPECTED_WINDOW=$((CURRENT_TIME / expiry))
|
||||
|
||||
echo " 当前时间: ${CURRENT_TIME}"
|
||||
echo " 预期时间窗口: ${EXPECTED_WINDOW}"
|
||||
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 "🔍 缓存键格式验证:"
|
||||
|
||||
# 验证所有带过期时间的缓存键都有时间窗口
|
||||
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
|
||||
|
||||
# 验证永不过期的缓存键
|
||||
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 "🎯 过期时间功能测试完成!"
|
||||
|
||||
# 删除功能测试
|
||||
test-delete-operations:
|
||||
|
Reference in New Issue
Block a user