-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_db.py
More file actions
40 lines (30 loc) · 807 Bytes
/
test_db.py
File metadata and controls
40 lines (30 loc) · 807 Bytes
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
#!/usr/bin/env python
# coding=utf-8
"""
test db connection pooling
"""
from __future__ import print_function, unicode_literals
import time
import threading
from threaded_db_pool import get_cursor
def test_basic_db_operation():
with get_cursor() as cur:
r = cur.execute("select 1")
assert r.fetchone()[0] == 1
def _basic_db_operation():
with get_cursor() as cur:
r = cur.execute("select 1")
time.sleep(1)
assert r.fetchone()[0] == 1
def test_concurrent_db_operation():
start = time.time()
tids = []
for _ in range(10):
tid = threading.Thread(target=_basic_db_operation, args=())
tid.start()
tids.append(tid)
for tid in tids:
tid.join()
end = time.time()
assert True
assert end - start < 2