This is my implementation for backend assignment of 2023 TikTok Tech Immersion.
Requirements: https://bytedance.sg.feishu.cn/docx/P9kQdDkh5oqG37xVm5slN1Mrgle
Make sure you have docker and docker-compose installed. Run the following command to start the app:
docker-compose upExecute the following command to connect to the running redis container:
docker exec -it $(docker ps | grep redis | awk '{print $1;}') redis-cliThen execute the following command to delete all data:
FLUSHALLCheck if the server is running
curl -X GET http://localhost:8080/pingExpected response: status 200
{
"message": "pong"
}Send a message to a chat
curl -X POST \
http://localhost:8080/api/send \
-H 'Content-Type: application/json' \
-d '{
"Chat": "user1:user2",
"Text": "Hello World",
"Sender": "user1"
}'Expected response: status 201
ok
Get messages from a chat from Cursor with Limit messages and sorting order Reverse (default: false)
curl -X GET \
http://localhost:8080/api/pull \
-H 'Content-Type: application/json' \
-d '{
"Chat": "user1:user2",
"Cursor": 0,
"Limit": 20,
"Reverse": false
}'Expected Response: status 200
{
"messages": [
{
"chat": "user1:user2",
"text": "Lorem ipsum dolor ...",
"sender": "john",
"send_time": 1684744610
}, ...
]
}Execute the following command in ./rpc-server folder to run unit tests and get test coverage:
go test -race -cover -coverprofile=coverage.out $(go list ./... | grep -Ev "_gen") -coverpkg $(go list ./... | grep -Ev "_gen" | tr "\n" "," | sed 's/.$//')Use the script stress_test.sh to run a stress test with <concurrent> concurrent requests and <requests> request batches.
./stress_test.sh <concurrent> <requests>- go
- kitex
- redis
- docker
- github actions