Skip to content

Commit

Permalink
test add integrate test (#183)
Browse files Browse the repository at this point in the history
* test add integrate test

* add license checker

* add license checker

* add license checker

* chmod sh

* chmod +X sh

* fix config path

* fix config path

* fix config path

* fix config path

* fix config path

* modify travis path

* split import

Former-commit-id: da732e8
  • Loading branch information
xiaoliu10 authored Jul 1, 2021
1 parent facba55 commit 04cac0a
Show file tree
Hide file tree
Showing 18 changed files with 1,025 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ jobs:
- name: Go Test
run: |
chmod u+x before_ut.sh && ./before_ut.sh
go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
# chmod +x integrate_test.sh && ./integrate_test.sh
go mod vendor && go test ./pkg/... -coverprofile=coverage.txt -covermode=atomic
# integration test
- name: Integration Test
run: |
chmod +x start_integrate_test.sh && chmod +x integrate_test.sh && ./start_integrate_test.sh
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ script:
# unit-test
- echo 'start unit-test'
- chmod u+x before_ut.sh && ./before_ut.sh
- go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
- go mod vendor && go test ./pkg/... -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
152 changes: 152 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

PROJECT_NAME = $(shell basename "$(PWD)")
PID = /tmp/.$(PROJECT_NAME).pid
PROJECT_DIR=$(shell pwd)
BASE_DIR := $(PROJECT_DIR)/dist
PIXIU_DIR := $(PIXIU_DIR)
PIXIU_PID = /tmp/.pixiu.pid

SOURCES = $(wildcard $(PROJECT_DIR)/server/app/*.go)
pixiuSources = $(wildcard $(PIXIU_DIR)/cmd/pixiu/*.go)

export GO111MODULE ?= on
export GOPROXY ?= https://goproxy.io,direct
export GOSUMDB ?= sum.golang.org
export GOARCH ?= amd64

export DOCKER_HOST_IP = $(shell ifconfig en0 | grep inet | grep -v inet6 | awk '{print $$2}')

OS := $(shell uname)
ifeq ($(OS), Linux)
export GOOS ?= linux
else ifeq ($(OS), Darwin)
export GOOS ?= darwin
else
export GOOS ?= windows
endif

ifeq ($(GOOS), windows)
export EXT_NAME ?= .exe
else
export EXT_NAME ?=
endif

CGO ?= 0
ifeq ($(DEBUG), true)
BUILD_TYPE := debug
GCFLAGS := -gcflags="all=-N -l"
LCFLAGS :=
else
BUILD_TYPE := release
LDFLAGS := "-s -w"
endif

OUT_DIR := $(BASE_DIR)/$(GOOS)_$(GOARCH)/$(rtfg8u7)
LOG_FILE := $(OUT_DIR)/$(PROJECT_NAME).log
API_CONFIG_PATH := $(OUT_DIR)/pixiuconf/api_config.yaml
CONFIG_PATH := $(OUT_DIR)/pixiuconf/conf.yaml

export APP_LOG_CONF_FILE ?= $(OUT_DIR)/conf/log.yml

.PHONY: all
all: help
help: $(realpath $(firstword $(MAKEFILE_LIST)))
@echo
@echo " Choose a command run in "$(PROJECT_NAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo

## build: Build application's binaries
.PHONY: build
build: $(OUT_DIR)/$(PROJECT_NAME)$(EXT_NAME) config

.PHONY: $(OUT_DIR)/$(PROJECT_NAME)$(EXT_NAME)
$(OUT_DIR)/$(PROJECT_NAME)$(EXT_NAME):
$(info > Buiding application binary: $(OUT_DIR)/$(PROJECT_NAME)$(EXT_NAME))
@CGO_ENABLED=$(CGO) GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GCFLAGS) -ldflags=$(LDFLAGS) -i -o $(OUT_DIR)/server/$(PROJECT_NAME)$(EXT_NAME) $(SOURCES)


## config: Setup config files
.PHONY: config
config:
$(info > Setting up config files)
@mkdir -p $(OUT_DIR)/server
@mkdir -p $(OUT_DIR)/pixiuconf
@-test -f $(PROJECT_DIR)/server/profiles/dev/log.yml && cat $(PROJECT_DIR)/server/profiles/dev/log.yml | sed "s#\$$HOST_IP#$(DOCKER_HOST_IP)#g" > $(OUT_DIR)/server/log.yml && echo " > $(OUT_DIR)/conf/log.yml"
@-test -f $(PROJECT_DIR)/server/profiles/dev/server.yml && cat $(PROJECT_DIR)/server/profiles/dev/server.yml | sed "s#\$$HOST_IP#$(DOCKER_HOST_IP)#g" > $(OUT_DIR)/server/server.yml && echo " > $(OUT_DIR)/conf/server.yml"
@-test -f $(PROJECT_DIR)/pixiu/api_config.yaml && cat $(PROJECT_DIR)/pixiu/api_config.yaml | sed "s#\$$HOST_IP#$(DOCKER_HOST_IP)#g" > $(OUT_DIR)/pixiuconf/api_config.yaml && echo " > $(OUT_DIR)/pixiuconf/api_config.yaml"
@-test -f $(PROJECT_DIR)/pixiu/conf.yaml && cat $(PROJECT_DIR)/pixiu/conf.yaml | sed "s#\$$HOST_IP#$(DOCKER_HOST_IP)#g" > $(OUT_DIR)/pixiuconf/conf.yaml && echo " > $(OUT_DIR)/pixiuconf/conf.yaml"

## docker-up: Shutdown dependency services on docker
.PHONY: docker-up
docker-up:
$(info > Starting dependency services with $(PROJECT_DIR)/docker/docker-compose.yml)
@docker-compose -f $(PROJECT_DIR)/docker/docker-compose.yml up -d

## docker-down: Shutdown dependency services on docker
.PHONY: docker-down
docker-down:
$(info > Stopping dependency services with $(PROJECT_DIR)/docker/docker-compose.yml)
@docker-compose -f $(PROJECT_DIR)/docker/docker-compose.yml down

## clean: Clean up the output and the binary of the application
.PHONY: clean
clean: stop
$(info > Cleanning up $(OUT_DIR))
@-rm -rf $(OUT_DIR)
@-cat $(PID) | awk '{print $1}' | xargs kill -9
@-cat $(PIXIU_PID) | awk '{print $1}' | xargs kill -9

## start: Start the application (for server)
.PHONY: start
start: export CONF_PROVIDER_FILE_PATH ?= $(OUT_DIR)/server/server.yml
start: build
$(info > Starting application $(PROJECT_NAME), output is redirected to $(LOG_FILE))
@-$(OUT_DIR)/server/$(PROJECT_NAME)$(EXT_NAME) > $(LOG_FILE) 2>&1 & echo $$! > $(PID)
@cat $(PID) | sed "/^/s/^/ \> PID: /"

## run: Run the application (for client)
.PHONY: run
run: buildPixiu
$(info > Running application PIXIU, output is redirected to $(LOG_FILE))

## buildPixiu: start pixiu
.PHONY: buildPixiu
buildPixiu:
@CGO_ENABLED=$(CGO) GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GCFLAGS) -ldflags=$(LDFLAGS) -i -o $(OUT_DIR)/pixiu$(EXT_NAME) $(pixiuSources)
@-$(OUT_DIR)/pixiu$(EXT_NAME) -a $(API_CONFIG_PATH) -c $(CONFIG_PATH) & echo $$! > $(PIXIU_PID)
@cat $(PIXIU_PID) | sed "/^/s/^/ \> PIXIU_PID: /"
## stop: Stop running the application (for server)
.PHONY: stop
stop:
$(info > Stopping the application $(PROJECT_NAME))
@cat $(PID) | sed "/^/s/^/ \> Killing PID: /"
@-kill `cat $(PID)` 2>/dev/null || true

## integration: Run integration test for this application
.PHONY: integration
integration: export CONF_CONSUMER_FILE_PATH ?= $(OUT_DIR)/conf/client.yml
integration: export CONF_ROUTER_FILE_PATH ?= $(OUT_DIR)/conf/router_config.yml
integration:
$(info > Running integration test for application $(PROJECT_NAME))
@go clean -testcache
@go test -tags integration -v $(PROJECT_DIR)/test/...
39 changes: 39 additions & 0 deletions integrate_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ -z "$1" ]; then
echo 'Provide test directory please, like : ./integrate_test.sh $(pwd)/samples/simple/server .'
exit
fi

P_DIR=$(pwd)/$1
PIXIU_DIR=$(pwd)

make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile docker-up

# start server
make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile start
# start pixiu
make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile buildPixiu
# start integration
make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile integration
result=$?
# stop server
make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile clean

make PROJECT_DIR=$P_DIR PIXIU_DIR=$PIXIU_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile docker-down

exit $((result))
27 changes: 27 additions & 0 deletions samples/dubbogo/simple/body/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

version: '3'

services:
zookeeper:
image: zookeeper
ports:
- 2181:2181
restart: on-failure
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions samples/dubbogo/simple/body/server/app/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)

import (
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"

_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
_ "github.com/apache/dubbo-go/filter/filter_impl"

_ "github.com/apache/dubbo-go/cluster/cluster_impl"
_ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/registry/zookeeper"
)

var survivalTimeout = int(3e9)

// they are necessary:
// export CONF_PROVIDER_FILE_PATH="xxx"
// export APP_LOG_CONF_FILE="xxx"
func main() {
config.Load()
logger.Info("dubbo version is: %s", Version)
initSignal()
}

func initSignal() {
signals := make(chan os.Signal, 1)
// It is not possible to block SIGKILL or syscall.SIGSTOP
signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
sig := <-signals
logger.Infof("get signal %s", sig.String())
switch sig {
case syscall.SIGHUP:
// reload()
default:
time.AfterFunc(time.Duration(survivalTimeout), func() {
logger.Warnf("app exit now by force...")
os.Exit(1)
})

// The program exits normally or timeout forcibly exits.
fmt.Println("provider app exit now...")
return
}
}
}
Loading

0 comments on commit 04cac0a

Please sign in to comment.