Skip to content

Commit

Permalink
Add socks proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
tokland committed Jun 19, 2024
1 parent 70ebd5d commit dde3dab
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Save a HAR file in a browser (Chrome: Developer Tools -> Network tab -> Export H
]
```

And run the scenarios against the same or a different DHIS2 instance:
And run the specificied scenarios against the same or a different DHIS2 instance:

```shell
$ yarn start loadTesting run \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"purify-ts": "2.0.1",
"random-seed": "^0.3.0",
"simple-node-logger": "^21.8.12",
"socks-proxy-agent": "^8.0.2",
"socks-proxy-agent": "^8.0.3",
"xlsx": "^0.18.5"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion src/data/LoadingPlanHarRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Entry, Har } from "har-format";
import axios, { AxiosRequestConfig, Method } from "axios";
import { LoadingPlanRepository, Options } from "../domain/repositories/LoadingPlanRepository";
import { LoadingPlan } from "../domain/entities/LoadingPlan";
import { SocksProxyAgent } from "socks-proxy-agent";

export interface RunHarResult {
time: number;
Expand All @@ -20,8 +21,12 @@ interface RepoOptions {
harUrl: string;
}

const socksProxyUrl = process.env.ALL_PROXY;
const agent = socksProxyUrl ? new SocksProxyAgent(socksProxyUrl) : undefined;

const axios2 = axios.create({
//keepAlive pools and reuses TCP connections, so it's faster
httpAgent: agent,
httpsAgent: new https.Agent({ keepAlive: true }),
//timeout: 600 * 1000,
//maxRedirects: 10,
Expand Down Expand Up @@ -154,7 +159,7 @@ export class LoadingPlanHarRepository implements LoadingPlanRepository {
console.debug(`[request-response:${index + 1}/${total}] ` + resInfo);

const isSuccess =
[0, 200, 201, 304, 404, 409].includes(res?.status || 0) ||
[0, 200, 201, 302, 304, 404, 409].includes(res?.status || 0) ||
request.url.includes("files/script") ||
request.url.includes("staticContent");

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/commands/loadTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const homepagePlan: Plan = {
This defines three sequential executions of src/hars/homepage.har, with 1/50/100 concurrent users that start the HAR at random points in the 0<->60secs interval.
2) Run: npx ts-node src/scripts/run-load-testing.ts http://host-used-in-har:8080 http://host-to-test:8081 hars homepagePlan
2) Run script
Plan-results: homepage - window=60 secs - users=1 | mean-time=6.4 s | errors=0/72 (0.00 %)
Plan-results: homepage - window=60 secs - users=10 | mean-time=8.8 s | errors=0/720 (0.00 %)
Plan-results: homepage - window=60 secs - users=50 | mean-time=7.0 s | errors=0/3600 (0.00 %)
IDEA for the next iteration: to make the request more real, we could run real scenarios
using a real browser (for example: headless chrome with puppeteer). Instead of HAR, we'd
run javascript code that runs the scenario.
execute javascript code that simulates the scenario.
*/

export function getCommand() {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ agent-base@6:
dependencies:
debug "4"

agent-base@^7.0.2:
version "7.1.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.0.tgz#536802b76bc0b34aa50195eb2442276d613e3434"
integrity sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==
agent-base@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317"
integrity sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==
dependencies:
debug "^4.3.4"

Expand Down Expand Up @@ -4231,12 +4231,12 @@ smart-buffer@^4.2.0:
resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"
integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==

socks-proxy-agent@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-8.0.2.tgz#5acbd7be7baf18c46a3f293a840109a430a640ad"
integrity sha512-8zuqoLv1aP/66PHF5TqwJ7Czm3Yv32urJQHrVyhD7mmA6d61Zv8cIXQYPTWwmg6qlupnPvs/QKDmfa4P/qct2g==
socks-proxy-agent@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-8.0.3.tgz#6b2da3d77364fde6292e810b496cb70440b9b89d"
integrity sha512-VNegTZKhuGq5vSD6XNKlbqWhyt/40CgoEw8XxD6dhnm8Jq9IEa3nIa4HwnM8XOqU0CdB0BwWVXusqiFXfHB3+A==
dependencies:
agent-base "^7.0.2"
agent-base "^7.1.1"
debug "^4.3.4"
socks "^2.7.1"

Expand Down

0 comments on commit dde3dab

Please sign in to comment.