Skip to content

Commit

Permalink
test(app): speed up client & server tests (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost authored Oct 24, 2024
1 parent 3477b03 commit 3697f89
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 323 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,41 @@ jobs:
cache: false # don't use cache for self-hosted runners

- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)
run: go test -race ./...

ut-windows:
strategy:
matrix:
version: ["1.20", "1.21", "1.22", "1.23"]
runs-on: windows-latest
env: # Fixes https://github.com/actions/setup-go/issues/240
GOMODCACHE: 'D:\go\pkg\mod'
GOCACHE: 'D:\go\go-build'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.version }}

- name: Unit Test
run: go test -race ./...

code-cov:
runs-on: [self-hosted, X64]
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
cache: false # don't use cache for self-hosted runners

- name: Unit Test
run: go test -race -covermode=atomic ./...
run: go test -covermode=atomic -coverprofile=coverage.txt ./...

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)

hz-test-unix:
runs-on: [ self-hosted, X64 ]
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
pkg/app/fs.go.hertz.gz
coverage.txt
coverage.out

# test benchmark tmp output
cpu.out
mem.out
*.test
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/bytedance/gopkg v0.1.0
github.com/bytedance/mockey v1.2.12
github.com/bytedance/sonic v1.12.0
github.com/cloudwego/netpoll v0.6.2
github.com/cloudwego/netpoll v0.6.4
github.com/fsnotify/fsnotify v1.5.4
github.com/tidwall/gjson v1.14.4
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/cloudwego/netpoll v0.6.2 h1:+KdILv5ATJU+222wNNXpHapYaBeRvvL8qhJyhcxRxrQ=
github.com/cloudwego/netpoll v0.6.2/go.mod h1:kaqvfZ70qd4T2WtIIpCOi5Cxyob8viEpzLhCrTrz3HM=
github.com/cloudwego/netpoll v0.6.4 h1:z/dA4sOTUQof6zZIO4QNnLBXsDFFFEos9OOGloR6kno=
github.com/cloudwego/netpoll v0.6.4/go.mod h1:BtM+GjKTdwKoC8IOzD08/+8eEn2gYoiNLipFca6BVXQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
38 changes: 17 additions & 21 deletions pkg/app/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,33 +551,29 @@ func (c *Client) CloseIdleConnections() {
}

func (c *Client) mCleaner() {
mustStop := false

for {
time.Sleep(10 * time.Second)
c.mLock.Lock()
for k, v := range c.m {
shouldRemove := v.ShouldRemove()

if shouldRemove {
delete(c.m, k)
if f, ok := v.(io.Closer); ok {
err := f.Close()
if err != nil {
hlog.Warnf("clean hostclient error, addr: %s, err: %s", k, err.Error())
}
}
}
}
if len(c.m) == 0 {
mustStop = true
if c.mClean() {
break
}
c.mLock.Unlock()
}
}

if mustStop {
break
func (c *Client) mClean() bool {
c.mLock.Lock()
defer c.mLock.Unlock()
for k, v := range c.m {
if v.ShouldRemove() {
delete(c.m, k)
if f, ok := v.(io.Closer); ok {
err := f.Close()
if err != nil {
hlog.Warnf("clean hostclient error, addr: %s, err: %s", k, err.Error())
}
}
}
}
return len(c.m) == 0
}

func (c *Client) SetClientFactory(cf suite.ClientFactory) {
Expand Down
Loading

0 comments on commit 3697f89

Please sign in to comment.