Skip to content

Commit f532bce

Browse files
committed
clean up unauth calls
1 parent b2a70af commit f532bce

3 files changed

Lines changed: 21 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"run:with-logs": "pnpm build && pnpm with-logs",
1616
"test:run": "pnpm run:with-logs artillery run",
1717

18-
"test:msp-unauth": "pnpm test:run scenarios/artillery.msp-unauth.yml",
18+
"test:unauth": "pnpm test:run scenarios/msp.unauth.yml",
1919
"test:examples.getProfile": "pnpm test:run scenarios/examples.getProfile.yml",
2020
"test:download": "pnpm test:run scenarios/download.yml"
2121
},
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ config:
3232
rampTo: 1
3333

3434
scenarios:
35-
- name: msp_unauth_load
35+
- name: MSP_Unauthenticated_calls
3636
flow:
37-
- function: mspUnauthLoad
37+
- function: getHealth
38+
- function: getInfo
3839

3940

src/processors/msp-unauth.ts

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,26 @@
11
import { MspClient } from "@storagehub-sdk/msp-client";
22
import type { HttpClientConfig } from "@storagehub-sdk/core";
3-
import type { Logger } from "pino";
43
import { getLogger } from "../log.js";
54
import { readEnv } from "../config.js";
65
import { NETWORKS } from "../networks.js";
7-
import type { Env } from "../config.js";
86
import { createEmitter } from "../helpers/metrics.js";
97
import type {
108
ArtilleryContext,
119
ArtilleryEvents,
1210
} from "../helpers/artillery.js";
11+
import { buildMspHttpClientConfig } from "../sdk/mspHttpConfig.js";
1312

14-
function sleep(ms: number): Promise<void> {
15-
return new Promise((resolve) => setTimeout(resolve, ms));
16-
}
17-
18-
function buildHttpConfig(env: Env): HttpClientConfig {
19-
const network = NETWORKS[env.network];
20-
const base: { baseUrl: string; timeoutMs?: number } = {
21-
baseUrl: network.msp.baseUrl,
22-
};
23-
if (typeof network.msp.timeoutMs === "number") {
24-
base.timeoutMs = network.msp.timeoutMs;
25-
}
26-
const overrideRaw = process.env.MSP_TIMEOUT_MS;
27-
if (overrideRaw && overrideRaw.length > 0) {
28-
const n = Number.parseInt(overrideRaw, 10);
29-
if (Number.isFinite(n)) {
30-
base.timeoutMs = n;
31-
}
32-
}
33-
return base;
34-
}
35-
36-
async function connectUnauth(env: Env, logger: Logger): Promise<MspClient> {
37-
const config = buildHttpConfig(env);
38-
logger.info({ baseUrl: config.baseUrl }, "msp unauth connect");
39-
return await MspClient.connect(config, async () => undefined);
40-
}
41-
42-
export async function mspUnauthLoad(
13+
export async function getHealth(
4314
context: ArtilleryContext,
4415
events: ArtilleryEvents
4516
): Promise<void> {
4617
const m = createEmitter(context, events);
4718
const logger = getLogger();
4819
const env = readEnv();
20+
const network = NETWORKS[env.network];
4921

50-
const client = await connectUnauth(env, logger);
22+
const config = buildMspHttpClientConfig(network);
23+
const client = await MspClient.connect(config);
5124

5225
const healthStart = Date.now();
5326
try {
@@ -58,8 +31,19 @@ export async function mspUnauthLoad(
5831
m.counter("msp.req.err", 1);
5932
logger.debug({ err }, "msp unauth request error");
6033
}
34+
}
35+
36+
export async function getInfo(
37+
context: ArtilleryContext,
38+
events: ArtilleryEvents
39+
): Promise<void> {
40+
const m = createEmitter(context, events);
41+
const logger = getLogger();
42+
const env = readEnv();
43+
const network = NETWORKS[env.network];
6144

62-
await sleep(1000);
45+
const config = buildMspHttpClientConfig(network);
46+
const client = await MspClient.connect(config);
6347

6448
const infoStart = Date.now();
6549
try {

0 commit comments

Comments
 (0)