From 68f4d92eb49bc1b99f85035687c2c648fd515446 Mon Sep 17 00:00:00 2001 From: kclark Date: Mon, 12 Feb 2024 16:22:08 +0000 Subject: [PATCH 1/9] Initial dummy endpoint skeleton and attempted changes to smoke test --- backend/src/controller/testController.ts | 7 +++++++ backend/src/sessionRoutes.ts | 4 ++++ k6/smoke.js | 12 ++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 backend/src/controller/testController.ts diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts new file mode 100644 index 000000000..02617d33f --- /dev/null +++ b/backend/src/controller/testController.ts @@ -0,0 +1,7 @@ +import { Response } from 'express'; + +function handleTest(_req: unknown, res: Response) { + res.send('Simple Test Json'); +} + +export { handleTest }; \ No newline at end of file diff --git a/backend/src/sessionRoutes.ts b/backend/src/sessionRoutes.ts index e33f01761..f83d08473 100644 --- a/backend/src/sessionRoutes.ts +++ b/backend/src/sessionRoutes.ts @@ -29,6 +29,7 @@ import { import { handleResetProgress } from './controller/resetController'; import { ChatModel, defaultChatModel } from './models/chat'; import { LevelState, getInitialLevelStates } from './models/level'; +import { handleTest } from './controller/testController'; declare module 'express-session' { interface Session { @@ -130,4 +131,7 @@ if (isProd) { }); } +// Testing dummy endpoint +router.get('/test/load', handleTest); + export default router; diff --git a/k6/smoke.js b/k6/smoke.js index 3a7f63042..c191d5b04 100644 --- a/k6/smoke.js +++ b/k6/smoke.js @@ -3,16 +3,20 @@ import { check, sleep } from 'k6'; export const options = { vus: 3, // Key for Smoke test. Keep it at 2, 3, max 5 VUs - duration: '1m', // This can be shorter or just a few iterations + // duration: '1m', // This can be shorter or just a few iterations + iterations: 3 }; export default () => { - const data = { message: "hi", currentLevel: '3' }; - const url = 'http://localhost:3001/openai/chat'; + // const data = { message: "hi", currentLevel: '3' }; + const url = 'http://localhost:3001/test/load'; - let response = http.post(url, JSON.stringify(data), { + let response = http.get(url, { headers: { 'Content-Type': 'application/json' }, }); + // let response = http.post(url, JSON.stringify(data), { + // headers: { 'Content-Type': 'application/json' }, + // }); check(response, { 'response code was 200': (response) => response.status === 200, }); From ebb966d2d12f2f2609aae37fc16dc50c8571bfed Mon Sep 17 00:00:00 2001 From: kclark Date: Mon, 12 Feb 2024 16:41:33 +0000 Subject: [PATCH 2/9] linting --- backend/src/controller/testController.ts | 2 +- backend/src/sessionRoutes.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index 02617d33f..4901ebe0c 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -4,4 +4,4 @@ function handleTest(_req: unknown, res: Response) { res.send('Simple Test Json'); } -export { handleTest }; \ No newline at end of file +export { handleTest }; diff --git a/backend/src/sessionRoutes.ts b/backend/src/sessionRoutes.ts index f83d08473..c89d31c8f 100644 --- a/backend/src/sessionRoutes.ts +++ b/backend/src/sessionRoutes.ts @@ -27,9 +27,9 @@ import { handleSetModel, } from './controller/modelController'; import { handleResetProgress } from './controller/resetController'; +import { handleTest } from './controller/testController'; import { ChatModel, defaultChatModel } from './models/chat'; import { LevelState, getInitialLevelStates } from './models/level'; -import { handleTest } from './controller/testController'; declare module 'express-session' { interface Session { From 6ff963d0082831a6de2f8e989523e393d9454ab3 Mon Sep 17 00:00:00 2001 From: kclark Date: Mon, 12 Feb 2024 17:02:23 +0000 Subject: [PATCH 3/9] Changing to post and attempting to have data sent up to endpoint to try attempt to get 200 back --- backend/src/controller/testController.ts | 15 +++++++++++++-- backend/src/sessionRoutes.ts | 2 +- k6/smoke.js | 7 ++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index 4901ebe0c..f57a09f2f 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -1,7 +1,18 @@ import { Response } from 'express'; +import { OpenAiChatRequest } from '@src/models/api/OpenAiChatRequest'; -function handleTest(_req: unknown, res: Response) { - res.send('Simple Test Json'); +function handleTest(req: OpenAiChatRequest, res: Response) { + const { message, currentLevel } = req.body; + + if (!message || currentLevel === undefined) { + console.log('Missing or empty message or level'); + res.status(400); + return; + } + else{ + res.send(200); + } + } export { handleTest }; diff --git a/backend/src/sessionRoutes.ts b/backend/src/sessionRoutes.ts index c89d31c8f..d9a19660e 100644 --- a/backend/src/sessionRoutes.ts +++ b/backend/src/sessionRoutes.ts @@ -132,6 +132,6 @@ if (isProd) { } // Testing dummy endpoint -router.get('/test/load', handleTest); +router.post('/test/load', handleTest); export default router; diff --git a/k6/smoke.js b/k6/smoke.js index c191d5b04..0047df6d6 100644 --- a/k6/smoke.js +++ b/k6/smoke.js @@ -8,15 +8,12 @@ export const options = { }; export default () => { - // const data = { message: "hi", currentLevel: '3' }; + const data = { message: "hi", currentLevel: '3' }; const url = 'http://localhost:3001/test/load'; - let response = http.get(url, { + let response = http.post(url, JSON.stringify(data), { headers: { 'Content-Type': 'application/json' }, }); - // let response = http.post(url, JSON.stringify(data), { - // headers: { 'Content-Type': 'application/json' }, - // }); check(response, { 'response code was 200': (response) => response.status === 200, }); From 0c8eab82a5b95173b8351a27a4235f267d03b18f Mon Sep 17 00:00:00 2001 From: kclark Date: Mon, 12 Feb 2024 17:03:00 +0000 Subject: [PATCH 4/9] linting --- backend/src/controller/testController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index f57a09f2f..df46fbaed 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -1,4 +1,5 @@ import { Response } from 'express'; + import { OpenAiChatRequest } from '@src/models/api/OpenAiChatRequest'; function handleTest(req: OpenAiChatRequest, res: Response) { From 4e41b164a37b24d27bb8d03479bdc9f084a37f45 Mon Sep 17 00:00:00 2001 From: kclark Date: Tue, 13 Feb 2024 09:48:47 +0000 Subject: [PATCH 5/9] it works? changes --- backend/src/controller/testController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index df46fbaed..1490b6b40 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -7,13 +7,13 @@ function handleTest(req: OpenAiChatRequest, res: Response) { if (!message || currentLevel === undefined) { console.log('Missing or empty message or level'); - res.status(400); + res.send(400); return; } else{ + console.log('Dummy test endpoint'); res.send(200); } - -} +} export { handleTest }; From 78d67d6f9d4bcd93426fcafdac5108f292cc1103 Mon Sep 17 00:00:00 2001 From: kclark Date: Tue, 13 Feb 2024 10:08:48 +0000 Subject: [PATCH 6/9] linting/formatting --- backend/src/controller/testController.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index 1490b6b40..1e5120b60 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -3,17 +3,15 @@ import { Response } from 'express'; import { OpenAiChatRequest } from '@src/models/api/OpenAiChatRequest'; function handleTest(req: OpenAiChatRequest, res: Response) { - const { message, currentLevel } = req.body; + const { message, currentLevel } = req.body; - if (!message || currentLevel === undefined) { + if (!message || currentLevel === undefined) { console.log('Missing or empty message or level'); - res.send(400); + res.send(400); return; + } else { + console.log('Dummy test endpoint'); + res.send(200); } - else{ - console.log('Dummy test endpoint'); - res.send(200); - } - } export { handleTest }; From b86f029c8d7cdb7274c7ba26f23137dd9acac102 Mon Sep 17 00:00:00 2001 From: kclark Date: Tue, 13 Feb 2024 11:04:38 +0000 Subject: [PATCH 7/9] Creating more realistic controller that doesn't just immediatley send response codes back and uses some memory --- backend/src/controller/testController.ts | 21 +++++++++------------ k6/smoke.js | 7 ++++--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index 1e5120b60..ede00e9cf 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -1,17 +1,14 @@ import { Response } from 'express'; -import { OpenAiChatRequest } from '@src/models/api/OpenAiChatRequest'; +import { handleAddInfoToChatHistory } from '@src/controller/chatController'; +import { OpenAiAddInfoToChatHistoryRequest } from '@src/models/api/OpenAiAddInfoToChatHistoryRequest'; -function handleTest(req: OpenAiChatRequest, res: Response) { - const { message, currentLevel } = req.body; - - if (!message || currentLevel === undefined) { - console.log('Missing or empty message or level'); - res.send(400); - return; - } else { - console.log('Dummy test endpoint'); - res.send(200); - } +function handleTest(req: OpenAiAddInfoToChatHistoryRequest, res: Response) { + let num = 0 + for(let x=0; x<= 1000000; x++) + { + num++; + } + handleAddInfoToChatHistory(req, res); } export { handleTest }; diff --git a/k6/smoke.js b/k6/smoke.js index 0047df6d6..f334467b7 100644 --- a/k6/smoke.js +++ b/k6/smoke.js @@ -1,21 +1,22 @@ import http from 'k6/http'; +// import exec from 'k6/execution'; import { check, sleep } from 'k6'; export const options = { vus: 3, // Key for Smoke test. Keep it at 2, 3, max 5 VUs - // duration: '1m', // This can be shorter or just a few iterations - iterations: 3 + duration: '10s', // This can be shorter or just a few iterations }; export default () => { const data = { message: "hi", currentLevel: '3' }; const url = 'http://localhost:3001/test/load'; + // console.log('VU ID:' + exec.vu.idInTest); let response = http.post(url, JSON.stringify(data), { headers: { 'Content-Type': 'application/json' }, }); check(response, { 'response code was 200': (response) => response.status === 200, }); - sleep(1); + sleep(0.1); }; From ae12363774726c2266a36f4dbe6bc792e3473080 Mon Sep 17 00:00:00 2001 From: kclark Date: Tue, 13 Feb 2024 11:10:40 +0000 Subject: [PATCH 8/9] linting unused var --- backend/src/controller/testController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index ede00e9cf..4a97d0d5a 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -7,7 +7,7 @@ function handleTest(req: OpenAiAddInfoToChatHistoryRequest, res: Response) { let num = 0 for(let x=0; x<= 1000000; x++) { - num++; + num = num++; } handleAddInfoToChatHistory(req, res); } From b47cd74b311e9e0c0fc98909b6244fb5acb2ca77 Mon Sep 17 00:00:00 2001 From: kclark Date: Tue, 13 Feb 2024 11:12:14 +0000 Subject: [PATCH 9/9] formatting --- backend/src/controller/testController.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/src/controller/testController.ts b/backend/src/controller/testController.ts index 4a97d0d5a..3d132a7aa 100644 --- a/backend/src/controller/testController.ts +++ b/backend/src/controller/testController.ts @@ -4,11 +4,10 @@ import { handleAddInfoToChatHistory } from '@src/controller/chatController'; import { OpenAiAddInfoToChatHistoryRequest } from '@src/models/api/OpenAiAddInfoToChatHistoryRequest'; function handleTest(req: OpenAiAddInfoToChatHistoryRequest, res: Response) { - let num = 0 - for(let x=0; x<= 1000000; x++) - { - num = num++; - } - handleAddInfoToChatHistory(req, res); + let num = 0; + for (let x = 0; x <= 1000000; x++) { + num = num++; + } + handleAddInfoToChatHistory(req, res); } export { handleTest };