Fix unit tests

This commit is contained in:
Andrey Pohilko 2014-02-11 15:08:38 +04:00
parent cbafd39741
commit edb6cdf514
2 changed files with 21 additions and 14 deletions

View File

@ -1,11 +1,12 @@
from Tank.Plugins.Aggregator import AggregatorPlugin, AbstractReader,\
SecondAggregateDataTotalItem, SecondAggregateDataItem
from Tests.TankTests import TankTestCase
import time
import unittest
from Tank.Plugins.Aggregator import AggregatorPlugin, AbstractReader, \
SecondAggregateDataTotalItem
from Tests.TankTests import TankTestCase
class AggregatorPluginTestCase(TankTestCase):
class AggregatorPluginTestCase(TankTestCase):
def setUp(self):
core = self.get_core()
core.load_configs(['config/aggregator.conf'])
@ -13,7 +14,7 @@ class AggregatorPluginTestCase(TankTestCase):
def tearDown(self):
del self.foo
self.foo = None
self.foo = None
def test_run(self):
self.foo.configure()
@ -25,7 +26,7 @@ class AggregatorPluginTestCase(TankTestCase):
while self.foo.is_test_finished() < 0 and retry < 5:
self.foo.log.debug("Not finished")
time.sleep(0.01)
retry = retry + 1
retry += 1
self.foo.end_test(0)
def test_run_final_read(self):
@ -34,22 +35,27 @@ class AggregatorPluginTestCase(TankTestCase):
self.foo.reader = FakeReader(self.foo)
self.foo.start_test()
self.foo.end_test(0)
def test_run_interrupt(self):
self.foo.configure()
self.foo.prepare_test()
self.foo.start_test()
time.sleep(2)
self.foo.end_test(0)
def test_total_quantiles(self):
self.foo=SecondAggregateDataTotalItem()
self.foo.total_count=1000
self.foo.times_dist={2: {'count': 14, 'to': 3, 'from': 2}, 3: {'count': 815, 'to': 4, 'from': 3}, 4: {'count': 55, 'to': 5, 'from': 4}, 5: {'count': 29, 'to': 6, 'from': 5}, 6: {'count': 26, 'to': 7, 'from': 6}, 7: {'count': 27, 'to': 8, 'from': 7}, 8: {'count': 14, 'to': 9, 'from': 8}, 9: {'count': 8, 'to': 10, 'from': 9}, 10:{'count': 12, 'to': 20, 'from': 10}}
res=self.foo.calculate_total_quantiles()
exp={98.0: 9, 99.0: 20, 100.0: 20, 75.0: 4, 80.0: 4, 50.0: 4, 25.0: 4, 90.0: 6, 95.0: 8}
self.foo = SecondAggregateDataTotalItem()
self.foo.total_count = 1000
self.foo.times_dist = {2: {'count': 14, 'to': 3, 'from': 2}, 3: {'count': 815, 'to': 4, 'from': 3},
4: {'count': 55, 'to': 5, 'from': 4}, 5: {'count': 29, 'to': 6, 'from': 5},
6: {'count': 26, 'to': 7, 'from': 6}, 7: {'count': 27, 'to': 8, 'from': 7},
8: {'count': 14, 'to': 9, 'from': 8}, 9: {'count': 8, 'to': 10, 'from': 9},
10: {'count': 12, 'to': 20, 'from': 10}}
res = self.foo.calculate_total_quantiles()
exp = {98.0: 9, 99.0: 20, 100.0: 20, 75.0: 4, 85.0: 5, 80.0: 4, 50.0: 4, 25.0: 4, 90.0: 6, 95.0: 8}
self.assertDictEqual(exp, res)
class FakeReader(AbstractReader):
pass

View File

@ -28,6 +28,7 @@ class Custom_TestCase(unittest.TestCase):
pass
#def tearDown(self):
# self.foo.dispose()
# self.foo = None
@ -125,7 +126,7 @@ class NetTxRxTestCase(unittest.TestCase):
time.sleep(2)
self.assertNotEquals(['0', '0'], self.foo.check())
socket.gethostbyname("google.com")
socket.create_connection("google.com", 5000)
socket.create_connection(("google.com", 80), 5000)
time.sleep(2)
print self.foo.check()