fix: tests
This commit is contained in:
parent
94ae43d116
commit
e6af7abc04
@ -17,6 +17,7 @@ class SampleData():
|
|||||||
"sample":"data"
|
"sample":"data"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RepSampleData(ReplicatedDatablock):
|
class RepSampleData(ReplicatedDatablock):
|
||||||
def serialize(self,data):
|
def serialize(self,data):
|
||||||
import pickle
|
import pickle
|
||||||
@ -28,6 +29,7 @@ class RepSampleData(ReplicatedDatablock):
|
|||||||
|
|
||||||
return pickle.loads(data)
|
return pickle.loads(data)
|
||||||
|
|
||||||
|
|
||||||
class TestDataFactory(unittest.TestCase):
|
class TestDataFactory(unittest.TestCase):
|
||||||
def test_data_factory(self):
|
def test_data_factory(self):
|
||||||
factory = ReplicatedDataFactory()
|
factory = ReplicatedDataFactory()
|
||||||
@ -38,7 +40,7 @@ class TestDataFactory(unittest.TestCase):
|
|||||||
self.assertEqual(isinstance(rep_sample,RepSampleData), True)
|
self.assertEqual(isinstance(rep_sample,RepSampleData), True)
|
||||||
|
|
||||||
|
|
||||||
class TestDataReplication(unittest.TestCase):
|
class TestClient(unittest.TestCase):
|
||||||
def __init__(self,methodName='runTest'):
|
def __init__(self,methodName='runTest'):
|
||||||
unittest.TestCase.__init__(self, methodName)
|
unittest.TestCase.__init__(self, methodName)
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ class TestDataReplication(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
def test_register_client_data(self):
|
def test_register_client_data(self):
|
||||||
# Setup
|
# Setup environment
|
||||||
factory = ReplicatedDataFactory()
|
factory = ReplicatedDataFactory()
|
||||||
factory.register_type(SampleData, RepSampleData)
|
factory.register_type(SampleData, RepSampleData)
|
||||||
|
|
||||||
@ -75,31 +77,31 @@ class TestDataReplication(unittest.TestCase):
|
|||||||
client2 = Client(factory=factory, id="client_2")
|
client2 = Client(factory=factory, id="client_2")
|
||||||
client2.connect(port=5560)
|
client2.connect(port=5560)
|
||||||
|
|
||||||
|
# Test the key registering
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
data_sample_key = client.register(SampleData())
|
data_sample_key = client.register(SampleData())
|
||||||
|
|
||||||
#Waiting for server to receive the datas
|
#Waiting for server to receive the datas
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
test_key = client2._rep_store[data_sample_key]
|
rep_test_key = client2._rep_store[data_sample_key].uuid
|
||||||
|
|
||||||
|
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
client2.disconnect()
|
client2.disconnect()
|
||||||
server.stop()
|
server.stop()
|
||||||
|
|
||||||
#Check if the server receive them
|
|
||||||
self.assertNotEqual(test_key, None)
|
self.assertEqual(rep_test_key, data_sample_key)
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(TestDataFactory('test_data_factory'))
|
suite.addTest(TestDataFactory('test_data_factory'))
|
||||||
suite.addTest(TestDataReplication('test_empty_snapshot'))
|
suite.addTest(TestClient('test_empty_snapshot'))
|
||||||
suite.addTest(TestDataReplication('test_register_client_data'))
|
suite.addTest(TestClient('test_register_client_data'))
|
||||||
|
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# unittest.main()
|
|
||||||
runner = unittest.TextTestRunner(failfast=True)
|
runner = unittest.TextTestRunner(failfast=True)
|
||||||
runner.run(suite())
|
runner.run(suite())
|
Loading…
x
Reference in New Issue
Block a user