diff --git a/load-test-timing.js b/load-test-timing.js index 885e0d5..e275e31 100644 --- a/load-test-timing.js +++ b/load-test-timing.js @@ -1,9 +1,13 @@ const css = ` header { padding-bottom: 20px; text-align: center; } header b { padding-left: 10px; } -table { margin: 0 auto 0 auto; } -th { text-align: left; padding: 10px !important; font-size: 14px !important; border: 1px solid #CCC; } +table { margin-top: 5px; margin-bottom: 20px; width: 100%; } +th { text-align: left; white-space: nowrap; padding: 10px !important; font-size: 14px !important; border: 1px solid #CCC; } td { border: 1px solid #CCC; padding: 5px 5px 5px 10px; } +td.shrink { + white-space: nowrap; + width: 1px; +} footer { padding-top: 20px; text-align: center; }`; const startHtml = ` @@ -14,7 +18,11 @@ const startHtml = ` `; -const startTableHtml = ` +const titleSummaryTableHTML = ` +
SUMMARY
+`; + +const startSummaryTableHtml = ` @@ -22,11 +30,27 @@ const startTableHtml = ` - + `; + +const titleDetailsTableHTML = ` +
DETAILS
`; -const endHtml = ` -
Request# Fails Avg. Time (ms) Total Time (ms)
+const startDetailsTableHtml = ` +
DETAILS + + + + + + + +`; + +const endTable = ` +
#RequestResponseTime (ms)
`; + +const footer = ` @@ -91,8 +115,8 @@ const action = async (context, data) => { const header = `
- # Iterations: [${numIterations}] Delay between requests: [${delayBetweenRequests}ms] Run: - [${runInParallel ? "in Parallel" : "Serially"}] + # Iterations: ${numIterations} Delay between requests: ${delayBetweenRequests}ms Run: + ${runInParallel ? "in Parallel" : "Serially"}
`; try { @@ -104,9 +128,32 @@ const action = async (context, data) => { }; }); + const detailedResults = [] + let iteration = 0 const recorder = (responses, j) => { responses.forEach((response, i) => { const result = results[j || i]; + const detailedResult = {} + + if (runInParallel) { + if (i % requests.length == 0) { + iteration++ + } + } else { + if (j == 0) { + iteration++ + } + } + + detailedResult.iteration = iteration + detailedResult.statusCode = response.statusCode.toString() + detailedResult.status = response.statusMessage + detailedResult.elapsedTime = response.elapsedTime + detailedResult.url = response.url.toString() + detailedResult.name = requests[j || i].name.toString() + + detailedResults.push(detailedResult) + if (response.statusCode.toString().startsWith("2")) { result.successes++; result.total += response.elapsedTime; @@ -169,9 +216,12 @@ const action = async (context, data) => { }); }; + const startTime = performance.now(); await execute(); + const endTime = performance.now(); + const totalTimeElapsed = endTime - startTime - const rows = []; + const summaryRows = []; results.forEach((r, i) => { const request = requests[i]; @@ -186,20 +236,75 @@ const action = async (context, data) => { color = "red"; } - rows.push( + summaryRows.push( + ` + ${request.name || request.url} + ${result.successes} + ${result.fails} + ${avg.toFixed(1)} + ${result.total.toFixed(1)} + `, + ); + }); + + const timeElapsedTable = + ` + + + + +
Total load test duration${totalTimeElapsed.toFixed(2)} ms
` + ; + + const detailedRows = []; + let tableIteration = 0; + + detailedResults.forEach((result, i) => { + + let color; + + const responseType = result.statusCode.charAt(0) + + switch (responseType) { + case "2": + color = "limegreen"; + break; + case "3": + case "4": + color = "orange"; + break; + case "5": + color = "red"; + break; + } + + if (tableIteration < result.iteration) { + tableIteration = result.iteration; + + if (tableIteration > 1) { + detailedRows.push(` + `, + ); + } + detailedRows.push(` + Iteration ${tableIteration.toString()} + `, + ); + }; + + detailedRows.push( ` - - - - - - `, + + + + + `, ); }); - const html = startHtml + header + startTableHtml + rows.join("") + endHtml; + const html = startHtml + header + titleSummaryTableHTML + startSummaryTableHtml + summaryRows.join("") + endTable + timeElapsedTable + titleDetailsTableHTML + detailedRows.join("") + endTable + footer; progressModal.innerHTML = html; - context.app.dialog("Results Table", progressModal, { + context.app.dialog("Results", progressModal, { tall: true, });
${request.name || request.url}${result.successes}${result.fails}${avg.toFixed(1)}${result.total.toFixed(2)}
${i + 1}${result.name || result.url}${result.statusCode} ${result.status}${result.elapsedTime.toFixed(1)} ms