NBomber icon indicating copy to clipboard operation
NBomber copied to clipboard

Is it possible to use Steps for Scenario.withInit and Scenario.withClean?

Open pavlogrushetsky opened this issue 2 years ago • 10 comments

It would be great if it was possible to reuse the actions defined in the Steps for the Scenario.withInit and Scenario.withClean functions.

For example, we could have the steps for some CRUD operations. Even though the steps could be tested within the different scenarios independently, it would be helpful if we could test Read step, and use Create step for initialization, and Delete step for cleanup.

It looks like it's not possible at the moment, or am I missing something?

pavlogrushetsky avatar May 10 '22 17:05 pavlogrushetsky

Hi @pavlogrushetsky I see your point and it sounds reasonable. But what to do with TFeed, TClient, IStepContext within Scenario.withInit ?

AntyaDev avatar May 11 '22 04:05 AntyaDev

I have no idea at the moment 😄 I just tried to replicate some of my existing load tests written in k6, and it turned out that it's not possible to re-use the steps logic for initialization/clean-up. To answer your question, I would need to take a closer look at the source code. But it seems to me like such feature would be very helpful, otherwise I would need to duplicate the same logic (for example, sending an http request) between the step (using NBomber.Http) and initialization/clean-up functions.

pavlogrushetsky avatar May 11 '22 06:05 pavlogrushetsky

Are you using Data Feed or some Websocket, SQL connections in k6 ?

AntyaDev avatar May 11 '22 08:05 AntyaDev

Currently we have just the k6 load tests for our web services over HTTP.

pavlogrushetsky avatar May 11 '22 09:05 pavlogrushetsky

Just by curiosity, why do you consider NBomber over k6 then?

AntyaDev avatar May 11 '22 10:05 AntyaDev

Because it's in F#, and we could use our existing request/response models and other logic.

pavlogrushetsky avatar May 11 '22 10:05 pavlogrushetsky

Hello everyone 👋🏽 I have a similar question. Is there a reason why the Client Factory is unavailable in the IScenarioContext & would it be possible to add it ? We face the same issue as we need to clean up remote data using DELETE HTTP requests. We don't necessarily need to use the exact logic of a step, but at least the HTTP client that we have initialized. I would appreciate any feedback. TY 🙏🏽

billsioros avatar Sep 14 '22 14:09 billsioros

Hi @billsioros It's a good question. Technically each step can have a different client factory; for example

Step.Create("test_mongo_db", MongoClientFactory.Create(), execute: async context => return Response.Ok());
Step.Create("test_redis", RedisClientFactory.Create(), execute: async context => return Response.Ok());

Which client factory should be passed to Scenario.Clean() ??

I guess we could have passed an array of ClientFactory(s), but then we face another issue - it's a generics limitation over ClientFactory<T>. It's impossible to have ClientFactories<T>[] since T will differ for RedisClient and MongoDBClient.

I think another option could be just to expose public property from ClientFactory itself. For example, MongoClientFactory.Clients: T[] and then you can just get access to it in ScenarioClean

Scenario.WithClean(context => MongoClientFactory.Clients[0].Dispose())

AntyaDev avatar Sep 15 '22 05:09 AntyaDev

Thank you @AntyaDev for the prompt response! I appreciate it extremely!

For example, MongoClientFactory.Clients: T[] and then you can just get access to it in ScenarioClean

I assume that this should suffice! Is something along those lines planned ? 😄

billsioros avatar Sep 15 '22 09:09 billsioros

Hi @billsioros Yes) This week, I will try to release a new version with a real-time stats table for the NBomber console (replacement for progress bars) And after this release, I will start working on this feature.

AntyaDev avatar Sep 17 '22 07:09 AntyaDev

Hi @billsioros , https://github.com/PragmaticFlow/NBomber/pull/486

You can use ClientFatory.initializedClients: TClient[] inside Scenario.Clean https://github.com/PragmaticFlow/NBomber.Contracts/blob/dev/src/NBomber.Contracts/ClientFactory.fs#L9

AntyaDev avatar Oct 05 '22 06:10 AntyaDev