Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: add initial tests #226

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 59 additions & 8 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

concurrency:
Expand All @@ -22,8 +25,8 @@ jobs:
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.RELEASE_DOCKERHUB_USERNAME }}
password: ${{ secrets.RELEASE_DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -34,8 +37,8 @@ jobs:
context: backend
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/tidb.ai-py:latest
${{ secrets.DOCKERHUB_USERNAME }}/tidb.ai-py:${{ github.sha }}
${{ (github.ref == 'refs/heads/main' && format('{0}/backend:dev', secrets.RELEASE_DOCKERHUB_USERNAME)) || '' }}
${{ secrets.RELEASE_DOCKERHUB_USERNAME }}/backend:dev-${{ github.sha }}

build-frontend:
name: Build and Push Frontend Image
Expand All @@ -48,8 +51,8 @@ jobs:
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ secrets.RELEASE_DOCKERHUB_USERNAME }}
password: ${{ secrets.RELEASE_DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -61,5 +64,53 @@ jobs:
file: ./frontend/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/tidb.ai-py-fe:latest
${{ secrets.DOCKERHUB_USERNAME }}/tidb.ai-py-fe:${{ github.sha }}
${{ (github.ref == 'main' && format('{0}/frontend:dev', secrets.RELEASE_DOCKERHUB_USERNAME)) || '' }}
${{ secrets.RELEASE_DOCKERHUB_USERNAME }}/frontend:dev-${{ github.sha }}

e2e-test:
name: E2E Test
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: e2e
needs:
- build-backend
- build-frontend
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install dependencies
run: npm ci

- uses: KengoTODA/actions-setup-docker-compose@v1
with:
version: '2.14.2'

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run tests
run: ./start-test.sh
env:
E2E_DOCKER_TAG: dev-${{ github.sha }}
E2E_LLM_PROVIDER: ${{env.E2E_LLM_PROVIDER}}
E2E_LLM_MODEL: ${{env.E2E_LLM_MODEL || ''}}
E2E_LLM_CREDENTIALS: ${{secrets.E2E_LLM_CREDENTIALS}}
E2E_EMBEDDING_PROVIDER: ${{env.E2E_EMBEDDING_PROVIDER || 'openai'}}
E2E_EMBEDDING_MODEL: ${{env.E2E_EMBEDDING_MODEL || ''}}
E2E_EMBEDDING_CREDENTIALS: ${{secrets.E2E_EMBEDDING_CREDENTIALS}}
E2E_RERANKER_PROVIDER: ${{env.E2E_RERANKER_PROVIDER || 'jinaai'}}
E2E_RERANKER_MODEL: ${{env.E2E_RERANKER_MODEL || ''}}
E2E_RERANKER_CREDENTIALS: ${{secrets.E2E_RERANKER_CREDENTIALS}}

- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e/playwright-report
path: e2e/playwright-report/
retention-days: 30
8 changes: 8 additions & 0 deletions e2e/.env.compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ENVIRONMENT=local
SECRET_KEY=w-cWBaNYuRRkuCWYFq5_cUxQor-b-nHfuupYpRCiFec
DSP_CACHEBOOL=false
TIDB_HOST=tidb
TIDB_USER=root
TIDB_PASSWORD=""
TIDB_DATABASE=test
TIDB_SSL=false
16 changes: 16 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

.idea

.env.local
local-test.sh

# Internal output
.credentials
*.stdout
*.stderr
screenshots
30 changes: 30 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Integration Test for TIDB.ai

## Requirements

- Docker compose
- NodeJS env
- OpenAI Api Key

```bash
npm i
echo OPENAI_API_KEY=sk-*** > .env.local
```

## Usage

### Start local TiDB.ai

```bash
$ ./start-cluster.sh

> ...
> ...
> [TiDB.AI Integration Test] Press Enter to exit...
```

### Run tests

```bash
npm start
```
56 changes: 56 additions & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: tidb-ai-integration-test

services:
tidb:
image: wangdi4zm/tind:v7.5.3-vector-index
restart: always

redis:
image: redis:6.0.16
restart: always

backend:
image: tidbai/backend:${E2E_DOCKER_TAG}
restart: always
depends_on:
- redis
ports:
- "5000:80"
env_file:
- .env.compose
logging:
driver: json-file
options:
max-size: "50m"
max-file: "6"

frontend:
image: tidbai/frontend:${E2E_DOCKER_TAG}
restart: always
depends_on:
- backend
ports:
- 3000:3000
environment:
BASE_URL: http://backend
logging:
driver: json-file
options:
max-size: "50m"
max-file: "6"

background:
image: tidbai/backend:${E2E_DOCKER_TAG}
restart: always
depends_on:
- redis
ports:
- "5555:5555"
env_file:
- .env.compose
command: /usr/bin/supervisord
logging:
driver: json-file
options:
max-size: "50m"
max-file: "6"
112 changes: 112 additions & 0 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "tidb.ai-playwright",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "playwright test"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.46.0",
"@types/node": "^22.2.0"
},
"dependencies": {
"dotenv": "^16.4.5"
}
}
Loading
Loading