Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key commands for increasing and stopping users #1612

Merged
merged 17 commits into from Nov 13, 2020

Conversation

DennisKrone
Copy link
Contributor

@DennisKrone DennisKrone commented Nov 2, 2020

w = increase by 1
W = increase by 10
s = stop 1
S = stop 10

fixes #1600

@@ -0,0 +1,91 @@
import time
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use gevent.sleep instead of time.sleep. They actually mean the same thing, but only because gevent has monkey patched it, and locust seems to use gevent.sleep throughout...

while True:
input = poller.poll()
if input is not None:
print(f"Current input is: {input}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt supposed to be here right? :) (could be useful as a logging.debug statement though)

locust/main.py Outdated
input_listener_greenlet = gevent.spawn(
input_listener(
{
"w": lambda: runner.spawn_users(1, runner.spawn_rate),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to use runner.spawn_rate, just do it immediately (set it to maybe 100). If people want to spawn slowly then let them wait between keypresses :) (when spawning only one user it will not matter anyway)

locust/main.py Show resolved Hide resolved
@@ -0,0 +1,91 @@
import time

isWindows = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nicer way to know if we're on Windows (no need to try/catch & no need to store our own variable)

import os

if os.name == 'nt':
     ...

return self

def __exit__(self, type, value, traceback):
if isWindows:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

if not something:
     # do something 

instead of

if something:
    pass
else:
    # do something


self.cur_event_length = len(events_peek)

if not len(self.captured_chars) == 0:
Copy link
Collaborator

@cyberw cyberw Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 90% sure this can be replaced with just

 if self.captured_chars:

if not len(events_peek) == self.cur_event_length:
for cur_event in events_peek[self.cur_event_length :]:
if cur_event.EventType == KEY_EVENT:
if ord(cur_event.Char) == 0 or not cur_event.KeyDown:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely, this:

                    if ord(cur_event.Char) == 0 or not cur_event.KeyDown:
                        pass
                    else:
                        cur_char = str(cur_event.Char)
                        self.captured_chars.append(cur_char)

can be replaced by

                    if ord(cur_event.Char) and cur_event.KeyDown:
                        cur_char = str(cur_event.Char)
                        self.captured_chars.append(cur_char)

@codecov
Copy link

codecov bot commented Nov 6, 2020

Codecov Report

Merging #1612 (85a8928) into master (08d5173) will decrease coverage by 1.11%.
The diff coverage is 24.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1612      +/-   ##
==========================================
- Coverage   81.97%   80.85%   -1.12%     
==========================================
  Files          28       29       +1     
  Lines        2585     2648      +63     
  Branches      394      408      +14     
==========================================
+ Hits         2119     2141      +22     
- Misses        370      410      +40     
- Partials       96       97       +1     
Impacted Files Coverage Δ
locust/argument_parser.py 77.39% <ø> (+0.19%) ⬆️
locust/main.py 20.52% <16.66%> (+0.43%) ⬆️
locust/input_events.py 24.63% <24.63%> (ø)
locust/clients.py 90.19% <0.00%> (-4.91%) ⬇️
locust/stats.py 88.82% <0.00%> (-1.26%) ⬇️
locust/user/users.py 95.77% <0.00%> (-0.06%) ⬇️
locust/env.py 96.72% <0.00%> (ø)
locust/web.py 91.56% <0.00%> (+0.18%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08d5173...85a8928. Read the comment docs.

@cyberw cyberw merged commit 1670b42 into locustio:master Nov 13, 2020
1 check failed
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.

Control user count from terminal
2 participants