Skip to content

Commit

Permalink
feat: start chunk before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
Van QA authored and louis-menlo committed Sep 6, 2024
1 parent 6beb96b commit 6afa083
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
10 changes: 7 additions & 3 deletions electron/tests/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ export const test = base.extend<
// After the test, we can check whether the test passed or failed.
if (testInfo.status !== testInfo.expectedStatus) {
await commonActions.takeScreenshot('')
await context.tracing.stopChunk({ path: TRACE_PATH })
await testInfo.attach('trace', { path: TRACE_PATH })
}

await context.tracing.stopChunk({ path: TRACE_PATH })
await testInfo.attach('trace', { path: TRACE_PATH })
},
{ auto: true },
],
Expand All @@ -125,6 +124,11 @@ test.beforeAll(async () => {
})
})

test.beforeEach(async () => {
// start chunk before each test
await context.tracing.startChunk()
})

test.afterAll(async () => {
// temporally disabling this due to the config for parallel testing WIP
// teardownElectron()
Expand Down
117 changes: 58 additions & 59 deletions electron/tests/e2e/thread.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,78 @@
import { expect } from '@playwright/test'
import { page, test, TIMEOUT } from '../config/fixtures'

test('Select User local model from Hub and Chat', async ({ hubPage }) => {
await hubPage.navigateByMenu()
await hubPage.verifyContainerVisible()

// Select the first GPT model
await page
.locator('[data-testid^="use-model-btn"][data-testid*="tinyllama"]')
.first().click()

await page
.getByTestId('txt-input-chat')
.fill('How many r\'s in strawberry?')

// send chat
await page
.getByTestId('btn-send-chat')
.click()
test.describe('Interact with local model', () => {
test('Select USE local model from Hub and Chat', async ({ hubPage }) => {
await hubPage.navigateByMenu()
await hubPage.verifyContainerVisible()

await expect(page.locator('[data-testid^="toaster-"]')).toBeVisible({
timeout: TIMEOUT,
})
// Select the first GPT model
await page
.locator('[data-testid^="use-model-btn"][data-testid*="tinyllama"]')
.first().click()

await hubPage.waitLoadersCompleted()
await page
.getByTestId('txt-input-chat')
.fill('How many r\'s in strawberry?')

await expect(page.getByTestId('btn-stop-chat')).not.toBeVisible({
timeout: TIMEOUT,
})
// send chat
await page
.getByTestId('btn-send-chat')
.click()

await expect(page.getByTestId('error-message')).not.toBeVisible({
timeout: TIMEOUT,
})
await expect(page.locator('[data-testid^="toaster-"]')).toBeVisible({
timeout: TIMEOUT,
})

await expect(page.getByTestId('btn-regenerate-msg')).toBeVisible({ timeout: TIMEOUT })
await hubPage.waitLoadersCompleted()

const text = await page.getByTestId('lbl-token-speed').textContent()
const tokenSpeed = parseFloat(text.match(/\d+(\.\d+)?/)[0])
// Assertion to check if token speed is higher than 3 t/s
expect(tokenSpeed).toBeGreaterThan(3)
await expect(page.getByTestId('btn-stop-chat')).not.toBeVisible({
timeout: TIMEOUT,
})

let apiRequest
await page.route('**/inferences/server/chat_completion', route => {
apiRequest = route.request()
route.continue()
})

await page.getByTestId('btn-regenerate-msg').click()

await page.waitForResponse('**/inferences/server/chat_completion')
await expect(page.getByTestId('error-message')).not.toBeVisible({
timeout: TIMEOUT,
})

await hubPage.waitLoadersCompleted()
await expect(page.getByTestId('btn-regenerate-msg')).toBeVisible({ timeout: TIMEOUT })

await expect(page.getByTestId('error-message')).not.toBeVisible({
timeout: TIMEOUT,
const text = await page.getByTestId('lbl-token-speed').textContent()
const tokenSpeed = parseFloat(text.match(/\d+(\.\d+)?/)[0])
// Assertion to check if token speed is higher than 3 t/s
expect(tokenSpeed).toBeGreaterThan(3)
})

// Verify API request payload
const requestBody = JSON.parse(await apiRequest.postData())
expect(requestBody).toMatchObject({
'engine': 'cortex.llamacpp',
'frequency_penalty': 0,
'max_tokens': 2048,
'presence_penalty': 0,
'stream': true,
'temperature': 0.7,
'top_p': 0.95,
test('Regenerate msg and verify API request ', async ({ hubPage }) => {
let apiRequest
await page.route('**/inferences/server/chat_completion', route => {
apiRequest = route.request()
route.continue()
})

await page.getByTestId('btn-regenerate-msg').click()

await page.waitForResponse('**/inferences/server/chat_completion')

await hubPage.waitLoadersCompleted()

await expect(page.getByTestId('error-message')).not.toBeVisible({
timeout: TIMEOUT,
})

// Verify request contains correct param
const requestBody = JSON.parse(await apiRequest.postData())
expect(requestBody).toMatchObject({
'engine': 'cortex.llamacpp',
'frequency_penalty': 0,
'max_tokens': 2048,
'presence_penalty': 0,
'temperature': 0.6,
'top_p': 0.95,
})
})
})

test('Select Use GPT model from Hub and Chat with Invalid API Key', async ({ hubPage }) => {
test('Select USE GPT model from Hub and Chat with Invalid API Key', async ({ hubPage }) => {
await hubPage.navigateByMenu()
await hubPage.verifyContainerVisible()

Expand Down Expand Up @@ -106,8 +109,4 @@ test('Thread dropdown option should be visible', async () => {
await expect(page.getByTestId('btn-edit-title').first()).toBeVisible()
await expect(page.getByTestId('btn-clean-thread').first()).toBeVisible()
await expect(page.getByTestId('btn-delete-thread').first()).toBeVisible()

// await expect(page.getByTestId('"toaster-"')).toBeVisible({
// timeout: 1,
// })
})

0 comments on commit 6afa083

Please sign in to comment.