mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 06:07:27 +08:00
fix: Optimization of Rate Limiting Logic for Cluster, AI Token and WASM Plugin (#2997)
This commit is contained in:
@@ -15,10 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cluster-key-rate-limit/config"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"cluster-key-rate-limit/config"
|
||||
|
||||
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
|
||||
"github.com/higress-group/wasm-go/pkg/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -527,9 +528,16 @@ func TestOnHttpRequestHeaders(t *testing.T) {
|
||||
require.Equal(t, types.HeaderStopAllIterationAndWatermark, action)
|
||||
|
||||
// 模拟 Redis 调用响应(触发限流)
|
||||
resp := test.CreateRedisRespArray([]interface{}{1000, -1, 60})
|
||||
// 当前请求数(1001)超过阈值(1000),触发限流
|
||||
resp := test.CreateRedisRespArray([]interface{}{1000, 1001, 60})
|
||||
host.CallOnRedisCall(0, resp)
|
||||
|
||||
// 检查是否发送了限流响应
|
||||
localResponse := host.GetLocalResponse()
|
||||
require.NotNil(t, localResponse)
|
||||
require.Equal(t, uint32(429), localResponse.StatusCode)
|
||||
require.Contains(t, string(localResponse.Data), "Too many requests")
|
||||
|
||||
host.CompleteHttp()
|
||||
})
|
||||
})
|
||||
@@ -641,7 +649,7 @@ func TestCompleteFlow(t *testing.T) {
|
||||
require.Equal(t, types.HeaderStopAllIterationAndWatermark, action)
|
||||
|
||||
// 2. 模拟 Redis 调用响应
|
||||
resp := test.CreateRedisRespArray([]interface{}{1000, 999, 60})
|
||||
resp := test.CreateRedisRespArray([]interface{}{1000, 1, 60})
|
||||
host.CallOnRedisCall(0, resp)
|
||||
|
||||
// 3. 处理响应头
|
||||
|
||||
Reference in New Issue
Block a user