Skip to content

Commit 3ef5ffb

Browse files
committed
feat: allow making the request timeout configurable
1 parent d305525 commit 3ef5ffb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/main.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ async fn main() -> Result<(), anyhow::Error> {
4343
}));
4444

4545
GooseAttack::initialize()?
46-
.test_start(Transaction::new(Arc::new({
47-
let scenario = scenario.clone();
48-
move |_| {
46+
.test_start(
47+
Transaction::new(Arc::new({
4948
let scenario = scenario.clone();
50-
Box::pin(async move {
51-
log::info!("Scenario: {scenario:#?}");
52-
Ok(())
53-
})
54-
}
55-
})))
49+
move |_| {
50+
let scenario = scenario.clone();
51+
Box::pin(async move {
52+
log::info!("Scenario: {scenario:#?}");
53+
Ok(())
54+
})
55+
}
56+
}))
57+
.set_name("log scenario"),
58+
)
5659
.register_scenario(
5760
scenario!("WebsiteUser")
5861
// .set_weight(1)?
@@ -183,11 +186,18 @@ async fn set_custom_client(
183186
header::HeaderValue::from_str(&format!("Bearer {auth_token}"))?,
184187
);
185188

189+
let timeout = std::env::var("REQUEST_TIMEOUT")
190+
.ok()
191+
.map(|value| humantime::Duration::from_str(&value))
192+
.transpose()?
193+
.map(|v| v.into())
194+
.unwrap_or(Duration::from_secs(300));
195+
186196
// Build a custom client.
187197
let builder = Client::builder()
188198
.default_headers(headers)
189199
.user_agent("loadtest-ua")
190-
.timeout(Duration::from_secs(300));
200+
.timeout(timeout);
191201

192202
// Assign the custom client to this GooseUser.
193203
user.set_client_builder(builder).await?;

0 commit comments

Comments
 (0)