The Mock Logic Controller (MLC) is a high-performance, lightweight Node.js middleware specifically engineered for performance testing tasks. It functions as a dynamic "Data and Fault Injection" hub to simulate external dependencies during load tests.
- Zero-Bottleneck Architecture: Built on a non-blocking event loop to handle high-concurrency traffic.
-
Low Memory Footprint: Uses in-memory Map lookups (
$O(1)$ complexity) for instant response matching. -
Persistent Configuration: Automatically saves all mocks to
mocks.json, ensuring your configurations survive server restarts. - Real-Time Agility: Allows adding, cloning, or editing mocks without server restarts, preventing test downtime.
Understanding the internal logic is vital for debugging during a performance run:
The server utilizes an auto-save mechanism. Every time a mock is added, edited, or removed, the saveToDisk() function updates mocks.json. Upon startup, loadFromDisk() restores your entire test suite.
mock.currentIndex = (mock.currentIndex + 1) % mock.csvData.length;
This logic uses the Modulo operator to ensure a continuous data loop. If headers in your CSV match keys in your Response JSON, the engine injects that row's data into the response.
The engine calculates a unique delay for every request to mimic "network noise":
Ensure your directory is organized as follows:
/your-folderserver.js(The Engine)package.json(Project Manifest)mocks.json(Auto-generated backup)key.pem&cert.pem(SSL Certificates)/public/index.html(The Dashboard)/data(Your uploaded CSV files)
Open your terminal in the project folder and run this to generate self-signed certificates for HTTPS:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes -subj "/CN=localhost"- Install requirements: Run
npm install express express-fileupload csv-parseto ensure all middleware is available. - Start server: Execute
node server.jsor usenpx nodemon server.jsfor development mode. - Open Dashboard: Navigate to
http://localhost:3000in your browser.
Use these commands to validate your mock configuration, data cycling, and payload capture.
Run this command multiple times to verify that the response data cycles through your test.csv rows in a loop:
curl -i -k -X GET "https://localhost:3443/api/v1/validate-cycle"| Issue | Probable Cause | Fix / Solution |
|---|---|---|
| "Insecure" Error | Browser does not trust the self-signed certificates. | Click "Advanced" -> "Proceed" or use -k in your curl commands. |
| CSV Not Loading | The path is incorrect or the folder is missing. | Ensure the path starts with data/ and the file is in the correct folder. |
| High Latency | Mac CPU is throttled or in "Low Power Mode." | Plug in your Mac; Node.js needs CPU cycles for accurate jitter math. |
| Mock 404 Error | Case sensitivity or trailing slashes in the URL. | Ensure the UI registration path exactly matches your request URL. |
- UI Dashboard: http://localhost:3000.List
- System Health: http://localhost:3000/_admin/health — Built-in check to validate connectivity.
- Active Mocks: GET http://localhost:3000/_admin/list.Secure
- Mock Endpoint: https://localhost:3443/[your-path].