Skip to content

Commit

Permalink
Merge pull request #2 from sofastack/master
Browse files Browse the repository at this point in the history
update master
  • Loading branch information
chenlei3641 authored Nov 28, 2023
2 parents dc369ea + ea1c8cc commit ac122e1
Show file tree
Hide file tree
Showing 629 changed files with 10,007 additions and 1,159 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/arklet_cd_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: SOFA Serverless Runtime CD Test
## trigger manually
on:
workflow_dispatch:

# Environment variables available to all jobs and steps in this workflow.
env:
NAMESPACE: sofaark_test
IMAGE: sofa-runtime-cdtest
TAG: ${{ github.sha }}

permissions:
contents: read

jobs:
ci_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven

- name: Set up Docker
uses: docker/metadata-action@v3
with:
images: |
node:14
- name: get sofa-runtime version & update sofa-runtime version for all test sample app
run: |
serverless_runtime_version=`egrep "<revision.default>([^<]+)</revision.default>" sofa-serverless-runtime/pom.xml |awk -F "revision.default>|</revision.default" '{print $2}'`
echo "升级sofa-runtime version to $serverless_runtime_version"
for testsample in `find samples -name "*-samples"`;do sed -i "s/<sofa.serverless.runtime.version>.*<\/sofa.serverless.runtime.version>/<sofa.serverless.runtime.version>$serverless_runtime_version<\/sofa.serverless.runtime.version>/g" $testsample/pom.xml ;done
- name: Test Env prepare
run: |
sudo apt-get update >>/tmp/envprepare.out
sudo apt-get install -y expect >>/tmp/envprepare.out
docker pull mongo:7.0.2-jammy
docker run --name mongodb -d -p 27017:27017 -v /home/runner/work/data:/data/db mongo:7.0.2-jammy
docker pull zookeeper:3.9.0
docker run -p 2181:2181 -it --name zookeeper --restart always -d zookeeper:3.9.0
sudo apt-get install redis-server -y
sudo systemctl start redis-server
sudo cp samples/ccbin/arkctl /usr/bin/arkctl
- name: Run jdk8 serverless runtime test
run: |
set -e
bash samples/ccbin/start.sh jdk8
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Run jdk17 serverless runtime test
run: |
set -e
bash samples/ccbin/start.sh jdk17
10 changes: 5 additions & 5 deletions .github/workflows/arklet_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
cache: maven

- name: Test
run: mvn clean install -DskipTests -Dmaven.javadoc.skip=true -B -U
run: mvn clean install -DskipTests -P8-release -Dmaven.javadoc.skip=true -B -U
&& sh ./check_format.sh
&& mvn test
&& mvn test -P8-release

- name: upload coverage reports to Codecov with github action
uses: codecov/codecov-action@v3
Expand All @@ -56,9 +56,9 @@ jobs:
cache: maven

- name: Test
run: mvn clean install -DskipTests -Dmaven.javadoc.skip=true -B -U
run: mvn clean install -DskipTests -P17-release -Dmaven.javadoc.skip=true -B -U
&& sh ./check_format.sh
&& mvn test
&& mvn test -P17-release

- name: upload coverage reports to Codecov with github action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3
Binary file added .github/workflows/ccbin/arkctl
Binary file not shown.
59 changes: 59 additions & 0 deletions .github/workflows/ccbin/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
## 返回值 0 : 成功
## 返回值 1 : 检查失败导致
## 返回值 2 : 链接超时导致
##
## Usage : sh bin/healthcheck.sh

HEALTH_URL="http://localhost:8080/health"
HEALTH_CHECK_COMMOND="curl -s --connect-timeout 3 --max-time 5 ${HEALTH_URL}"

echo " -- SOFA Boot CheckService"
echo " -- HealthCheck URL : ${HEALTH_URL}"
#success:0;failure:1;timeout:2,and default value is failure=1
status=1
#default 120s
times=30

for num in $(seq $times); do
sleep 1
COSTTIME=$(($times - $num ))

HEALTH_CHECK_CODE=`${HEALTH_CHECK_COMMOND} -o /dev/null -w %{http_code}`
# reference : https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html#production-ready-health-access-restrictions
if [ "$HEALTH_CHECK_CODE" == "200" ]; then
#success
status=0;
break;
elif [ "$HEALTH_CHECK_CODE" == "503" ] ; then
echo -n -e "\r -- HealthCheck Cost Time `expr $num` seconds."
# failure
status=1;
break;
else
# starting
# echo -n -e "\r -- HealthCheck Remaining Time `expr $COSTTIME` seconds."
status=2;
fi
done

SOFA_BOOT_HEALTH_CHECK_RESULT="SUCCESS";

if [ $status -eq 1 ]; then
echo " -- HealthCheck Failed.-- Current Server Responded Http Code ${HEALTH_CHECK_CODE}"
SOFA_BOOT_HEALTH_CHECK_RESULT=`${HEALTH_CHECK_COMMOND}`;
# 重定向到标准错误流,zpaas 平台捕获打印
echo -e "Health Check Result \n$SOFA_BOOT_HEALTH_CHECK_RESULT" >&2
exit 1;
fi

if [ $status -eq 2 ]; then
SOFA_BOOT_HEALTH_CHECK_RESULT="Could Not Connect to ${HEALTH_URL}.HealthCheck ${times} Seconds Timeout!";
# 重定向到标准错误流,zpaas 平台捕获打印
echo -e "Health Check Result \n$SOFA_BOOT_HEALTH_CHECK_RESULT" >&2
exit 2;
fi

# success
# 重定向到标准错误流,zpaas 平台捕获打印
echo -e "Health Check Result \n$SOFA_BOOT_HEALTH_CHECK_RESULT" >&2
137 changes: 137 additions & 0 deletions .github/workflows/ccbin/moduletest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash

function module_biz_install_test() {
bizName=$1
bizDir=$2

/usr/bin/expect <<EOF
set fp [open "test_output.txt" w]
set timeout 5
spawn telnet localhost 1234
expect {
"Escape character is '^]'." {
puts -nonewline \$fp "Telnet connection success!\n"
}
timeout {
puts -nonewline \$fp "Telnet connection failed!\n"
}
eof {
puts -nonewline \$fp "Telnet connection failed!\n"
}
}
send "biz -i file://$bizDir\r"
expect {
"Start to process install command now, pls wait and check." {
puts -nonewline \$fp "module installing!\n"
}
timeout {
puts -nonewline \$fp "module install failed!\n"
}
eof {
puts -nonewline \$fp "Telnet connection failed!\n"
}
}
sleep 10
send "biz -a\r"
expect {
"$bizName*activated" {
puts -nonewline \$fp "module install success!\n"
}
timeout {
puts -nonewline \$fp "module install failed!\n"
}
eof {
puts -nonewline \$fp "Telnet connection failed!\n"
}
}
send "exit\r"
expect {
"Connection closed by foreign host" {
puts -nonewline \$fp "close telnet success!\n"
}
timeout {
puts -nonewline \$fp "close telnet failed!\n"
}
eof {
puts -nonewline \$fp "close telnet failed!\n"
}
}
close \$fp
EOF
}

function arkctl_module_biz_install_test() {
bizName=$1
bizVersion=$2
bizDir=$3

arkctl deploy $bizDir
arkStatus=$(arkctl status)
# 提取数据部分
data=$(echo $arkStatus | awk -F "QueryAllBiz " '{print $2}')
# 校验状态
if echo $data | grep -q "\"bizName\":\"$bizName\",\"bizState\":\"ACTIVATED\""; then
echo "biz $bizName install success"
else
echo "biz $bizName install failed:$arkStatus"
exit 1
fi
# 卸载模块
uninstallResult=$(curl --location 'http://localhost:1238/uninstallBiz' \
--header 'Content-Type: application/json' \
--data "{
\"bizName\":\"$bizName\",
\"bizVersion\":\"$bizVersion\"
}")
# 校验卸载
if echo $uninstallResult | grep -q "Uninstall biz: $bizName:$bizVersion success."; then
echo "biz $bizName unInstall success"
else
echo "biz $bizName unInstall failed:$uninstallResult"
exit 1
fi
# 2次安装
arkctl deploy $bizDir
arkStatus=$(arkctl status)
# 提取数据部分
data=$(echo $arkStatus | awk -F "QueryAllBiz " '{print $2}')
# 校验状态
if echo $data | grep -q "\"bizName\":\"$bizName\",\"bizState\":\"ACTIVATED\""; then
echo "biz $bizName install success"
else
echo "biz $bizName install failed:$arkStatus"
exit 1
fi
}

set -e
#测试路径
echo "BaseDir=$BaseDir"
cd $BaseDir/..

BIZ_INSTALL_URL="http://localhost:8080/module/install"
BIZ_LIST_URL="http://localhost:8080/module/list"

for moduleBootDir in $(find $(pwd) -type d -path "*/biz[1-9]" -o -path "*/*biz" |grep -v src|grep -v target|grep -v logs);do
echo "start deploy $moduleBootDir"
cd $moduleBootDir

echo "找到$(find $(pwd) -name "*-ark-biz.jar" | wc -l)个模块!"
for moduleJar in $(find $(pwd) -name "*-ark-biz.jar");do
moduleName=$(echo $moduleJar |awk -F "target/" '{print $2}' | sed -e 's/-[0-9].*$//')
moduleVersion=$(echo "$moduleJar" | sed "s/.*$moduleName-\(.*\)-ark-biz.jar/\1/")
echo "find one module, moduleName:$moduleName,moduleVersion:$moduleVersion, jar:$moduleJar"
echo ''>test_output.txt
arkctl_module_biz_install_test ${moduleName} ${moduleVersion} $moduleJar
# echo "start check module install result "
# cat test_output.txt|while read line;do
# if [[ $line =~ "failed" ]];then
# echo "module install fail:$line"
# exit 1
# fi
# done
done
echo "$BaseDir 测试完成!"
done

72 changes: 72 additions & 0 deletions .github/workflows/ccbin/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

function kill_java_process() {
local bootpids=`ps aux|grep java|grep sofa-runtimetest| grep -v grep |awk '{print $2;}'`
local boot_pid_array=($bootpids)
echo -e "\\nkilling SOFABoot processes:${boot_pid_array[@]}"
for bootpid in "${boot_pid_array[@]}"
do
if [ -z "$bootpid" ]; then
continue;
fi
echo "kill $bootpid"
kill $bootpid
/bin/sleep 3
killed_pid=`ps aux|grep java|grep $bootpid |awk '{print $2;}'`

if [[ "$killed_pid" == "$bootpid" ]]; then
echo "Kill $bootpid don't work and kill -9 $bootpid used violently!"
kill -9 $bootpid
fi
done
}

set -e

#dobbo common-model
ROOTDir=$(pwd)
testSuite=$1
echo "start testsuite:$testSuite"
if [[ $testSuite == "jdk8" ]];then
suiteReg="*[^3|^dubbo]-samples"
else
# suiteReg="*[3|dubbo]-samples"
suiteReg="*[3]-samples"

fi
#测试路径
for TEST_DIR in $(find $(pwd) -name "$suiteReg");do
TESTAPP_DIR=$TEST_DIR
echo "TESTAPP_DIR=$TESTAPP_DIR"
cd ${TESTAPP_DIR}
mvn clean install -U -Dmaven.test.skip=true
for BaseDir in $( find $(pwd) -type d -name "*base" |grep -v src|grep -v target|grep -v mybatis|grep -v logs);do
echo "BaseDir $BaseDir"
export BaseDir=$BaseDir
cd $BaseDir

echo "start clean old java processes"
kill_java_process

baseJar=$(find . -name "*[base|bootstrap]-*.jar"|grep -v facade)
echo "Deployed base app $baseJar"
if [[ "$baseJar" == "" ]];then
echo "找不到基座jar包!"
exit 1
fi
java -Dtest=sofa-runtimetest -Drpc_bind_network_interface=eth0 -jar $baseJar >/dev/null 2>&1 &
sleep 5

echo "Start health check"
bash $ROOTDir/.github/workflows/ccbin/healthcheck.sh

echo "Start module biz Test"
bash $ROOTDir/.github/workflows/ccbin/moduletest.sh

echo "测试通过 $BaseDir"

done
done

set +e

Loading

0 comments on commit ac122e1

Please sign in to comment.