Skip to content

Commit

Permalink
fix: test case error
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshan committed Dec 5, 2021
1 parent 92be032 commit d59f9ea
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 197 deletions.
4 changes: 4 additions & 0 deletions pkg/flow/quota/assist.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type FlowQuotaAssistant struct {
localRules map[model.ServiceKey]model.ServiceRule
}

func (f *FlowQuotaAssistant) AsyncRateLimitConnector() AsyncRateLimitConnector {
return f.asyncRateLimitConnector
}

func (f *FlowQuotaAssistant) Destroy() {
atomic.StoreUint32(&f.destroyed, 1)
f.asyncRateLimitConnector.Destroy()
Expand Down
2 changes: 2 additions & 0 deletions pkg/flow/quota/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type AsyncRateLimitConnector interface {
GetMessageSender(svcKey model.ServiceKey, hashValue uint64) (RateLimitMsgSender, error)
//销毁
Destroy()
//流数量
StreamCount() int
}

//头信息带给server真实的IP地址
Expand Down
30 changes: 2 additions & 28 deletions test/ratelimit/remote_normal_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,6 @@ type IndexResult struct {
code model.QuotaResultCode
}

// 测试不能设置polaris.metric为限流集群
func (rt *RemoteNormalTestingSuite) TestNoSetPolarisMetric(c *check.C) {
log.Printf("Start TestNoSetPolarisMetric")
cfg := api.NewConfiguration()
consumer, err := api.NewProviderAPIByConfig(cfg)
_ = consumer
c.Assert(err, check.IsNil)
consumer.Destroy()

cfg = api.NewConfiguration()
cfg.GetProvider().GetRateLimit().SetRateLimitCluster(config.ServerNamespace, "polaris.metric.test")
consumer, err = api.NewProviderAPIByConfig(cfg)
c.Assert(err, check.IsNil)
consumer.Destroy()

cfg = api.NewConfiguration()
cfg.GetProvider().GetRateLimit().SetRateLimitCluster(config.ServerNamespace, config.ForbidServerMetricService)
consumer, err = api.NewProviderAPIByConfig(cfg)
fmt.Println(err)
c.Assert(err, check.NotNil)
}

//测试远程精准匹配限流
func (rt *RemoteNormalTestingSuite) TestRemoteTwoDuration(c *check.C) {
log.Printf("Start TestRemoteTwoDuration")
Expand Down Expand Up @@ -270,8 +248,6 @@ func (rt *RemoteNormalTestingSuite) TestRemoteRegexCombineV2(c *check.C) {
go func(idx int) {
defer wg.Done()
cfg := config.NewDefaultConfiguration([]string{mockDiscoverAddress})
//测试通过SDK来设置集群名,兼容场景
cfg.GetProvider().GetRateLimit().SetRateLimitCluster(config.ServerNamespace, rateLimitSvcName)
limitAPI, err := api.NewLimitAPIByConfig(cfg)
c.Assert(err, check.IsNil)
defer limitAPI.Destroy()
Expand Down Expand Up @@ -348,8 +324,6 @@ func (rt *RemoteNormalTestingSuite) TestRemoteShareEqually(c *check.C) {
go func(idx int) {
defer wg.Done()
cfg := config.NewDefaultConfiguration([]string{mockDiscoverAddress})
//测试通过SDK来设置集群名,兼容场景
cfg.GetProvider().GetRateLimit().SetRateLimitCluster(config.ServerNamespace, rateLimitSvcName)
limitAPI, err := api.NewLimitAPIByConfig(cfg)
c.Assert(err, check.IsNil)
defer limitAPI.Destroy()
Expand All @@ -362,7 +336,7 @@ func (rt *RemoteNormalTestingSuite) TestRemoteShareEqually(c *check.C) {
map[string]string{"appIdShare": "appShare"})
atomic.AddInt64(&calledCount, 1)
curTime := model.CurrentMillisecond()
if curTime - startTime >= 1000 {
if curTime-startTime >= 1000 {
//前500ms是上下线,不计算
codeChan <- IndexResult{
index: idx,
Expand Down Expand Up @@ -409,4 +383,4 @@ func (rt *RemoteNormalTestingSuite) TestRemoteShareEqually(c *check.C) {
}
c.Assert(allocatedPerSecond >= 170 && allocatedPerSecond <= 260, check.Equals, true)
}
}
}
6 changes: 1 addition & 5 deletions test/ratelimit/window_expire_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/config"
"github.com/polarismesh/polaris-go/pkg/flow"
"github.com/polarismesh/polaris-go/pkg/flow/data"
"github.com/polarismesh/polaris-go/plugin/serverconnector/grpc"
"gopkg.in/check.v1"
"time"
)
Expand Down Expand Up @@ -148,9 +146,7 @@ func (rt *WindowExpireTestingSuite) TestUinExpiredRemote(c *check.C) {
taskValues := engine.FlowQuotaAssistant().TaskValues()
c.Assert(taskValues.Started(), check.Equals, true)

connector, err := data.GetServerConnector(cfg, engine.PluginSupplier())
c.Assert(err, check.IsNil)
asyncRateLimitConnector := connector.GetAsyncRateLimitConnector().(*grpc.AsyncRateLimitConnector)
asyncRateLimitConnector := engine.FlowQuotaAssistant().AsyncRateLimitConnector()
c.Assert(asyncRateLimitConnector.StreamCount(), check.Equals, 1)

//等待淘汰
Expand Down
222 changes: 113 additions & 109 deletions test/testdata/ratelimit_rule_v2/remote_normal.json
Original file line number Diff line number Diff line change
@@ -1,110 +1,114 @@
{
"rules": [
{
"id": "r0001",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"method": {
"type": "EXACT",
"value": "query"
},
"uin": {
"type": "EXACT",
"value": "007"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 200,
"validDuration": "1s"
},
{
"maxAmount": 800,
"validDuration": "10s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
},
{
"id": "r0002",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"appId": {
"type": "REGEX",
"value": ".+"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"regex_combine": false,
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 100,
"validDuration": "1s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
},
{
"id": "r0003",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"test_uin": {
"type": "REGEX",
"value": ".+"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"regex_combine": true,
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 300,
"validDuration": "1s"
}
]
},
{
"id": "r0004",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"appIdShare": {
"type": "EXACT",
"value": "appShare"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"amount_mode": "SHARE_EQUALLY",
"amounts": [
{
"maxAmount": 20,
"validDuration": "1s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
}
]
{
"rules": [
{
"id": "r0001",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"method": {
"type": "EXACT",
"value": "query"
},
"uin": {
"type": "EXACT",
"value": "007"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 200,
"validDuration": "1s"
},
{
"maxAmount": 800,
"validDuration": "10s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
},
{
"id": "r0002",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"appId": {
"type": "REGEX",
"value": ".+"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"regex_combine": false,
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 100,
"validDuration": "1s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
},
{
"id": "r0003",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"test_uin": {
"type": "REGEX",
"value": ".+"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"regex_combine": true,
"amount_mode": "GLOBAL_TOTAL",
"amounts": [
{
"maxAmount": 300,
"validDuration": "1s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
},
{
"id": "r0004",
"service": "RemoteTestSvcV2",
"namespace": "Test",
"labels": {
"appIdShare": {
"type": "EXACT",
"value": "appShare"
}
},
"resource": "QPS",
"type": "GLOBAL",
"action": "reject",
"amount_mode": "SHARE_EQUALLY",
"amounts": [
{
"maxAmount": 20,
"validDuration": "1s"
}
],
"cluster": {
"namespace": "Polaris",
"service": "polaris.metric.test.ide"
}
}
]
}
Loading

0 comments on commit d59f9ea

Please sign in to comment.