Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test Workflow #712

Merged
merged 18 commits into from
Sep 23, 2024
67 changes: 66 additions & 1 deletion .github/workflows/go-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,72 @@ jobs:
cd wasm/cmd && make wasm


# TODO: add coverage test
# TODO: add coverage test
go-test:
name: Benchmark Test with go ${{ matrix.go_version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
env:
SERVER_DIR: open-im-server
CONFIG_PATH: config/notification.yml
# pull-requests: write
strategy:
matrix:
os: [ ubuntu-latest ]
go_version: [ "1.22.x" ]

steps:
- name: Checkout SDK repository
uses: actions/checkout@v4

- name: Checkout Server repository
uses: actions/checkout@v4
with:
repository: 'openimsdk/open-im-server'
path: ${{ env.SERVER_DIR }}

- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}

- name: Get Server dependencies
run: |
cd ${{ env.SERVER_DIR }}
go install github.com/magefile/mage@latest
go mod download

- name: Install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq

- name: Modify Server Configuration
run: |
cd ${{ env.SERVER_DIR }}
yq e '.groupCreated.unreadCount = true' -i ${{ env.CONFIG_PATH }}
yq e '.friendApplicationApproved.unreadCount = true' -i ${{ env.CONFIG_PATH }}

- name: Start Server Services
run: |
cd ${{ env.SERVER_DIR }}
docker compose up -d
mage build
mage start
mage check

- name: Build test SDK core
run: |
go mod tidy
cd integration_test
mkdir data
go run main.go -lgr 0.8 -imf -crg -ckgn -ckcon -sem -ckmsn -u 20 -su 5 -lg 2 -cg 2 -cgm 3 -sm 10 -gm 10 -reg

# - name: Stop Server
# run: |
# cd ${{ github.workspace }}/open-im-server
# mage stop

# dockerfile-test:
# name: Build and Test Dockerfile
Expand Down
24 changes: 8 additions & 16 deletions integration_test/internal/checker/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func (c *CounterChecker[T, K]) LoopCheck(ctx context.Context) error {
gr, cctx = reerrgroup.WithContext(ctx, c.GoroutineLimit)
total int
now int

checkers = make(map[K]*Counter, len(sdk.TestSDKs))
)
total = len(c.LoopSlice)
p := progress.FuncBarPrint(cctx, stringutil.GetFuncName(1), gr, now, total)
Expand Down Expand Up @@ -140,9 +138,13 @@ func (c *CounterChecker[T, K]) LoopCheck(ctx context.Context) error {
if !isEqual {
checkCount++

log.ZWarn(ctx, fmt.Sprintf("check num:%d, %s un correct",
checkCount, stringutil.CamelCaseToSpaceSeparated(c.checkNumName)),
nil, c.CheckerKeyName, key, c.checkNumName, totalNum, "correct num", correctNum)
checkMsg := fmt.Sprintf("check num:%d, %s un correct", checkCount, stringutil.CamelCaseToSpaceSeparated(c.checkNumName))

log.ZWarn(ctx, checkMsg, nil, c.CheckerKeyName, key, c.checkNumName, totalNum, "correct num", correctNum)

if checkCount == config.MaxCheckLoopNum {
return errs.New(checkMsg, c.CheckerKeyName, key, c.checkNumName, totalNum, "correct num", correctNum).Wrap()
}
} else {
log.ZInfo(ctx, fmt.Sprintf("check num:%d, %s correct",
checkCount, stringutil.CamelCaseToSpaceSeparated(c.checkNumName)),
Expand All @@ -156,16 +158,6 @@ func (c *CounterChecker[T, K]) LoopCheck(ctx context.Context) error {
if err := gr.Wait(); err != nil {
return err
}

if len(checkers) != 0 {
err := errs.New(fmt.Sprintf("%s un correct!", stringutil.CamelCaseToSpaceSeparated(c.CheckName))).Wrap()
for k, ck := range checkers {
log.ZWarn(ctx, fmt.Sprintf("%s un correct", stringutil.CamelCaseToSpaceSeparated(c.checkNumName)),
err, c.CheckerKeyName, k, c.checkNumName, ck.TotalCount, "correct num", ck.CorrectCount)
}
InsertToErrChan(ctx, err)
} else {
log.ZInfo(ctx, fmt.Sprintf("%s success", stringutil.CamelCaseToSpaceSeparated(c.CheckName)))
}
log.ZInfo(ctx, fmt.Sprintf("%s success", stringutil.CamelCaseToSpaceSeparated(c.CheckName)))
return nil
}
5 changes: 3 additions & 2 deletions integration_test/internal/config/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const (
)

const (
CheckMsgRate = 1 // Sampling and statistical message ratio. Max check message is MaxCheckMsg
MaxCheckMsg = 1e+8
CheckMsgRate = 1 // Sampling and statistical message ratio. Max check message is MaxCheckMsg
MaxCheckMsg = 1e+8
MaxCheckLoopNum = 40
)

const (
Expand Down
15 changes: 11 additions & 4 deletions integration_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import (
"github.com/openimsdk/openim-sdk-core/v3/integration_test/internal/vars"
"github.com/openimsdk/tools/log"
"github.com/openimsdk/tools/utils/formatutil"
"os"
"runtime/debug"
"time"
)

const runFailed = -1

func Init(ctx context.Context) error {
initialization.InitFlag()
flag.Parse()
Expand Down Expand Up @@ -100,24 +103,28 @@ func DoFlagFunc(ctx context.Context) (err error) {
}

func main() {
var err error
defer func() {
if r := recover(); r != nil {
fmt.Printf("panic: %v\n", r)
fmt.Println("Stack trace:")
fmt.Printf("%s", debug.Stack())
os.Exit(runFailed)
}
if err != nil {
fmt.Println(utils.FormatErrorStack(err))
os.Exit(runFailed)
}
}()
ctx := context.Background()
if err := Init(ctx); err != nil {
if err = Init(ctx); err != nil {
log.ZError(ctx, "init err", err, "stack", utils.FormatErrorStack(err))
fmt.Println("init err")
fmt.Println(utils.FormatErrorStack(err))
return
}
if err := DoFlagFunc(ctx); err != nil {
if err = DoFlagFunc(ctx); err != nil {
log.ZError(ctx, "do flag err", err, "stack", utils.FormatErrorStack(err))
fmt.Println("do flag err")
fmt.Println(utils.FormatErrorStack(err))
return
}

Expand Down