pyrace¶
pyrace is an HTTP[S] race condition auditing package built using the Requests library.
Examples
Single Request per worker:
>>> driver = pyrace.Driver()
>>> request = requests.Request('GET', 'http://now.httpbin.org')
>>> threads = driver.process(request, thread_count = 2)
>>> [t.response.json()['now']['epoch'] for t in threads]
[1497300394.5125718, 1497300394.5126784]
Multiple Requests per worker:
>>> driver = pyrace.Driver()
>>> req1 = requests.Request('GET', 'http://httpbin.org/get?foo=bar')
>>> req2 = requests.Request('POST', 'http://httpbin.org/post?baz=qux')
>>> work_queue = [req1, req2]
>>> threads = driver.process(work_queue, thread_count = 2)
>>> [t.all_responses for t in threads]
[[<Response [200]>, <Response [200]>], [<Response [200]>, <Response [200]>]]
Evaluation of embedded statements in Requests:
>>> driver = pyrace.Driver()
>>> data = {'thread': '<<<self.thread_num>>>', 'rand': '<<<random.random()>>>'}
>>> request = requests.Request('POST', 'http://httpbin.org/post', data = data)
>>> threads = driver.process(request, thread_count = 2, do_eval = True)
>>> [t.response.json()['form'] for t in threads]
[{u'rand': u'0.405020220768', u'thread': u'0'}, {u'rand': u'0.466687005524', u'thread': u'1'}]
For more detailed demonstrations see the examples/ source code directory.