Skip to content

Update shape class' runner when Web UI picker is used - #2534

Merged
cyberw merged 5 commits into
locustio:masterfrom
wiatrak2:set_shape_class_runner_when_ui_picker_used
Jan 5, 2024
Merged

Update shape class' runner when Web UI picker is used#2534
cyberw merged 5 commits into
locustio:masterfrom
wiatrak2:set_shape_class_runner_when_ui_picker_used

Conversation

@wiatrak2

@wiatrak2 wiatrak2 commented Jan 4, 2024

Copy link
Copy Markdown
Contributor

a shape class' .runner member is set by _create_runner method of Environment class. However, when the UI picker is used, the shape_class member of an Environment instance is not initialized yet, hence, there's no Runner assignment on initialization. Therefore, if you'd like to refer to self.runner in your custom test shape (for instance to get the number of users running), you receive an error saying that self.runner is None.

Hence, I added the shape class runner initialization also when the shape class is selected with UI picker.

@cyberw

cyberw commented Jan 4, 2024

Copy link
Copy Markdown
Collaborator

Can you add a test case that fails without this change?

@wiatrak2

wiatrak2 commented Jan 4, 2024

Copy link
Copy Markdown
Contributor Author

There you go :)

@cyberw

cyberw commented Jan 5, 2024

Copy link
Copy Markdown
Collaborator

I see the need for the change, but update_shape_class_runner is a very weird method. Perhaps it can be refactored/renamed to something that makes more sense. Or just remove the method and have the "weird" behavior inline, where it is at least readable.

@wiatrak2

wiatrak2 commented Jan 5, 2024

Copy link
Copy Markdown
Contributor Author

I believe that we should avoid code repetition. Also I think that the action should be encapsulated by a method, as it wouldn't be clean to modify Environment's members from inside the WebUI. Thinking about a better name, my candidate is set_runner_in_shape_class - what do you think? 馃槄

@cyberw

cyberw commented Jan 5, 2024

Copy link
Copy Markdown
Collaborator

How about doing it here: https://github.com/locustio/locust/pull/2534/files#diff-498b8c363e788cc0210ac8600bce7660c60d210cad41af086886b79055c717beR636
, where we are already accessing the shape class directly.

Something like
shape_class.runner = self.environment.runner

environment-runner separation is very messy, and while I dont like duplication, I like methods with unclear meaning even less :)

@wiatrak2

wiatrak2 commented Jan 5, 2024

Copy link
Copy Markdown
Contributor Author

your code, your rules ;)

@cyberw
cyberw merged commit d557d1e into locustio:master Jan 5, 2024
@cyberw

cyberw commented Jan 5, 2024

Copy link
Copy Markdown
Collaborator

Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants