Skip to content

Commit

Permalink
SearchQnA UT (#421)
Browse files Browse the repository at this point in the history
Signed-off-by: Yue, Wenjiao <wenjiao.yue@intel.com>
  • Loading branch information
WenjiaoYue authored Jul 25, 2024
1 parent 5984848 commit 268d58d
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 59 deletions.
16 changes: 16 additions & 0 deletions SearchQnA/docker/gaudi/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ services:
- LLM_SERVICE_PORT=${LLM_SERVICE_PORT}
ipc: host
restart: always
searchqna-gaudi-ui-server:
image: opea/searchqna-ui:latest
container_name: searchqna-gaudi-ui-server
depends_on:
- searchqna-gaudi-backend-server
ports:
- "5173:5173"
environment:
- no_proxy=${no_proxy}
- https_proxy=${https_proxy}
- http_proxy=${http_proxy}
- BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
ipc: host
restart: always



networks:
default:
Expand Down
2 changes: 1 addition & 1 deletion SearchQnA/docker/ui/svelte/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKEND_BASE_URL = 'http://x.x.x.x:yyyy/v1/searchqna'
BACKEND_BASE_URL = 'http://backend_address:3008/v1/searchqna'
1 change: 1 addition & 0 deletions SearchQnA/docker/ui/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@playwright/test": "^1.45.2",
"@sveltejs/adapter-auto": "1.0.0-next.75",
"@sveltejs/kit": "^1.30.4",
"@tailwindcss/typography": "0.5.7",
Expand Down
54 changes: 54 additions & 0 deletions SearchQnA/docker/ui/svelte/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests",
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [["html", { open: "never" }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://localhost:5173",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
class={msg.role === 0
? "flex w-full gap-3"
: "flex w-full items-center gap-3"}
data-testid={msg.role === 0
? "display-answer"
: "display-question"}
>
<div
class={msg.role === 0
Expand Down
1 change: 1 addition & 0 deletions SearchQnA/docker/ui/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
class="text-md block w-full border-0 border-b-2 border-gray-300 px-1 py-4
text-gray-900 focus:border-gray-300 focus:ring-0 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
type="text"
data-testid="chat-input"
placeholder="Enter prompt here"
disabled={loading}
maxlength="1200"
Expand Down
29 changes: 29 additions & 0 deletions SearchQnA/docker/ui/svelte/tests/searchQnA.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

import { test, expect, type Page } from "@playwright/test";

// Initialization before each test
test.beforeEach(async ({ page }) => {
await page.goto("/");
});

// Constants definition
const CHAT_ITEMS = ["What is the total revenue of Nike in 2023?"];

// Helper function: Enter message to chat
async function enterMessageToChat(page: Page, message: string) {
await page.getByTestId("chat-input").click();
await page.getByTestId("chat-input").fill(message);
await page.getByTestId("chat-input").press("Enter");
await page.waitForTimeout(10000);
await expect(page.getByTestId("display-answer")).toBeVisible();
}

// Test description: New Chat
test.describe("New Chat", () => {
// Test: Enter message to chat
test("should enter message to chat", async ({ page }) => {
await enterMessageToChat(page, CHAT_ITEMS[0]);
});
});
15 changes: 15 additions & 0 deletions SearchQnA/docker/xeon/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ services:
- LLM_SERVICE_PORT=${LLM_SERVICE_PORT}
ipc: host
restart: always
searchqna-gaudi-ui-server:
image: opea/searchqna-ui:latest
container_name: searchqna-xeon-ui-server
depends_on:
- searchqna-xeon-backend-server
ports:
- "5173:5173"
environment:
- no_proxy=${no_proxy}
- https_proxy=${https_proxy}
- http_proxy=${http_proxy}
- BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
ipc: host
restart: always


networks:
default:
Expand Down
61 changes: 32 additions & 29 deletions SearchQnA/tests/test_searchqna_on_gaudi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# for test

set -e
set -xe

WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests"
Expand All @@ -30,8 +30,8 @@ function build_docker_images() {
cd $WORKPATH/docker
docker build --no-cache -t opea/searchqna:latest -f Dockerfile .

# cd $WORKPATH/docker/ui
# docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
cd $WORKPATH/docker/ui
docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .

docker images
}
Expand Down Expand Up @@ -66,8 +66,10 @@ function start_services() {
export WEB_RETRIEVER_SERVICE_PORT=3003
export RERANK_SERVICE_PORT=3005
export LLM_SERVICE_PORT=3007
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:3008/v1/searchqna"

# sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env

sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env

if [[ "$IMAGE_REPO" != "" ]]; then
# Replace the container name with a test-specific name
Expand Down Expand Up @@ -111,30 +113,31 @@ function validate_megaservice() {

}

#function validate_frontend() {
# cd $WORKPATH/docker/ui/svelte
# local conda_env_name="OPEA_e2e"
# export PATH=${HOME}/miniforge3/bin/:$PATH
## conda remove -n ${conda_env_name} --all -y
## conda create -n ${conda_env_name} python=3.12 -y
# source activate ${conda_env_name}
#
# sed -i "s/localhost/$ip_address/g" playwright.config.ts
#
## conda install -c conda-forge nodejs -y
# npm install && npm ci && npx playwright install --with-deps
# node -v && npm -v && pip list
#
# exit_status=0
# npx playwright test || exit_status=$?
#
# if [ $exit_status -ne 0 ]; then
# echo "[TEST INFO]: ---------frontend test failed---------"
# exit $exit_status
# else
# echo "[TEST INFO]: ---------frontend test passed---------"
# fi
#}
function validate_frontend() {
cd $WORKPATH/docker/ui/svelte
local conda_env_name="OPEA_e2e"

export PATH=${HOME}/miniforge3/bin/:$PATH
# conda remove -n ${conda_env_name} --all -y
# conda create -n ${conda_env_name} python=3.12 -y
source activate ${conda_env_name}

sed -i "s/localhost/$ip_address/g" playwright.config.ts

# conda install -c conda-forge nodejs -y
npm install && npm ci && npx playwright install --with-deps
node -v && npm -v && pip list

exit_status=0
npx playwright test || exit_status=$?

if [ $exit_status -ne 0 ]; then
echo "[TEST INFO]: ---------frontend test failed---------"
exit $exit_status
else
echo "[TEST INFO]: ---------frontend test passed---------"
fi
}

function stop_docker() {
cd $WORKPATH/docker/gaudi
Expand All @@ -148,7 +151,7 @@ function main() {
start_services

validate_megaservice
# validate_frontend
validate_frontend

stop_docker
echo y | docker system prune
Expand Down
60 changes: 31 additions & 29 deletions SearchQnA/tests/test_searchqna_on_xeon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -e
set -xe

WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests"
Expand All @@ -22,8 +22,8 @@ function build_docker_images() {
cd $WORKPATH/docker
docker build -t opea/searchqna:latest -f Dockerfile .

# cd $WORKPATH/docker/ui
# docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
cd $WORKPATH/docker/ui
docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .

docker images
}
Expand Down Expand Up @@ -52,8 +52,10 @@ function start_services() {
export WEB_RETRIEVER_SERVICE_PORT=3003
export RERANK_SERVICE_PORT=3005
export LLM_SERVICE_PORT=3007
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:3008/v1/searchqna"

# sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env

sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env

if [[ "$IMAGE_REPO" != "" ]]; then
# Replace the container name with a test-specific name
Expand Down Expand Up @@ -94,30 +96,30 @@ function validate_megaservice() {

}

#function validate_frontend() {
# cd $WORKPATH/docker/ui/svelte
# local conda_env_name="OPEA_e2e"
# export PATH=${HOME}/miniforge3/bin/:$PATH
## conda remove -n ${conda_env_name} --all -y
## conda create -n ${conda_env_name} python=3.12 -y
# source activate ${conda_env_name}
#
# sed -i "s/localhost/$ip_address/g" playwright.config.ts
#
## conda install -c conda-forge nodejs -y
# npm install && npm ci && npx playwright install --with-deps
# node -v && npm -v && pip list
#
# exit_status=0
# npx playwright test || exit_status=$?
#
# if [ $exit_status -ne 0 ]; then
# echo "[TEST INFO]: ---------frontend test failed---------"
# exit $exit_status
# else
# echo "[TEST INFO]: ---------frontend test passed---------"
# fi
#}
function validate_frontend() {
cd $WORKPATH/docker/ui/svelte
local conda_env_name="OPEA_e2e"
export PATH=${HOME}/miniforge3/bin/:$PATH
# conda remove -n ${conda_env_name} --all -y
# conda create -n ${conda_env_name} python=3.12 -y
source activate ${conda_env_name}

sed -i "s/localhost/$ip_address/g" playwright.config.ts

# conda install -c conda-forge nodejs -y
npm install && npm ci && npx playwright install --with-deps
node -v && npm -v && pip list

exit_status=0
npx playwright test || exit_status=$?

if [ $exit_status -ne 0 ]; then
echo "[TEST INFO]: ---------frontend test failed---------"
exit $exit_status
else
echo "[TEST INFO]: ---------frontend test passed---------"
fi
}

function stop_docker() {
cd $WORKPATH/docker/xeon
Expand All @@ -131,7 +133,7 @@ function main() {
start_services

validate_megaservice
# validate_frontend
validate_frontend

stop_docker
echo y | docker system prune
Expand Down

0 comments on commit 268d58d

Please sign in to comment.