Skip to content

Commit 3de2da6

Browse files
authored
chore/remove cutoms limiter (#868)
* chore: using time/rate instead of custom limiter * fix the platform line end related issues * upgrade github.com/linuxsuren/go-service to v0.0.2 * change gh runner from macos-13 to macos-14 * change openjdk:23 to eclipse-temurin:25 * add missing curl command --------- Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 846ee17 commit 3de2da6

File tree

16 files changed

+75
-220
lines changed

16 files changed

+75
-220
lines changed

.claude/settings.local.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(go test:*)",
5+
"Bash(go doc:*)",
6+
"WebSearch",
7+
"Bash(go env:*)",
8+
"Bash(docker pull:*)"
9+
]
10+
}
11+
}

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
BuildDesktop:
130130
strategy:
131131
matrix:
132-
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
132+
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
133133
runs-on: ${{ matrix.os }}
134134
steps:
135135
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
fail-fast: false
134134
matrix:
135135
# see https://github.com/actions/runner-images
136-
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
136+
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
137137
runs-on: ${{ matrix.os }}
138138
steps:
139139
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

cmd/run.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"golang.org/x/time/rate"
2324
"io"
2425
"net/http"
2526
"os"
@@ -32,7 +33,6 @@ import (
3233
"github.com/linuxsuren/api-testing/pkg/util/home"
3334

3435
"github.com/linuxsuren/api-testing/pkg/apispec"
35-
"github.com/linuxsuren/api-testing/pkg/limit"
3636
"github.com/linuxsuren/api-testing/pkg/logging"
3737
"github.com/linuxsuren/api-testing/pkg/runner"
3838
"github.com/linuxsuren/api-testing/pkg/runner/monitor"
@@ -55,8 +55,8 @@ type runOption struct {
5555
thread int64
5656
context context.Context
5757
qps int32
58-
burst int32
59-
limiter limit.RateLimiter
58+
burst int
59+
limiter *rate.Limiter
6060
startTime time.Time
6161
reporter runner.TestReporter
6262
reportFile string
@@ -137,7 +137,7 @@ func (o *runOption) addFlags(flags *pflag.FlagSet) {
137137
flags.StringVarP(&o.swaggerURL, "swagger-url", "", "", "The URL of swagger")
138138
flags.Int64VarP(&o.thread, "thread", "", 1, "Threads of the execution")
139139
flags.Int32VarP(&o.qps, "qps", "", 5, "QPS")
140-
flags.Int32VarP(&o.burst, "burst", "", 5, "burst")
140+
flags.IntVarP(&o.burst, "burst", "", 5, "burst")
141141
flags.StringVarP(&o.monitorDocker, "monitor-docker", "", "", "The docker container name to monitor")
142142
}
143143

@@ -256,10 +256,9 @@ func (o *runOption) startMonitor() (err error) {
256256

257257
func (o *runOption) runE(cmd *cobra.Command, args []string) (err error) {
258258
o.startTime = time.Now()
259-
o.limiter = limit.NewDefaultRateLimiter(o.qps, o.burst)
259+
o.limiter = rate.NewLimiter(rate.Limit(o.qps), o.burst)
260260
defer func() {
261261
cmd.Printf("Consumed: %s\n", time.Since(o.startTime).String())
262-
o.limiter.Stop()
263262
}()
264263

265264
if err = o.loader.Put(o.pattern); err != nil {
@@ -400,7 +399,7 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter
400399
case <-stopSingal:
401400
return
402401
default:
403-
o.limiter.Accept()
402+
o.limiter.Allow()
404403

405404
ctxWithTimeout, cancel := context.WithTimeout(ctx, o.requestTimeout)
406405
defer cancel() // Ensure context is always cancelled when leaving this scope

cmd/run_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727
"time"
2828

2929
"github.com/h2non/gock"
30-
"github.com/linuxsuren/api-testing/pkg/limit"
3130
atest "github.com/linuxsuren/api-testing/pkg/testing"
3231
"github.com/linuxsuren/api-testing/pkg/util"
3332
"github.com/spf13/cobra"
3433
"github.com/stretchr/testify/assert"
34+
"golang.org/x/time/rate"
3535
)
3636

3737
func TestRunSuite(t *testing.T) {
@@ -71,7 +71,7 @@ func TestRunSuite(t *testing.T) {
7171
ctx := getDefaultContext()
7272
opt := newDiscardRunOption()
7373
opt.requestTimeout = 30 * time.Second
74-
opt.limiter = limit.NewDefaultRateLimiter(0, 0)
74+
opt.limiter = rate.NewLimiter(rate.Limit(0), 0)
7575
stopSingal := make(chan struct{}, 1)
7676

7777
loader := atest.NewFileLoader()

e2e/code-generator/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG LAN_ENV=docker.io/library/golang:1.21
22

33
FROM ghcr.io/linuxsuren/api-testing:master AS atest
4-
FROM ghcr.io/linuxsuren/hd:v0.0.42 as downloader
4+
FROM ghcr.io/linuxsuren/hd:v0.0.42 AS downloader
55
RUN hd install jq
66
FROM $LAN_ENV
77

e2e/code-generator/compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
context: .
1414
dockerfile: Dockerfile
1515
args:
16-
- LAN_ENV=docker.io/library/openjdk:23
16+
- LAN_ENV=docker.io/library/openjdk:26-rc-jdk
1717
command:
1818
- /workspace/entrypoint.sh
1919
- java
@@ -49,7 +49,7 @@ services:
4949
context: .
5050
dockerfile: Dockerfile
5151
args:
52-
- LAN_ENV=docker.io/library/openjdk:23
52+
- LAN_ENV=docker.io/library/openjdk:26-rc-jdk
5353
command:
5454
- /workspace/entrypoint.sh
5555
- curl

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/invopop/jsonschema v0.7.0
2323
github.com/jhump/protoreflect v1.15.3
2424
github.com/linuxsuren/go-fake-runtime v0.0.5
25-
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9
25+
github.com/linuxsuren/go-service v0.0.2
2626
github.com/linuxsuren/unstructured v0.0.1
2727
github.com/prometheus/client_golang v1.22.0
2828
github.com/prometheus/common v0.67.2
@@ -48,6 +48,7 @@ require (
4848
github.com/gorilla/websocket v1.5.3
4949
github.com/linuxsuren/http-downloader v0.0.99
5050
golang.org/x/mod v0.28.0
51+
golang.org/x/time v0.14.0
5152
)
5253

5354
require (

go.sum

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
131131
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
132132
github.com/linuxsuren/go-fake-runtime v0.0.5 h1:x1qvuGMfly3L4BTwx6Hq5oUcuf/1u0kSVPzQylHHpwI=
133133
github.com/linuxsuren/go-fake-runtime v0.0.5/go.mod h1:hlE6bZp76N3YPDsKi5YKOf1XmcJy4rvf8EtkTLYRYLw=
134-
github.com/linuxsuren/go-service v0.0.1 h1:GoeK2HLDlRh+QQvFlxOferGtDUwzO3YduumMJ0XYPJ8=
135-
github.com/linuxsuren/go-service v0.0.1/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
136-
github.com/linuxsuren/go-service v0.0.2-0.20251117075600-96234f59e3f2 h1:vy8Y8NA7vjZmHE+28v2Un4mtc4DG1XtXo66hbeQ4pXE=
137-
github.com/linuxsuren/go-service v0.0.2-0.20251117075600-96234f59e3f2/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
138-
github.com/linuxsuren/go-service v0.0.2-0.20251117081324-130f4c6054f7 h1:/xN+kJ5Vo+FCCjasmapVw5lRMwb6sgdJZqTu02kfNag=
139-
github.com/linuxsuren/go-service v0.0.2-0.20251117081324-130f4c6054f7/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
140-
github.com/linuxsuren/go-service v0.0.2-0.20251117081529-39b6694d1e30 h1:C9aOFP9tVFcDKlQAd3X4rU43s+VmS/R/BNzHKWD6uhU=
141-
github.com/linuxsuren/go-service v0.0.2-0.20251117081529-39b6694d1e30/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
142-
github.com/linuxsuren/go-service v0.0.2-0.20251117082747-764ea1ba3825 h1:6CwFWPq2DjFrW1gbH2FtKPlNPCm1j0vgYBl5/LWeT6Y=
143-
github.com/linuxsuren/go-service v0.0.2-0.20251117082747-764ea1ba3825/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
144-
github.com/linuxsuren/go-service v0.0.2-0.20251117083110-fbec39b2f85d h1:+kMcMI8rB9VbpcfWH8h3lOH7sYjT0+uq0EWsDf1byf4=
145-
github.com/linuxsuren/go-service v0.0.2-0.20251117083110-fbec39b2f85d/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
146-
github.com/linuxsuren/go-service v0.0.2-0.20251117083330-afb28a74b935 h1:bAFGUhlWuRla9Di1Fq7alY9Q9lXeLDgHMQdyLPVbVOg=
147-
github.com/linuxsuren/go-service v0.0.2-0.20251117083330-afb28a74b935/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
148-
github.com/linuxsuren/go-service v0.0.2-0.20251117083554-81682ffea100 h1:7uMuI3tJB53C4+dlBrfF4FaQ9YxY3KvatUSZL9Kgo8A=
149-
github.com/linuxsuren/go-service v0.0.2-0.20251117083554-81682ffea100/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
150-
github.com/linuxsuren/go-service v0.0.2-0.20251117084203-71bf4d3ebe0f h1:XYw35A2a2XafK57MSSoyDICrTw+TOcUWWT0cqHE/Khw=
151-
github.com/linuxsuren/go-service v0.0.2-0.20251117084203-71bf4d3ebe0f/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
152-
github.com/linuxsuren/go-service v0.0.2-0.20251117091757-3ae9fc74c5b9 h1:5jCZ8Xh4Bxpq9pwrs+T4CBVCfG4gVTpx45t3s/0gnxI=
153-
github.com/linuxsuren/go-service v0.0.2-0.20251117091757-3ae9fc74c5b9/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
154134
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9 h1:w5prP6ROOxInPV38KL+0laf7ZDIHlidBerhrphHqWHU=
155135
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
136+
github.com/linuxsuren/go-service v0.0.2 h1:4pq+LEXs1/V6qBCVW749PZbaXSQb3dyz/VR+xsdf95o=
137+
github.com/linuxsuren/go-service v0.0.2/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
156138
github.com/linuxsuren/http-downloader v0.0.99 h1:fEu+HkHdYeLM932c7IfmuaDJqWxVU5sIEnS/Aln8h9o=
157139
github.com/linuxsuren/http-downloader v0.0.99/go.mod h1:OngIAkbOJTMbd+IMRbt3TiWSizVJZvPfjdbTpl6uHLo=
158140
github.com/linuxsuren/oauth-hub v0.0.1 h1:5LAdX9ZlWhaM7P10rdxiXPk26eceYHRyfkFXsym6AxY=
@@ -334,6 +316,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
334316
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
335317
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
336318
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
319+
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
320+
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
337321
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
338322
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
339323
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

pkg/limit/limiter.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)