Skip to content

Commit 52120c0

Browse files
author
rhamlett_microsoft
committed
More load test fixes
1 parent 0d20dc0 commit 52120c0

File tree

1 file changed

+26
-72
lines changed

1 file changed

+26
-72
lines changed

src/PerfProblemSimulator/Controllers/LoadTestController.cs

Lines changed: 26 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ public LoadTestController(
148148
/// <summary>
149149
/// Executes a load test probe request that performs lightweight work.
150150
/// </summary>
151-
/// <param name="workIterations">Number of SHA256 hash iterations (default: 1000).</param>
152-
/// <param name="bufferSizeKb">Memory buffer size in KB (default: 100).</param>
153-
/// <param name="baselineDelayMs">Minimum blocking delay in ms (default: 500).</param>
154-
/// <param name="softLimit">Concurrent request soft limit (default: 5).</param>
155-
/// <param name="degradationFactor">Delay ms per request over limit (default: 200).</param>
151+
/// <param name="request">Load test parameters as JSON body.</param>
156152
/// <param name="cancellationToken">Cancellation token from the HTTP request pipeline.</param>
157153
/// <returns>Load test result with timing and diagnostic information.</returns>
158154
/// <remarks>
@@ -213,87 +209,36 @@ public LoadTestController(
213209
/// <response code="200">Load test completed successfully with timing details.</response>
214210
/// <response code="500">Request exceeded 120s and random exception was triggered.</response>
215211
[HttpPost]
216-
[HttpGet]
217212
[ProducesResponseType(typeof(LoadTestResult), StatusCodes.Status200OK)]
218213
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status500InternalServerError)]
219214
public async Task<IActionResult> ExecuteLoadTest(
220-
[FromQuery] int workIterations = 1000,
221-
[FromQuery] int bufferSizeKb = 100,
222-
[FromQuery] int baselineDelayMs = 500,
223-
[FromQuery] int softLimit = 5,
224-
[FromQuery] int degradationFactor = 200,
215+
[FromBody] LoadTestRequest request,
225216
CancellationToken cancellationToken = default)
226217
{
227218
/*
228219
* =====================================================================
229-
* REQUEST HANDLING FLOW
220+
* JSON BODY ENDPOINT
230221
* =====================================================================
231222
*
232-
* This endpoint now accepts query parameters for maximum compatibility
233-
* with Azure Load Testing, JMeter, and browser testing.
234-
*
235-
* Examples:
236-
* - GET/POST /api/loadtest (uses all defaults - maximum stress)
237-
* - GET/POST /api/loadtest?baselineDelayMs=200&softLimit=20&degradationFactor=50
238-
*
239-
* PORTING NOTES:
240-
* - Query parameters are universal across HTTP clients
241-
* - No Content-Type header required
242-
* - Works with any load testing tool
223+
* POST /api/loadtest with JSON body:
224+
* {
225+
* "workIterations": 5000,
226+
* "bufferSizeKb": 1000,
227+
* "baselineDelayMs": 500,
228+
* "softLimit": 5,
229+
* "degradationFactor": 200
230+
* }
243231
*/
244232

245-
// Build request from query parameters
246-
var request = new LoadTestRequest
247-
{
248-
WorkIterations = workIterations,
249-
BufferSizeKb = bufferSizeKb,
250-
BaselineDelayMs = baselineDelayMs,
251-
SoftLimit = softLimit,
252-
DegradationFactor = degradationFactor
253-
};
254-
255233
_logger.LogDebug(
256-
"Load test request received: WorkIterations={WorkIterations}, BufferSizeKb={BufferSizeKb}, SoftLimit={SoftLimit}",
234+
"Load test: WorkIterations={WorkIterations}, BufferSizeKb={BufferSizeKb}, BaselineDelayMs={BaselineDelayMs}, SoftLimit={SoftLimit}, DegradationFactor={DegradationFactor}",
257235
request.WorkIterations,
258236
request.BufferSizeKb,
259-
request.SoftLimit);
237+
request.BaselineDelayMs,
238+
request.SoftLimit,
239+
request.DegradationFactor);
260240

261-
/*
262-
* =====================================================================
263-
* SERVICE DELEGATION
264-
* =====================================================================
265-
*
266-
* WHY SEPARATE SERVICE:
267-
* - Controller handles HTTP concerns (routing, request/response)
268-
* - Service handles business logic (the actual algorithm)
269-
* - This separation makes the logic testable and reusable
270-
*
271-
* ASYNC/AWAIT:
272-
* The "await" keyword suspends this method until the service completes.
273-
* This does NOT block a thread - the thread returns to the pool.
274-
*
275-
* PORTING:
276-
* - Node.js: const result = await loadTestService.executeWork(...)
277-
* - Python: result = await load_test_service.execute_work(...)
278-
* - Java: Result result = loadTestService.executeWork(...).get()
279-
* - PHP: $result = $loadTestService->executeWork(...) (sync or with ReactPHP)
280-
*/
281241
var result = await _loadTestService.ExecuteWorkAsync(request, cancellationToken);
282-
283-
/*
284-
* =====================================================================
285-
* RESPONSE FORMATTING
286-
* =====================================================================
287-
*
288-
* Ok(result) returns HTTP 200 with JSON body
289-
* The framework automatically serializes the result object to JSON
290-
*
291-
* PORTING:
292-
* - Node.js: res.json(result) or return result (Fastify)
293-
* - Python: return result (FastAPI auto-serializes)
294-
* - Java: return ResponseEntity.ok(result)
295-
* - PHP: return response()->json($result)
296-
*/
297242
return Ok(result);
298243
}
299244

@@ -342,8 +287,17 @@ public async Task<IActionResult> ExecuteLoadTestProbe(
342287
* - PHP: $request->query('workIterations', 1000)
343288
*/
344289

345-
// Delegate to main endpoint - both now use query parameters
346-
return await ExecuteLoadTest(workIterations, bufferSizeKb, baselineDelayMs, softLimit, degradationFactor, cancellationToken);
290+
var request = new LoadTestRequest
291+
{
292+
WorkIterations = workIterations,
293+
BufferSizeKb = bufferSizeKb,
294+
BaselineDelayMs = baselineDelayMs,
295+
SoftLimit = softLimit,
296+
DegradationFactor = degradationFactor
297+
};
298+
299+
var result = await _loadTestService.ExecuteWorkAsync(request, cancellationToken);
300+
return Ok(result);
347301
}
348302

349303
/*

0 commit comments

Comments
 (0)