-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
…s in headless mode
locust/input_events.py
Outdated
@@ -0,0 +1,91 @@ | |||
import time |
There was a problem hiding this comment.
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...
locust/input_events.py
Outdated
while True: | ||
input = poller.poll() | ||
if input is not None: | ||
print(f"Current input is: {input}") |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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/input_events.py
Outdated
@@ -0,0 +1,91 @@ | |||
import time | |||
|
|||
isWindows = False |
There was a problem hiding this comment.
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':
...
locust/input_events.py
Outdated
return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
if isWindows: |
There was a problem hiding this comment.
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
locust/input_events.py
Outdated
|
||
self.cur_event_length = len(events_peek) | ||
|
||
if not len(self.captured_chars) == 0: |
There was a problem hiding this comment.
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:
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: |
There was a problem hiding this comment.
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)
Also updates how the current os is found.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
w = increase by 1
W = increase by 10
s = stop 1
S = stop 10
fixes #1600