From e3ec7ea0c62a29bf7e45b12569a10359c0d544d1 Mon Sep 17 00:00:00 2001 From: Chakradhar Date: Fri, 1 Sep 2023 02:32:34 +0530 Subject: [PATCH] load testing script initial phase --- Cargo.lock | 60 ++ crates/load_test/Cargo.toml | 26 + .../__pycache__/locustfile.cpython-311.pyc | Bin 0 -> 9832 bytes .../load_test/generateconfig/generatetoken.js | 77 ++ .../generateconfig/output/driver_token.json | 15 + .../generateconfig/output/rider_token.json | 4 + .../generateconfig/package-lock.json | 780 ++++++++++++++++++ crates/load_test/generateconfig/package.json | 21 + crates/load_test/locustfile.py | 205 +++++ crates/load_test/new.rs | 1 + crates/load_test/src/lib.rs | 1 + crates/load_test/src/main.rs | 452 ++++++++++ 12 files changed, 1642 insertions(+) create mode 100644 crates/load_test/Cargo.toml create mode 100644 crates/load_test/__pycache__/locustfile.cpython-311.pyc create mode 100644 crates/load_test/generateconfig/generatetoken.js create mode 100644 crates/load_test/generateconfig/output/driver_token.json create mode 100644 crates/load_test/generateconfig/output/rider_token.json create mode 100644 crates/load_test/generateconfig/package-lock.json create mode 100644 crates/load_test/generateconfig/package.json create mode 100644 crates/load_test/locustfile.py create mode 100644 crates/load_test/new.rs create mode 100644 crates/load_test/src/lib.rs create mode 100644 crates/load_test/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 4bddd81..a6d1303 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -495,6 +495,12 @@ dependencies = [ "bytes", ] +[[package]] +name = "cargo-test" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "980e69396f61ebd8a2af764ca60d3a154761092d91f42e2f0498188f29b6b701" + [[package]] name = "cc" version = "1.0.83" @@ -536,6 +542,16 @@ dependencies = [ "cc", ] +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -712,6 +728,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "earcutr" version = "0.4.2" @@ -1387,6 +1409,23 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +[[package]] +name = "load_test" +version = "0.1.0" +dependencies = [ + "actix-web", + "cargo-test", + "chrono", + "dotenv", + "fred", + "rand", + "redis", + "reqwest", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "local-channel" version = "0.1.3" @@ -1946,6 +1985,21 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "redis" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffd6543a7bc6428396845f6854ccf3d1ae8823816592e2cbe74f20f50f209d02" +dependencies = [ + "combine", + "itoa", + "percent-encoding", + "ryu", + "sha1_smol", + "socket2 0.4.9", + "url", +] + [[package]] name = "redis-protocol" version = "4.1.0" @@ -2243,6 +2297,12 @@ dependencies = [ "digest", ] +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + [[package]] name = "sha2" version = "0.10.7" diff --git a/crates/load_test/Cargo.toml b/crates/load_test/Cargo.toml new file mode 100644 index 0000000..423de9e --- /dev/null +++ b/crates/load_test/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "load_test" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[[bin]] +path = "src/main.rs" +name = "load_test" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = {version = "1.28.2", features = ["macros", "rt-multi-thread"]} +dotenv = "0.15.0" +redis = {version = "0.23.0"} +cargo-test = "0.3.1" +actix-web = "4.3.1" +reqwest = {version = "0.11.18", features = ["json"]} +serde = {version ="1.0.171", features = ["derive"]} +fred = { version = "6.0.0", features = ["metrics", "partial-tracing"] } +serde_json = "1.0.100" +rand = "0.8.5" +chrono = {version = "0.4.26", features = ["serde"]} \ No newline at end of file diff --git a/crates/load_test/__pycache__/locustfile.cpython-311.pyc b/crates/load_test/__pycache__/locustfile.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f5358d8326cf1208894215e94a1b34d30547b964 GIT binary patch literal 9832 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 c= 2.1.2 < 3" + } + }, + "ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==" + }, + "is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==" + }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + }, + "nodemon": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz", + "integrity": "sha512-g9AZ7HmkhQkqXkRc20w+ZfQ73cHLbE8hnPbtaFbFtCumZsjyMhKk9LajQ07U5Ux28lvFjZ5X7HvWR1xzU8jHVw==", + "requires": { + "chokidar": "^3.5.2", + "debug": "^3.2.7", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", + "requires": { + "abbrev": "1" + } + }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" + }, + "object-inspect": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" + }, + "on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" + }, + "proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "requires": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + } + }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "requires": { + "side-channel": "^1.0.4" + } + }, + "range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" + }, + "raw-body": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "requires": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + } + }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "requires": { + "picomatch": "^2.2.1" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "requires": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "requires": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.18.0" + } + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, + "simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "requires": { + "semver": "^7.5.3" + } + }, + "statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + } + }, + "toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" + }, + "touch": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", + "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", + "requires": { + "nopt": "~1.0.10" + } + }, + "type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + } + }, + "undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } +} diff --git a/crates/load_test/generateconfig/package.json b/crates/load_test/generateconfig/package.json new file mode 100644 index 0000000..0a7e235 --- /dev/null +++ b/crates/load_test/generateconfig/package.json @@ -0,0 +1,21 @@ +{ + "name": "generate-config", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js", + "start-dev": "nodemon index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "axios": "^1.4.0", + "body-parser": "^1.20.2", + "cors": "^2.8.5", + "express": "^4.18.2", + "nodemon": "^3.0.1" + } +} diff --git a/crates/load_test/locustfile.py b/crates/load_test/locustfile.py new file mode 100644 index 0000000..28f2921 --- /dev/null +++ b/crates/load_test/locustfile.py @@ -0,0 +1,205 @@ +from locust import HttpUser, task, between +import random +import datetime +import random +import json + + +class LocationUpdate(HttpUser): + def on_start(self): + self.token = [ + "89865ef5-da51-4c1b-b383-862e57504a0e", + "75ba0a82-f750-4539-b067-d5c79fba4dad", + "7c722062-95a7-40f2-8edd-01e71b1c4122", + "c5c668f9-f127-4a86-b115-594e52b6829a", + "acbcdde0-ec76-4593-bf25-86c58638ea8d", + "1d653a3b-bde3-4fdd-96ff-a748c9e210bd", + "f9270164-5e20-4c44-b563-d062a02c80df", + "7009c594-1c5c-4d22-8071-0fdea8fd2b75", + "7f160752-8070-4fca-adc1-4735069b6812", + "576d20d6-896f-4719-ac7f-8dd5fe1e606b", + "e583da16-d331-4bd3-b8d6-a6f3bc5bb8bf", + "122bf13f-e873-40fa-84d1-c0a4cac1f854", + "77f05c66-5712-4e06-9bce-56420ae69557" + ] + self.mId = "favorit0-0000-0000-0000-00000favorit" + self.vt = "SUV" + @task + def location_updates(self): + + + current_utc_time = datetime.datetime.utcnow() + + formatted_utc_time = current_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') + + token = random.choice(self.token) + print(token) + + headers = { + "Content-Type": "application/json", + "token": token, + "mId": self.mId, + "vt": self.vt + } + + locationData =[{ + "pt": { + "lat": random.uniform(13.0, 16.5), + "lon": random.uniform(75.0, 76.5) + }, + "ts": "2023-08-29T08:34:27Z", + "acc": 1 + }] + + print(locationData, "location data") + + with self.client.post(url = "/driver/location", json=locationData, headers=headers) as response: + print(response.json(), "location results") + + +class RideSearch(HttpUser): + wait_time = between(1,2) + + def on_start(self): + self.token = "c892e9cb-0a02-4966-8f2b-8a27bcbd972f" + + @task + def ride_search(self): + ride_data = { + "fareProductType": "ONE_WAY", + "contents": { + "origin": { + "address": { + "area": "8th Block Koramangala", + "areaCode": "560047", + "building": "Juspay Buildings", + "city": "Bangalore", + "country": "India", + "door": "#444", + "street": "18th Main", + "state": "Karnataka" + }, + "gps": { + "lat": 16.479615647756166, + "lon": 75.39032459232 + } + }, + "destination": { + "address": { + "area": "6th Block Koramangala", + "areaCode": "560047", + "building": "Juspay Apartments", + "city": "Bangalore", + "country": "India", + "door": "#444", + "street": "18th Main", + "state": "Karnataka" + }, + "gps": { + "lat": 16.42990908333854, + "lon": 75.36080308508846 + } + } + } + } + + headers = { + "Content-Type": "application/json", + "token": self.token, + } + + with self.client.post(url = "/rideSearch", json=ride_data, headers=headers) as response: + print(response.json(), "ride search") + +class RideSearchResults(HttpUser): + wait_time = between(1,2) + + def on_start(self): + self.token = "00ade58d-c526-43f5-9ce4-1f538388b526" + self.searchId = "7d6c2b0a-d6f8-4913-86fb-7202c48e2a99" + + @task + def ride_search_results(self): + + headers = { + "Content-Type": "application/json", + "token": self.token, + } + + with self.client.get(url = "/rideSearch/{searchId}/results".format(searchId = self.searchId), headers=headers) as response: + + # search_id = response.json().get("searchId", None) + print(response.json(), "ride search results") + + +class EstimateSelect(HttpUser): + wait_time = between(1,2) + + def on_start(self): + self.token = "00ade58d-c526-43f5-9ce4-1f538388b526" + self.estimateId = "69f585bd-7f58-44a5-ac98-ae9301822e0d" + + @task + def estimate_select(self): + headers = { + "Content-Type": "application/json", + "token": self.token, + } + + estimateData = { + "customerExtraFee": None, + "autoAssignEnabledV2": True, + "autoAssignEnabled": True + } + + with self.client.post(url = "/estimate/{estimateId}/select2".format(estimateId = self.estimateId), json=estimateData, headers=headers) as response: + print(response.json(), "estimate select results") + +class QuoteConfirm(HttpUser): + wait_time = between(1,2) + + def on_start(self): + self.token = "00ade58d-c526-43f5-9ce4-1f538388b526" + self.searchReqId = "bee5eb3f-2be8-4936-ac82-ced05b2bfe55" + + @task + def quote_confirm(self): + headers = { + "Content-Type": "application/json", + "token": self.token, + } + + quoteData = { + "searchRequestId": self.searchReqId, + "offeredFare" : 10 + } + + with self.client.post(url = "/driver/searchRequest/quote/offer", json=quoteData, headers=headers) as response: + print(response.json(), "quote results") + + +class StartRide(HttpUser): + wait_time = between(1,2) + + def on_start(self): + self.token = "00ade58d-c526-43f5-9ce4-1f538388b526" + self.rideId = "bee5eb3f-2be8-4936-ac82-ced05b2bfe55" + self.rideOtp = "" + + @task + def start_ride(self): + headers = { + "Content-Type": "application/json", + "token": self.token, + } + + rideData = { + "rideOtp": self.rideOtp, + "point": { + "lat": "12.9783131063211", + "lon": "77.595122819161" + } + } + + with self.client.post(url = "/driver/ride/{rideId}/start".format(rideId = self.rideId), json=rideData, headers=headers) as response: + print(response.json(), "quote results") \ No newline at end of file diff --git a/crates/load_test/new.rs b/crates/load_test/new.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/crates/load_test/new.rs @@ -0,0 +1 @@ + diff --git a/crates/load_test/src/lib.rs b/crates/load_test/src/lib.rs new file mode 100644 index 0000000..f94d535 --- /dev/null +++ b/crates/load_test/src/lib.rs @@ -0,0 +1 @@ +//! src/lib.rs diff --git a/crates/load_test/src/main.rs b/crates/load_test/src/main.rs new file mode 100644 index 0000000..0331976 --- /dev/null +++ b/crates/load_test/src/main.rs @@ -0,0 +1,452 @@ +//! src/main.rs +// use actix_web::{HttpRequest, HttpResponse}; +// use fred::types::GeoRadiusInfo; +use chrono::{DateTime, Utc}; +use rand::{thread_rng, Rng}; +use reqwest::header::CONTENT_TYPE; +use serde::{Deserialize, Serialize}; +use std::{ + io::{stdin, stdout, Write}, + str::FromStr, + time::{Duration, Instant}, +}; +// use std::thread; +// use serde_json::Value; + +const HOST_URL: &str = "http://127.0.0.1:8081"; + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct UpdateDriverLocationRequest { + pub pt: Point, + pub ts: DateTime, + pub acc: i32, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Point { + pub lat: f64, + pub lon: f64, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct AuthResponseData { + pub driver_id: String, + pub token: String, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct GetNearbyDriversRequest { + pub lat: f64, + pub lon: f64, + pub vehicle_type: String, + pub radius: f64, + pub merchant_id: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct DriverLocs { + pub lon: f64, + pub lat: f64, + pub driver_id: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct RideStartRequest { + pub lat: f64, + pub lon: f64, + pub driver_id: String, + pub merchant_id: String, +} +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct RideEndRequest { + pub lat: f64, + pub lon: f64, + pub driver_id: String, + pub merchant_id: String, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct NearbyDriverResp { + pub resp: Vec<(f64, f64, String)>, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct RideId { + pub on_ride: bool, + pub ride_id: String, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct DriverRideData { + pub resp: Vec<(f64, f64)>, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct DriverData { + pub lon: f64, + pub lat: f64, + pub merchant_id: String, + pub vehicle_type: String, + pub driver_id: String, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct DurationStruct { + pub dur: Duration, +} + +#[tokio::main] +async fn main() { + let client = reqwest::Client::new(); + let mut rng = thread_rng(); + loop { + println!("1. get_drivers\n2. default send driver\n3. call actual endpoint\n4. Start ride enpoint\n5. End ride endpoint\n6. Default actual endpoints\n7. On Ride testing\n0. End"); + let mut inp = String::new(); + stdin().read_line(&mut inp).unwrap(); + match inp.trim().parse::() { + Ok(x) => { + if x == 1 { + let lon = get_inp::("lon"); + let lat = get_inp::("lat"); + let vehicle_type = get_inp::("vt"); + let radius = get_inp::("radius"); + let merchant_id = String::from("Namma Yatri"); + let data = GetNearbyDriversRequest { + lon, + lat, + vehicle_type, + radius, + merchant_id, + }; + let resp = get_drivers(data, client.clone()) + .await + .json::() + .await + .unwrap(); + println!("{:?}", resp); + } else if x == 2 { + let mut list: Vec = Vec::new(); + let num = get_inp::("num of points"); + for i in 0..num { + let lon = rng.gen_range(-180.0..180.0); + let lat = rng.gen_range(-85.05..85.05); + let driver_id = format!("loc{}", i); + let num = rng.gen_range(0..4); + let vehicle_type = match num { + 0 => "auto".to_string(), + 1 => "cab".to_string(), + 2 => "suv".to_string(), + _ => "sedan".to_string(), + }; + let merchant_id = if rng.gen_bool(0.5) { + "Namma Yatri".to_string() + } else { + "Uber".to_string() + }; + let data = DriverData { + lon, + lat, + driver_id, + vehicle_type, + merchant_id, + }; + list.push(data); + // println!("{:?}", data); + + // thread::sleep(Duration::from_millis(10)); + } + let batch_size = get_inp::("batch size"); + let mut dur = Duration::from_secs(0); + if num <= batch_size { + println!("single"); + let start = Instant::now(); + dur += send_loc(list, client.clone()).await; + let duration = start.elapsed(); + println!("Duration: {:?}", duration); + } else { + let num_new = num / batch_size; + let start = Instant::now(); + for i in 0..num_new { + let start = i * batch_size; + let mut end = (i + 1) * batch_size; + end = if end > num { num } else { end }; + dur += send_loc(list[start..end].to_vec(), client.clone()).await; + } + let duration = start.elapsed(); + println!("Duration: {:?}", duration); + } + println!("Time Taken: {:?}", dur); + } else if x == 3 { + let lon = rng.gen_range(-180.0..180.0); + let lat = rng.gen_range(-85.05..85.05); + let num = rng.gen_range(0..4); + let ts = Utc::now(); + let acc = 1; + let vt = match num { + 0 => "auto".to_string(), + 1 => "cab".to_string(), + 2 => "suv".to_string(), + _ => "sedan".to_string(), + }; + let token = "3ab7efd4-961e-432a-835d-4d36caa042cb"; + let m_id = "favorit0-0000-0000-0000-00000favorit".to_string(); + let data = UpdateDriverLocationRequest { + pt: Point { lat, lon }, + ts, + acc, + }; + send_actual_loc(vec![data], client.clone(), token, m_id, vt).await; + } else if x == 4 { + let lon = rng.gen_range(75.0..76.5); + let lat = rng.gen_range(13.0..16.5); + let driver_id = "favorit-suv-000000000000000000000000".to_string(); + let merchant_id = "favorit0-0000-0000-0000-00000favorit".to_string(); + let data = RideStartRequest { + lon, + lat, + driver_id, + merchant_id, + }; + let ride_id = "1234"; + send_start_req(data, client.clone(), ride_id).await; + } else if x == 5 { + let lon = rng.gen_range(75.0..76.5); + let lat = rng.gen_range(13.0..16.5); + let driver_id = "favorit-suv-000000000000000000000000".to_string(); + let merchant_id = "favorit0-0000-0000-0000-00000favorit".to_string(); + let data = RideEndRequest { + lon, + lat, + driver_id, + merchant_id, + }; + let ride_id = "1234"; + let resp = send_end_req(data, client.clone(), ride_id) + .await + .json::() + .await + .unwrap(); + println!("resp: {:?}", resp); + } else if x == 6 { + let mut list: Vec = Vec::new(); + let num = get_inp::("num of points"); + let batch_size = get_inp::("batch size"); + for _i in 0..num { + let mut lon: f64; + let mut lat: f64; + let region_num = rng.gen_range(0..2); + for _j in 0..batch_size { + if region_num == 1 { + lon = rng.gen_range(75.0..76.5); + lat = rng.gen_range(13.0..16.5); + } else { + lon = rng.gen_range(76.5..77.0); + lat = rng.gen_range(9.5..10.0); + } + let data = UpdateDriverLocationRequest { + pt: Point { lon, lat }, + acc: 1, + ts: Utc::now(), + }; + list.push(data); + } + // println!("{:?}", data); + + // thread::sleep(Duration::from_millis(10)); + } + + let merchant_id = "favorit0-0000-0000-0000-00000favorit".to_string(); + let mut dur = Duration::from_secs(0); + println!("starting"); + if num <= batch_size { + println!("single"); + let num_gen = rng.gen_range(0..6); + let token = match num_gen { + 0 => "favorit-admin-0000000000000000-token", + 1 => "favorit-auto1-0000000000000000-token", + 2 => "favorit-auto2-0000000000000000-token", + 3 => "favorit-hatchback-000000000000-token", + 4 => "favorit-sedan-0000000000000000-token", + _ => "favorit-suv-000000000000000000-token", + }; + let vehicle_type = match num_gen { + 0 => "admin".to_string(), + 1 => "auto1".to_string(), + 2 => "auto2".to_string(), + 3 => "hatchback".to_string(), + 4 => "sedan".to_string(), + _ => "suv".to_string(), + }; + let start = Instant::now(); + dur += + send_actual_loc(list, client.clone(), token, merchant_id, vehicle_type) + .await; + let duration = start.elapsed(); + println!("Duration: {:?}", duration); + } else { + let num_new = num / batch_size; + let start = Instant::now(); + for i in 0..num_new { + let num_gen = rng.gen_range(0..6); + let token = match num_gen { + 0 => "favorit-admin-0000000000000000-token", + 1 => "favorit-auto1-0000000000000000-token", + 2 => "favorit-auto2-0000000000000000-token", + 3 => "favorit-hatchback-000000000000-token", + 4 => "favorit-sedan-0000000000000000-token", + _ => "favorit-suv-000000000000000000-token", + }; + let vehicle_type = match num_gen { + 0 => "admin".to_string(), + 1 => "auto1".to_string(), + 2 => "auto2".to_string(), + 3 => "hatchback".to_string(), + 4 => "sedan".to_string(), + _ => "suv".to_string(), + }; + let start = i * batch_size; + let mut end = (i + 1) * batch_size; + end = if end > num { num } else { end }; + dur += send_actual_loc( + list[start..end].to_vec(), + client.clone(), + token, + merchant_id.clone(), + vehicle_type.clone(), + ) + .await; + } + let duration = start.elapsed(); + println!("Duration: {:?}", duration); + } + println!("Time Taken: {:?}", dur); + } else if x == 7 { + let lon = rng.gen_range(75.0..76.5); + let lat = rng.gen_range(13.0..16.5); + let token = "favorit-suv-000000000000000000-token"; + let vehicle_type = "suv".to_string(); + let merchant_id = "favorit0-0000-0000-0000-00000favorit".to_string(); + let data = UpdateDriverLocationRequest { + pt: Point { lon, lat }, + ts: Utc::now(), + acc: 1, + }; + let _ = send_actual_loc( + vec![data], + client.clone(), + token, + merchant_id, + vehicle_type, + ) + .await; + } else if x == 0 { + break; + } + } + _ => continue, + } + } +} + +fn get_inp(query: &str) -> K +where + K: FromStr, +{ + let mut inp = String::new(); + loop { + print!("{}: ", query); + stdout().flush().unwrap(); + stdin().read_line(&mut inp).unwrap(); + match inp.trim().parse::() { + Ok(x) => { + return x; + } + _ => continue, + } + } +} + +async fn send_start_req(data: RideStartRequest, client: reqwest::Client, ride_id: &str) { + let json = serde_json::to_string(&data).unwrap(); + let _body = client + .post(format!("{}/internal/ride/{}/start", HOST_URL, ride_id)) + .header(CONTENT_TYPE, "application/json") + .body(json) + .send() + .await; +} + +async fn send_end_req( + data: RideEndRequest, + client: reqwest::Client, + ride_id: &str, +) -> reqwest::Response { + let json = serde_json::to_string(&data).unwrap(); + // println!("{}", format_args!("{}/internal/ride/?rideId={}/end", HOST_URL, ride_id)); + client + .post(format!("{}/internal/ride/{}/end", HOST_URL, ride_id)) + .header(CONTENT_TYPE, "application/json") + .body(json) + .send() + .await + .unwrap() +} + +async fn send_loc(data: Vec, client: reqwest::Client) -> Duration { + let json = serde_json::to_string(&data).unwrap(); + let body = client + .post(format!("{}/location", HOST_URL)) + .header(CONTENT_TYPE, "application/json") + .body(json.clone()) + .send() + .await; + // println!("{json}"); + serde_json::from_str::(&body.unwrap().text().await.unwrap()) + .unwrap() + .dur +} + +async fn send_actual_loc( + data: Vec, + client: reqwest::Client, + token: &str, + m_id: String, + vt: String, +) -> Duration { + let json = serde_json::to_string(&data).unwrap(); + // println!("{}", json); + let body = client + .post(format!("{}/ui/driver/location", HOST_URL)) + .header(CONTENT_TYPE, "application/json") + .header("token", token) + .header("vt", vt) + .header("mId", m_id) + .body(json) + .send() + .await + .unwrap(); + let status = body.status(); + let response_body = body.text().await.unwrap(); + if status != 200 { + // println!("{response_body}"); + Duration::from_secs(0) + } else { + serde_json::from_str::(&response_body) + .unwrap() + .dur + } +} + +// driver-id: favorit-suv-000000000000000000000000 + +async fn get_drivers(data: GetNearbyDriversRequest, client: reqwest::Client) -> reqwest::Response { + let json = serde_json::to_string(&data).unwrap(); + // println!("{}", formatted.concat()); + client + .get(format!("{}/internal/drivers/nearby", HOST_URL)) + .header(CONTENT_TYPE, "application/json") + .body(json) + .send() + .await + .unwrap() +}