Permalink
Browse files

New test added (for parallel queries)

  • Loading branch information...
1 parent 72865a6 commit f30e7a4c3953d534f85e6cf8a6631073bda4663d @deavid committed Jan 7, 2011
Showing with 27 additions and 7 deletions.
  1. +27 −7 test/test_main.py
View
@@ -10,10 +10,16 @@
class TestJSONBasics(unittest.TestCase):
def setUp(self):
+ """
+ Start the server and connect the client for every test.
+ """
testserver1.start()
self.conn = bjsonrpc.connect()
def tearDown(self):
+ """
+ Stop the server every test.
+ """
testserver1.stop(self.conn)
#def test_zzz_stopserver(self): # workaround for teardownclass in python <2.7
@@ -26,7 +32,7 @@ def test_call(self):
rcall = self.conn.call
for i in range(30):
pong = rcall.ping()
- self.assertEqual(pong, "pong")
+ self.assertEqual(pong, "pong", "Server MUST return 'pong' when ping is called")
def test_call2params(self):
"""
@@ -48,7 +54,7 @@ def test_call2params(self):
]
for x, y in pairs:
added = rcall.add2(x, y)
- self.assertEqual(added, x+y)
+ self.assertEqual(added, x+y, "Server FAILED to add remotely the two params")
def test_callNparams(self):
@@ -59,7 +65,7 @@ def test_callNparams(self):
for i in range(50):
tosum = [ x + i * 3 + x % 10 for x in range(10+i*4)]
added = rcall.addN(*tosum)
- self.assertEqual(added, sum(tosum))
+ self.assertEqual(added, sum(tosum), "Server FAILED to sum N params remotely")
def test_float(self):
@@ -73,8 +79,8 @@ def test_float(self):
tosum = [ math.sin(x + i * 3 + x % 10) * 1999 / float(i+math.pi) for x in range(10+i*4)]
added = rcall.addN(*tosum)
- self.assertNotEqual(added, int(added)) # Ok, this can be equal, but this test should fail in this case
- self.assertAlmostEqual(added, sum(tosum))
+ self.assertNotEqual(added, int(added), "Test invalid! Should try only floats, not integers.") # Ok, this can be equal, but this test should fail in this case
+ self.assertAlmostEqual(added, sum(tosum), 6, "Float precision error when doing a remote sum of params")
def test_nested_list(self):
"""
@@ -90,15 +96,15 @@ def test_nested_list(self):
nlist.append(ilist)
result = rcall.addnlist(nlist)
- self.assertEqual(result, tot)
+ self.assertEqual(result, tot, "Failed to remotely sum elements of a nested list")
def test_tuple(self):
"""
Tuples should be converted to lists
"""
rcall = self.conn.call
result = rcall.getabc()
- self.assertTrue(isinstance(result, ListType))
+ self.assertTrue(isinstance(result, ListType),"JSON library should convert tuples to lists!")
def test_kwparams(self):
@@ -125,6 +131,20 @@ def test_commonerrors(self):
self.assertRaises(ServerError, rcall.getabc, j=32) # "j" parameter unknown
self.assertRaises(ServerError, rcall.add, 2, 3, 4,) # too parameters
+ def test_methodNparams(self):
+ """
+ Get remote method for call with N parameters
+ """
+ rmethod = self.conn.method
+ lmethods = []
+ total = 0
+ for i in range(50):
+ tosum = [ x + i * 3 + x % 10 for x in range(10+i*4)]
+ total += sum(tosum)
+ lmethods.append(rmethod.addN(*tosum))
+
+ remote_total = sum([ m.value for m in lmethods ])
+ self.assertEqual(total, remote_total, "Server FAILED to sum N params remotely handling paralell queries")

0 comments on commit f30e7a4

Please sign in to comment.