-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: [BE] transaction 적용 및 에러 fix #182
[BE] feature : transaction 적용 및 에러 fix
- Loading branch information
Showing
17 changed files
with
355 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
/.env | ||
/.prod.env | ||
/.test.env | ||
|
||
/*.env | ||
LoadTestDocs | ||
# Logs | ||
logs | ||
*.log | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
backEnd/api/src/common/decorator/typeormTransactional.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getNamespace } from 'cls-hooked'; | ||
export const typeormTransactional = () => { | ||
return (target: any, key: string, descriptor: PropertyDescriptor) => { | ||
const nameSpace = getNamespace('namespace'); | ||
nameSpace.set(); | ||
// console.log("target instance:", target); | ||
|
||
const originalMethod = descriptor.value; | ||
descriptor.value = async function (...args: any[]) { | ||
// 비동기 작업을 수행하거나 비동기 함수를 호출할 수 있습니다. | ||
const [res, req] = args; | ||
if (!req.authorized) return res.redirect('/user/login'); | ||
// console.log(originalMethod) | ||
await originalMethod.apply(this, args); | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const { io } = require('socket.io-client'); | ||
|
||
const DURATION = 120 * 1000; // 120초 | ||
const MAX_CLIENTS = 100; | ||
const ERROR_RATE = 0.1; | ||
let total_request = 0; | ||
let errorCount = 0; | ||
let clientCount = 0; | ||
let concurrentClients = 10; | ||
const 소요시간 = []; | ||
|
||
const URL = 'ws://localhost:4000/run'; | ||
const data = { | ||
code: 'console.log("Hello World")', | ||
language: 'javascript', | ||
}; | ||
|
||
const printResult = () => { | ||
console.log('총 요청개수 : ', total_request); | ||
console.log('성공한 요청 개수 : ', 소요시간.length); | ||
console.log( | ||
'평균 소요 시간 : ', | ||
소요시간.reduce((p, c) => p + c, 0) / 소요시간.length, | ||
); | ||
console.log('최대 동시 요청 수 : ', concurrentClients - 10); | ||
}; | ||
|
||
const createSingleClient = () => { | ||
// for demonstration purposes, some clients stay stuck in HTTP long-polling | ||
const start = Date.now(); | ||
const socket = io(URL, { | ||
transport: ['websocket'], | ||
}); | ||
|
||
let doneEventReceived = false; | ||
// Set a timeout of 6 seconds | ||
const timeId = setTimeout(() => { | ||
if (!doneEventReceived) { | ||
errorCount++; | ||
// console.log('Timeout: done event not received within 6 seconds.'); | ||
socket.disconnect(); | ||
} | ||
}, 6000); | ||
|
||
socket.on('connect', () => { | ||
// console.log('소켓이 연결되었습니다.'); | ||
socket.emit('request', data); | ||
}); | ||
|
||
socket.on('done', (data) => { | ||
// console.log(data); // 코드 실행 결과 | ||
doneEventReceived = true; | ||
clearTimeout(timeId); | ||
소요시간.push(Date.now() - start); | ||
socket.disconnect(); | ||
}); | ||
}; | ||
|
||
const createClient = () => { | ||
if (clientCount >= MAX_CLIENTS) { | ||
setTimeout(() => { | ||
console.log('Test Success'); | ||
printResult(); | ||
process.exit(1); | ||
}, 6000); | ||
} | ||
if (total_request * ERROR_RATE < errorCount) { | ||
setTimeout(() => { | ||
console.log('Test Done By error'); | ||
printResult(); | ||
process.exit(1); | ||
}, 6000); | ||
} | ||
|
||
console.log(`Create ${concurrentClients} VUs`); | ||
Array.from({ length: concurrentClients }, (v, i) => i).forEach(() => { | ||
createSingleClient(); | ||
}); | ||
|
||
total_request += concurrentClients; | ||
concurrentClients += 10; // 동시 실행 횟수를 10씩 증가 | ||
clientCount++; | ||
|
||
setTimeout(createClient, 3000); // 1초 뒤에 다음 그룹의 클라이언트 생성 시작 | ||
}; | ||
|
||
createClient(); | ||
|
||
setTimeout(() => { | ||
console.log('duration done'); | ||
printResult(); | ||
process.exit(1); // Exit the process with an error code (1) | ||
}, DURATION); // Set the timeout to 60 seconds |
Oops, something went wrong.