Skip to content

Add key commands for increasing and stopping users - #1612

Merged
cyberw merged 17 commits into
locustio:masterfrom
DennisKrone:keyboard-input
Nov 13, 2020
Merged

cyberw merged 17 commits into
locustio:masterfrom
DennisKrone:keyboard-input

Conversation

@DennisKrone

@DennisKrone DennisKrone commented Nov 2, 2020

Copy link
Copy Markdown
Collaborator

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

fixes #1600

Comment thread locust/input_events.py Outdated
@@ -0,0 +1,91 @@
import time

Copy link
Copy Markdown
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...

Comment thread locust/input_events.py Outdated
while True:
input = poller.poll()
if input is not None:
print(f"Current input is: {input}")

Copy link
Copy Markdown
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)

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

Copy link
Copy Markdown
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)

Comment thread locust/main.py
Comment thread locust/input_events.py Outdated
@@ -0,0 +1,91 @@
import time

isWindows = False

Copy link
Copy Markdown
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':
     ...

Comment thread locust/input_events.py Outdated
return self

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

Copy link
Copy Markdown
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

Comment thread locust/input_events.py Outdated

self.cur_event_length = len(events_peek)

if not len(self.captured_chars) == 0:

@cyberw cyberw Nov 2, 2020

Copy link
Copy Markdown
Collaborator

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:

Comment thread locust/input_events.py Outdated
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
Copy Markdown
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

codecov Bot commented Nov 6, 2020

Copy link
Copy Markdown

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
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