From a1d74b5e210623114f84cf805224d90b21f36b99 Mon Sep 17 00:00:00 2001 From: Raphael Koh <72152843+kohrapha@users.noreply.github.com> Date: Fri, 4 Dec 2020 14:43:44 -0500 Subject: [PATCH] Expose transactions per minute via mocked server endpoint (#174) --- mocked_server/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mocked_server/index.js b/mocked_server/index.js index 3be2379ce..ad1f4a191 100644 --- a/mocked_server/index.js +++ b/mocked_server/index.js @@ -6,14 +6,25 @@ const http = require('http'); const fs = require('fs'); const app = express(); -var get_data = "" +let data = ""; +let numTransactions = 0; +const startTime = new Date(); -app.get("/check-data", function(req, res){ - res.send(get_data); +// Retrieve number of transactions per minute +app.get("/tpm", function (req, res) { + // Calculate duration in minutes + const duration = Math.ceil((new Date() - startTime) / 60000); + const tpm = numTransactions / duration; + res.send({ tpm }); +}); + +app.get("/check-data", function (req, res) { + res.send(data); }); app.all('/put-data*', function (req, res) { - get_data = "success"; + data = "success"; + numTransactions++; res.send('{}'); });