Comments (5)
To only log each user in once, you'd use set_on_start() and the GooseUser will log in and then make all subsequent requests as an authenticated user:
https://docs.rs/goose/latest/goose/goose/struct.Transaction.html#method.set_on_start
To truly only log in once, you could instead call test_start():
https://docs.rs/goose/latest/goose/struct.GooseAttack.html#method.test_start
However, you'd then be responsible for saving whatever session information is needed, most likely requiring that you build each user setting the appropriate header or cookie etc:
https://docs.rs/goose/latest/goose/goose/struct.GooseUser.html#method.set_client_builder
from goose.
That's really helpful. What's the idiomatic way to pass session information from that global level down into a GooseUser
? The user created for the test_start
method wouldn't have its information saved and I can't see a way to get information out of that thread and back up to the main
function to be passed down to future users?
from goose.
When I did something similar for a client some time ago, I used OnceCell
. I essentially populated it during test_start()
which runs before the GooseUser's are created for the load test, and then used it in set_on_start()
to simulate per GooseUser login.
from goose.
Grand. Thank you. I ended up leaning into std::sync::OnceLock
. I'll share a very basic snippet of it here for anyone else that comes across this
// globals.rs
pub static SESSION: OnceLock<Box<Session>> = OnceLock::new();
pub fn build_global_session(
auth_token: SecretString,
api_key: SecretString,
) {
let session = Session {
auth_token,
api_key,
};
let boxed_session = Box::new(session);
SESSION.get_or_init(|| boxed_session);
}
// authorisation.rs
pub async fn setup_custom_client(user: &mut GooseUser) -> TransactionResult {
let session = SESSION.get().expect("Couldn't get the global session data");
user.set_session_data(session);
Ok(())
}
Thanks for your help!
from goose.
Great! If you'd like to make a quick PR, it would be great to add another example that demonstrates this:
https://github.com/tag1consulting/goose/tree/main/examples
from goose.
Related Issues (20)
- Potential segfault in the time crate
- Non friendly for newcomers HOT 2
- panic: assertion failed: self.is_char_boundary(new_len) when transaction!(xx).set_name("一二三四五六七") HOT 2
- User Context HOT 3
- Something fishy about cookies managment ... HOT 2
- compile on windows failed HOT 2
- Is it able to make gaggle support html report? HOT 1
- Goose hangs in the exiting phase HOT 4
- Integrate https://pola.rs/ HOT 1
- Duration formatting rounds up to 1 ms HOT 4
- support server-sent events
- Time for a new release ? HOT 2
- Time to first byte? HOT 3
- Programatically accessing the HTML Report HOT 2
- how to log response body HOT 4
- Markdown report HOT 1
- Export report as JSON HOT 1
- `-dev` version causes issues with patching HOT 1
- Compare with baseline HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goose.