-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.py
92 lines (78 loc) · 3.48 KB
/
test-runner.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# encoding: utf=8
import logging, datetime, sys
from mongodbtest import *
from rethinkdbtest import *
from postgrestest import *
class TestRunner():
def __init__(self, count):
self.count = count
def run(self):
summary_logger = logging.getLogger('summary')
summary_file_handler = logging.FileHandler('log/summary.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
summary_file_handler.setFormatter(formatter)
summary_logger.addHandler(summary_file_handler)
summary_logger.setLevel(logging.INFO)
detail_logger = logging.getLogger('detail')
detail_file_handler = logging.FileHandler('log/detail.log')
detail_file_handler.setFormatter(formatter)
detail_logger.addHandler(detail_file_handler)
detail_logger.setLevel(logging.INFO)
count = int(self.count)
tests = [MongoDBTest(count), RethinkDBTest(count), PostgresTest(count)]
for test in tests:
classname = test.__class__.__name__
summary_logger.info('Starting {0} tests...'.format(classname))
suitestart = datetime.datetime.now()
test1start = datetime.datetime.now()
summary_logger.info('starting performance test #1: insert {0} records'.format(test.count))
for i in range (1, test.count):
test.insert(i)
test1duration = datetime.datetime.now() - test1start
summary_logger.info('ending performance test #1: insert {0} records, Duration: {1} seconds'.format(test.count, test1duration.total_seconds()))
test2start = datetime.datetime.now()
summary_logger.info('starting performance test #2: reading {0} records'.format(test.count))
for i in range (1, test.count):
item = test.select(i)
detail_logger.info(item)
test2duration = datetime.datetime.now() - test2start
summary_logger.info('ending performance test #2: reading {0} records, Duration: {1} seconds'.format(test.count, test2duration.total_seconds()))
heavy_pct_count=count * .9
test3start = datetime.datetime.now()
summary_logger.info('starting performance test #3: write heavily ({0} writes, {1} reads)'.format(heavy_pct_count, test.count-heavy_pct_count))
j = 0
for i in range (test.count, test.count*2):
j+=1
if j % 10 == 0:
item = test.select(i)
detail_logger.info(item)
j = 0
else:
item = test.insert(i)
test3duration = datetime.datetime.now() - test3start
summary_logger.info('ending performance test #3: write heavily ({0} writes, {1} reads), Duration: {2} seconds'.format(heavy_pct_count, test.count-heavy_pct_count, test3duration.total_seconds()))
test4start = datetime.datetime.now()
summary_logger.info('starting performance test #4: read heavily ({0} reads, {1} writes)'.format(heavy_pct_count, test.count-heavy_pct_count))
j = 0
for i in range (test.count*2, test.count*3):
j+=1
if j % 10 == 0:
item = test.insert(i)
else:
item = test.select(i)
detail_logger.info(item)
j = 0
test4duration = datetime.datetime.now() - test4start
summary_logger.info('ending performance test #4: read heavily ({0} reads, {1} writes), Duration: {2} seconds'.format(heavy_pct_count, test.count-heavy_pct_count, test4duration.total_seconds() ))
totalduration = datetime.datetime.now() - suitestart
summary_logger.info('Ending {0} tests, Total Duration: {1} seconds'.format(classname, totalduration.total_seconds()))
def main():
try:
count = sys.argv[1]
except:
print 'python test-runner.py [count]'
sys.exit(-1)
TestRunner(count).run()
if __name__=='__main__':
main()