Add key commands for increasing and stopping users - #1612
Conversation
…s in headless mode
| @@ -0,0 +1,91 @@ | |||
| import time | |||
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
this isnt supposed to be here right? :) (could be useful as a logging.debug statement though)
| input_listener_greenlet = gevent.spawn( | ||
| input_listener( | ||
| { | ||
| "w": lambda: runner.spawn_users(1, runner.spawn_rate), |
There was a problem hiding this comment.
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)
| @@ -0,0 +1,91 @@ | |||
| import time | |||
|
|
|||
| isWindows = False | |||
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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