/
test-3-sqlite-server-http-1.py
62 lines (53 loc) · 1.22 KB
/
test-3-sqlite-server-http-1.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
#!/usr/bin/env python3
#
#
# test-3-sqlite-server-http-1.py
# Tester for sqlite-server-http-1.py (Very simple SQLite Server (HTTP))
# (c) Noprianto <nop@noprianto.com>
# 2016
# License: GPL
# https://github.com/nopri/code/
#
# Tested in Python 3.4 using only standard library
#
import base64
import json
import threading
import urllib.request
URL = 'http://localhost:8080/?q='
MAX_THREADS = 2000
def build_query(q, c=False):
q = q.encode()
q = base64.encodebytes(q).decode().strip()
ret = URL + q
if c:
ret += '&c=1'
return ret
def test_query():
q = 'select undefined_function_test()'
u = build_query(q)
f = urllib.request.urlopen(u)
r = json.loads(f.read().decode())
#
msg = '[%s][response: %s]' %(
threading.current_thread().name,
r
)
print(msg)
#
q = 'create tables error'
u = build_query(q)
f = urllib.request.urlopen(u)
r = json.loads(f.read().decode())
#
msg = '[%s][response: %s]' %(
threading.current_thread().name,
r
)
print(msg)
def main():
for i in range(MAX_THREADS):
t = threading.Thread(target=test_query)
t.start()
if __name__ == '__main__':
main()