-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.py
62 lines (55 loc) · 1.76 KB
/
launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Send a bunch of requests to median-microservice."""
from argparse import ArgumentParser
from datetime import datetime
from random import randrange
from urllib import urlencode
from urllib2 import Request, urlopen
def send_requests_to_median(host, amount, upper_limit):
"""
Send an `amount` of random put requests with median requests interpersed.
Args:
amount (int): The amount of requests to send.
upper_limit (int): The highest number you want to send to /put.
"""
for i in range(0, amount):
this_int = randrange(1, upper_limit)
data = urlencode({'int': this_int})
req = Request('http://{}/put'.format(host), data)
response = urlopen(req)
if response.code == 200:
print('{} - Sent: {}'.format(datetime.now(), this_int))
del response
def create_parser():
"""Create a command line parser for this module."""
parser = ArgumentParser(
description='Send some requests to median-microservice.'
)
parser.add_argument(
'host',
type=str,
help="The median-microservice host."
)
parser.add_argument(
'-a',
'--amount',
type=int,
default=2000,
help="The amount of /put requests you want to send."
)
parser.add_argument(
'-u',
'--upper-limit',
type=int,
default=100000,
help='The largest integer to send to /put (each number sent will be '
'randomly chosen between 1 and this value).'
)
return parser
if __name__ == '__main__':
parser = create_parser()
# Arguments to set
args = parser.parse_args()
host = args.host
amount = args.amount
upper_limit = args.upper_limit
send_requests_to_median(host, amount, upper_limit)