Skip to content

Commit 0634a5b

Browse files
committed
chore: 更新ci相关版本,并重构memroy相关测试
Signed-off-by: longyue0521 <[email protected]>
1 parent c49cfb9 commit 0634a5b

22 files changed

+472
-59
lines changed

.github/workflows/go-fmt.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
build:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
- name: Set up Go
29-
uses: actions/setup-go@v3
29+
uses: actions/setup-go@v4
3030
with:
31-
go-version: ">=1.18.0"
31+
go-version: ">=1.21.0"
3232

3333
- name: Install goimports
3434
run: go install golang.org/x/tools/cmd/goimports@latest

.github/workflows/go.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
build:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v4
2828
- name: Set up Go
29-
uses: actions/setup-go@v2
29+
uses: actions/setup-go@v4
3030
with:
31-
go-version: 1.18
31+
go-version: '>=1.21.0'
3232

3333
- name: Build
3434
run: go build -v ./...
@@ -37,4 +37,4 @@ jobs:
3737
run: go test -race -coverprofile=cover.out -v ./...
3838

3939
- name: Post Coverage
40-
uses: codecov/codecov-action@v2
40+
uses: codecov/codecov-action@v3

.github/workflows/golangci-lint.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ jobs:
3131
name: lint
3232
runs-on: ubuntu-latest
3333
steps:
34-
- uses: actions/setup-go@v3
34+
- uses: actions/checkout@v4
35+
- name: Set up Go
36+
uses: actions/setup-go@v4
3537
with:
36-
go-version: '1.20'
37-
- uses: actions/checkout@v3
38+
go-version: '>=1.21.0'
3839
- name: golangci-lint
3940
uses: golangci/golangci-lint-action@v3
4041
with:
4142
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
42-
version: v1.52.2
43+
version: v1.54
4344

4445
# Optional: working directory, useful for monorepos
4546
# working-directory: somedir

.github/workflows/integration_test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
build:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v4
2828
- name: Set up Go
29-
uses: actions/setup-go@v2
29+
uses: actions/setup-go@v4
3030
with:
31-
go-version: 1.18
31+
go-version: '>=1.21.0'
3232

3333
- name: Test
3434
run: sudo sh ./script/integrate_test.sh

.github/workflows/stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/stale@v4
27+
- uses: actions/stale@v8
2828
with:
2929
repo-token: ${{ secrets.GITHUB_TOKEN }}
3030
stale-issue-message: 'This issue is inactive for a long time.'

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
# vendor/
1919

2020
# Go workspace file
21-
go.work
2221
.idea
22+
.vscode/
23+
**/.DS_Store
24+
test.db

Makefile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
APP_PATH:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2+
SCRIPTS_PATH:=$(APP_PATH)/scripts
3+
4+
.PHONY: setup
5+
setup:
6+
@echo "初始化开发环境......"
7+
@find "$(SCRIPTS_PATH)" -type f -name '*.sh' -exec chmod +x {} \;
8+
@bash $(SCRIPTS_PATH)/setup/setup.sh
9+
@$(MAKE) tidy
10+
11+
# 依赖清理
12+
.PHONY: tidy
13+
tidy:
14+
@go mod tidy
15+
16+
# 代码风格
17+
.PHONY: fmt
18+
fmt:
19+
@goimports -l -w $$(find . -type f -name '*.go' -not -path "./.idea/*" -not -path "./cmd/monolithic/ioc/wire_gen.go")
20+
@gofumpt -l -w $$(find . -type f -name '*.go' -not -path "./.idea/*" -not -path "./cmd/monolithic/ioc/wire_gen.go")
21+
22+
# 静态扫描
23+
.PHONY: lint
24+
lint:
25+
@golangci-lint run -c $(SCRIPTS_PATH)/lint/.golangci.yaml ./...
26+
27+
# 单元测试
28+
.PHONY: ut
29+
ut:
30+
@go test -race -cover -coverprofile=unit.out -failfast -shuffle=on ./...
31+
32+
# 集成测试
33+
.PHONY: it
34+
it:
35+
@make dev_3rd_down
36+
@make dev_3rd_up
37+
@go test -tags=integration -race -cover -coverprofile=integration.out -failfast -shuffle=on ./...
38+
@make dev_3rd_down
39+
40+
# 端到端测试
41+
.PHONY: e2e
42+
e2e:
43+
@make dev_3rd_down
44+
@make dev_3rd_up
45+
@go test -tags=e2e -race -cover -coverprofile=e2e.out -failfast -shuffle=on ./...
46+
@make dev_3rd_down
47+
48+
# 启动本地研发 docker 依赖
49+
.PHONY: dev_3rd_up
50+
dev_3rd_up:
51+
@docker compose -f ./scripts/deploy/dev-compose.yaml up -d
52+
53+
.PHONY: dev_3rd_down
54+
dev_3rd_down:
55+
@docker compose -f ./scripts/deploy/dev-compose.yaml down -v
56+
57+
.PHONY: check
58+
check:
59+
@echo "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 检查阶段 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
60+
@echo "整理项目依赖中......"
61+
@$(MAKE) tidy
62+
@echo "代码风格检查中......"
63+
@$(MAKE) fmt
64+
@echo "代码静态扫描中......"
65+
@$(MAKE) lint

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ecodeclub/mq-api
33
go 1.21.0
44

55
require (
6-
github.com/ecodeclub/ekit v0.0.7
6+
github.com/ecodeclub/ekit v0.0.8
77
github.com/stretchr/testify v1.8.4
88
)
99

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/ecodeclub/ekit v0.0.7 h1:6e3p4FQToZPvnsHSKRCTcDo+vYcr8yChV78NeCOcEp0=
4-
github.com/ecodeclub/ekit v0.0.7/go.mod h1:q/cMifDy7CygsCz9NZNgFS6lksEo5tWxsb7RjMoZv00=
3+
github.com/ecodeclub/ekit v0.0.8 h1:861Aot0GvD5ueREEYDVYc1oIhDuFyg6MTxIyiOa4Pvw=
4+
github.com/ecodeclub/ekit v0.0.8/go.mod h1:OqTojKeKFTxeeAAUwNIPKu339SRkX6KAuoK/8A5BCEs=
55
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
66
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
77
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=

memory/mq.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ package memory
1616

1717
import (
1818
"context"
19+
"sync"
20+
1921
"github.com/ecodeclub/ekit/syncx"
2022
"github.com/ecodeclub/mq-api"
21-
"sync"
2223
)
2324

2425
type Topic struct {
@@ -30,12 +31,6 @@ type Topic struct {
3031

3132
type topicOption func(topic *Topic)
3233

33-
func WithProducerChannelSize(size int) topicOption {
34-
return func(topic *Topic) {
35-
topic.produceChan = make(chan *mq.Message, size)
36-
}
37-
}
38-
3934
func (t *Topic) NewConsumer(size int) mq.Consumer {
4035
consumerCh := make(chan *mq.Message, size)
4136
t.lock.Lock()
@@ -100,7 +95,8 @@ func NewMq() mq.MQ {
10095

10196
func (m *Mq) Consumer(topic string) mq.Consumer {
10297
tp, _ := m.topics.LoadOrStore(topic, NewTopic(topic))
103-
return tp.NewConsumer(10)
98+
const size = 10
99+
return tp.NewConsumer(size)
104100
}
105101

106102
func (m *Mq) Producer(topic string) mq.Producer {
@@ -109,9 +105,10 @@ func (m *Mq) Producer(topic string) mq.Producer {
109105
}
110106

111107
func NewTopic(name string, opts ...topicOption) *Topic {
108+
const i = 1000
112109
t := &Topic{
113110
Name: name,
114-
produceChan: make(chan *mq.Message, 1000),
111+
produceChan: make(chan *mq.Message, i),
115112
}
116113
for _, opt := range opts {
117114
opt(t)

memory/mq_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ package memory
1616

1717
import (
1818
"context"
19-
"github.com/ecodeclub/mq-api"
20-
"github.com/stretchr/testify/assert"
21-
"github.com/stretchr/testify/suite"
2219
"sync"
2320
"testing"
2421
"time"
22+
23+
"github.com/ecodeclub/mq-api"
24+
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/suite"
2526
)
2627

2728
type MemoryMqTestSuite struct {
@@ -34,7 +35,7 @@ func (m *MemoryMqTestSuite) SetupSuite() {
3435
}
3536

3637
func (m *MemoryMqTestSuite) TestMq() {
37-
testcases := []struct {
38+
testcases := []*struct {
3839
name string
3940
consumers []mq.Consumer
4041
producers []mq.Producer
@@ -101,11 +102,11 @@ func (m *MemoryMqTestSuite) TestMq() {
101102
for _, a := range ansList {
102103
assert.Equal(t, tc.wantValue, a)
103104
}
104-
105105
})
106106
}
107107
}
108108

109109
func TestMq(t *testing.T) {
110+
t.Parallel()
110111
suite.Run(t, &MemoryMqTestSuite{})
111112
}

scripts/cicd/3rd-dependency-check.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
output=$(make tidy)
4+
if [ -n "$output" ]; then
5+
echo "错误: 请在本地运行'make tidy'命令,确认无误后再提交." >&2
6+
exit 1
7+
fi

scripts/cicd/code-static-check.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
output=$(make lint)
4+
if [ -n "$output" ]; then
5+
echo "错误: 请在本地运行'make lint'命令,确认无误后再提交." >&2
6+
exit 1
7+
fi

scripts/cicd/code-style-check.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
output=$(make fmt)
4+
if [ -n "$output" ]; then
5+
echo >&2 "错误: 请在本地运行'make fmt'命令,确认无误后再提交."
6+
exit 1
7+
fi

scripts/cicd/end-to-end-testing.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "运行端到端测试中......"
4+
make e2e
5+
if [ $? -ne 0 ]; then
6+
echo "错误: 请在本地运行'make e2e'命令,确认测试全部通过后再提交." >&2
7+
exit 1
8+
fi

scripts/cicd/integration-testing.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "运行集成测试中......"
4+
make it
5+
if [ $? -ne 0 ]; then
6+
echo "错误: 请在本地运行'make it'命令,确认测试全部通过后再提交." >&2
7+
exit 1
8+
fi

scripts/cicd/unit-testing.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "运行单元测试中......"
4+
make ut
5+
if [ $? -ne 0 ]; then
6+
echo "错误: 请在本地运行'make ut'命令,确认测试全部通过后再提交." >&2
7+
exit 1
8+
fi

scripts/deploy/dev-compose.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3'
2+
services:
3+
zookeeper:
4+
image: 'bitnami/zookeeper:latest'
5+
ports:
6+
- '2181:2181'
7+
environment:
8+
- ALLOW_ANONYMOUS_LOGIN=yes
9+
kafka:
10+
image: 'bitnami/kafka:3.5.1'
11+
ports:
12+
- '9092:9092'
13+
environment:
14+
- KAFKA_BROKER_ID=1
15+
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
16+
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
17+
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
18+
- ALLOW_PLAINTEXT_LISTENER=yes
19+
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
20+
depends_on:
21+
- zookeeper

0 commit comments

Comments
 (0)