Skip to content

build: update chat test. #55

build: update chat test.

build: update chat test. #55

name: Docker Deployment Test
on:
push:
branches:
- main
pull_request:
branches:
- main
paths-ignore:
- "**/*.md"
workflow_dispatch:
jobs:
docker-build:
name: Test docker deployment on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
pull-requests: write
strategy:
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Docker
uses: docker/setup-buildx-action@v3.8.0
- name: Run Docker Compose
run: |
docker compose up -d
docker compose ps
- name: Test OpenIM Server
run: |
check_error() {
echo "Response: $1"
errCode=$(echo $1 | jq -r '.errCode')
if [ "$errCode" != "0" ]; then
errMsg=$(echo $1 | jq -r '.errMsg')
echo "Error: $errMsg"
exit 1
fi
}
wait_for_service() {
local url=$1
local max_retries=30
local retry_count=0
local response
until [ $retry_count -ge $max_retries ]
do
response=$(curl -s -o /dev/null -w "%{http_code}" $url) || true
if [ "$response" != "000" ]; then
echo "Service at $url is up"
return 0
fi
retry_count=$((retry_count+1))
echo "Waiting for service at $url to be up... ($retry_count/$max_retries)"
echo "Response code: $response"
sleep 10
done
echo "Service at $url failed to start"
exit 1
}
wait_for_service http://127.0.0.1:10002/auth/get_admin_token
get_admin_token_response=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -d '{
"secret": "openIM123",
"platformID": 2,
"userID": "imAdmin"
}' http://127.0.0.1:10002/auth/get_admin_token)
check_error "$get_admin_token_response"
adminToken=$(echo $get_admin_token_response | jq -r '.data.token')
echo "adminToken: $adminToken"
echo "ADMIN_TOKEN=$adminToken" >> $GITHUB_ENV
# docker logs openim-server
echo "echo ${{ env.ADMIN_TOKEN }}"
- name: Test OpenIM chat
run: |
check_error() {
echo "Response: $1"
errCode=$(echo $1 | jq -r '.errCode')
if [ "$errCode" != "0" ]; then
errMsg=$(echo $1 | jq -r '.errMsg')
echo "Error: $errMsg"
exit 1
fi
}
# sleep 35
wait_for_service() {
local url=$1
local max_retries=30
local retry_count=0
local response
until [ $retry_count -ge $max_retries ]
do
response=$(curl -s -o /dev/null -w "%{http_code}" $url) || true
if [ "$response" != "000" ]; then
echo "Service at $url is up"
return 0
fi
retry_count=$((retry_count+1))
echo "Waiting for service at $url to be up... ($retry_count/$max_retries)"
echo "Response code: $response"
sleep 10
done
echo "Service at $url failed to start"
exit 1
}
# Wait all Service
wait_for_service http://127.0.0.1:10008/account/register
wait_for_service http://127.0.0.1:10002/auth/get_admin_token
# Test register
response1=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -d '{
"verifyCode": "666666",
"platform": 3,
"autoLogin": true,
"user":{
"nickname": "test12312",
"areaCode":"+86",
"phoneNumber": "12345678190",
"password":"test123456"
}
}' http://127.0.0.1:10008/account/register)
check_error "$response1"
userID1=$(echo $response1 | jq -r '.data.userID')
echo "userID1: $userID1"
response2=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -d '{
"verifyCode": "666666",
"platform": 3,
"autoLogin": true,
"user":{
"nickname": "test22312",
"areaCode":"+86",
"phoneNumber": "12345678290",
"password":"test123456"
}
}' http://127.0.0.1:10008/account/register)
check_error "$response2"
userID2=$(echo $response2 | jq -r '.data.userID')
echo "userID2: $userID2"
# Test login
login_response=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -d '{
"platform": 3,
"areaCode":"+86",
"phoneNumber": "12345678190",
"password":"test123456"
}' http://localhost:10008/account/login)
check_error "$login_response"
# # Test get admin token
# get_admin_token_response=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -d '{
# "secret": "openIM123",
# "platformID": 2,
# "userID": "imAdmin"
# }' http://127.0.0.1:10002/auth/get_admin_token)
# check_error "$get_admin_token_response"
# adminToken=$(echo $get_admin_token_response | jq -r '.data.token')
# echo "adminToken: $adminToken"
# Test send message
send_msg_response=$(curl -X POST -H "Content-Type: application/json" -H "operationID: imAdmin" -H "token: ${{ env.ADMIN_TOKEN }}" -d '{
"sendID": "'$userID1'",
"recvID": "'$userID2'",
"senderPlatformID": 3,
"content": {
"content": "hello!!"
},
"contentType": 101,
"sessionType": 1
}' http://127.0.0.1:10002/msg/send_msg)
check_error "$send_msg_response"
go-test:
name: Benchmark Test with go ${{ matrix.go_version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
env:
SDK_DIR: openim-sdk-core
CONFIG_PATH: docker-compose.yaml
strategy:
matrix:
os: [ubuntu-latest]
go_version: ["1.22.x"]
steps:
- name: Checkout Docker repository
uses: actions/checkout@v4
- name: Checkout SDK repository
uses: actions/checkout@v4
with:
repository: "openimsdk/openim-sdk-core"
ref: "release-v3.8"
path: ${{ env.SDK_DIR }}
- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}
- name: Modify Server Configuration
run: |
yq eval '.services.openim-server.environment += ["IMENV_NOTIFICATION_GROUPCREATED_UNREADCOUNT=TRUE"]' -i ${{ env.CONFIG_PATH }}
yq eval '.services.openim-server.environment += ["IMENV_NOTIFICATION_FRIENDAPPLICATIONAPPROVED_UNREADCOUNT=TRUE"]' -i ${{ env.CONFIG_PATH }}
- name: Start Server Services
run: |
docker compose up -d
- name: Build test SDK core
run: |
cd ${{ env.SDK_DIR }}
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