Skip to content

Commit

Permalink
add unit test and remove unused code (#509)
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuanhhy <[email protected]>
  • Loading branch information
huanghaoyuanhhy authored Jan 21, 2025
1 parent 50f445f commit dd5511c
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 1,197 deletions.
18 changes: 17 additions & 1 deletion .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pull_request_rules:

- name: Test passed for code changed-main
conditions:
- check-success=Unit test go
- check-success=Backup and restore cross version (docker-compose, standalone, standalone, 2.3-latest, master-latest)
- check-success=Backup and restore cross version (docker-compose, standalone, standalone, 2.3-latest, 2.4-latest)
- check-success=Backup and restore cross version (docker-compose, standalone, standalone, 2.4-latest, master-latest)
Expand Down Expand Up @@ -113,7 +114,22 @@ pull_request_rules:
- base=main
- files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
- or:
- check-failure=CI
- check-success!=Unit test go
- check-success!=Backup and restore cross version (docker-compose, standalone, standalone, 2.3-latest, master-latest)
- check-success!=Backup and restore cross version (docker-compose, standalone, standalone, 2.3-latest, 2.4-latest)
- check-success!=Backup and restore cross version (docker-compose, standalone, standalone, 2.4-latest, master-latest)
- check-success!=Backup and restore after upgrade (docker-compose, standalone, standalone, v2.4.17, master-latest)
- check-success!=Backup and restore after upgrade (docker-compose, standalone, standalone, v2.4.17, 2.4-latest)
- check-success!=Backup and restore after upgrade (docker-compose, standalone, standalone, 2.4-latest, master-latest)
- check-success!=Backup and restore cli (docker-compose, standalone, standalone, master-latest)
- check-success!=Backup and restore with rbac config (helm, standalone, master-latest)
- check-success!=Backup and restore api (docker-compose, standalone, master-latest, L0)
- check-success!=Backup and restore api (docker-compose, standalone, master-latest, L1)
- check-success!=Backup and restore api (docker-compose, standalone, master-latest, L2)
- check-success!=Backup and restore api (docker-compose, standalone, master-latest, MASTER)
- check-success!=Backup and restore api (docker-compose, standalone, 2.4-latest, L0)
- check-success!=Backup and restore api (docker-compose, standalone, 2.4-latest, L1)
- check-success!=Backup and restore api (docker-compose, standalone, 2.4-latest, L2)
actions:
label:
remove:
Expand Down
35 changes: 29 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@ on:
schedule:
- cron: '0 0 * * *'


env:
go-version: 1.23

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
unit-test-go:
name: Unit test go
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go ${{ env.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
cache: true
- name: Unit test
run: make test

test-backup-restore-cross-version:
needs: unit-test-go
name: Backup and restore cross version
runs-on: ubuntu-latest
strategy:
Expand All @@ -41,8 +59,9 @@ jobs:
cache: pip

- uses: actions/setup-go@v3
name: Set up Go ${{ env.go-version }}
with:
go-version: '1.23'
go-version: ${{ env.go-version }}
cache: true

- name: Build
Expand All @@ -62,7 +81,6 @@ jobs:
sudo chmod +x /usr/local/bin/docker-compose
- name: Milvus deploy

timeout-minutes: 15
shell: bash
working-directory: deployment/${{ matrix.milvus_mode }}
Expand Down Expand Up @@ -157,6 +175,7 @@ jobs:
python example/verify_data.py
test-backup-restore-after-upgrade:
needs: unit-test-go
name: Backup and restore after upgrade
runs-on: ubuntu-latest
strategy:
Expand All @@ -181,8 +200,9 @@ jobs:
cache: pip

- uses: actions/setup-go@v3
name: Set up Go ${{ env.go-version }}
with:
go-version: '1.23'
go-version: ${{ env.go-version }}
cache: true

- name: Build
Expand Down Expand Up @@ -251,6 +271,7 @@ jobs:
test-backup-restore-cli:
needs: unit-test-go
name: Backup and restore cli
runs-on: ubuntu-latest
strategy:
Expand All @@ -272,8 +293,9 @@ jobs:
cache: pip

- uses: actions/setup-go@v3
name: Set up Go ${{ env.go-version }}
with:
go-version: '1.23'
go-version: ${{ env.go-version }}
cache: true

- name: Build
Expand Down Expand Up @@ -386,6 +408,7 @@ jobs:
python example/verify_data.py
test-backup-restore-with-rbac-config:
needs: unit-test-go
name: Backup and restore with rbac config
runs-on: ubuntu-latest
strategy:
Expand All @@ -406,7 +429,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.23'
go-version: ${{ env.go-version }}
cache: "true"

- name: Creating kind cluster
Expand Down Expand Up @@ -555,7 +578,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.23'
go-version: ${{ env.go-version }}
cache: true

- name: Build
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ LDFLAGS += -X "$(PKG)/version.Date=$(DATE)"
# Default target
all: gen build

test:
@echo "Running unit tests..."
@go test --race ./...

# Build the binary
build:
@echo "Building Backup binary..."
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ Execute `make all` will generate an executable binary `milvus-backup` in the `{p

### Test

Developers can also test it using an IDE. `core/backup_context_test.go` contains test demos for all main interfaces. Alternatively, you can test it using the command line interface:
Developers can also test it using an IDE. You can test it using the command line interface:

```shell
cd core
go test -v -test.run TestCreateBackup
make test
```


Expand Down
8 changes: 4 additions & 4 deletions core/backup_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type BackupContext struct {
grpcClient client.Grpc

// restful client
restfulClient client.Restful
restfulClient client.RestfulBulkInsert

// data storage client
milvusStorageClient storage.ChunkManager
Expand Down Expand Up @@ -80,7 +80,7 @@ func paramsToCfg(params *paramtable.BackupParams) (*client.Cfg, error) {
}

cfg := &client.Cfg{
Address: ep,
Host: ep,
EnableTLS: enableTLS,
Username: params.MilvusCfg.User,
Password: params.MilvusCfg.Password,
Expand All @@ -104,7 +104,7 @@ func CreateGrpcClient(params *paramtable.BackupParams) (client.Grpc, error) {
return cli, nil
}

func CreateRestfulClient(params *paramtable.BackupParams) (client.Restful, error) {
func CreateRestfulClient(params *paramtable.BackupParams) (client.RestfulBulkInsert, error) {
cfg, err := paramsToCfg(params)
if err != nil {
log.Error("failed to create restful client", zap.Error(err))
Expand Down Expand Up @@ -160,7 +160,7 @@ func (b *BackupContext) getMilvusClient() client.Grpc {
return b.grpcClient
}

func (b *BackupContext) getRestfulClient() client.Restful {
func (b *BackupContext) getRestfulClient() client.RestfulBulkInsert {
if b.restfulClient == nil {
restfulClient, err := CreateRestfulClient(b.params)
if err != nil {
Expand Down
Loading

0 comments on commit dd5511c

Please sign in to comment.