Anyway, here the test is, in case anyone cares. I thought that you
might like to hear good news, rather than bugs, from me for once. To
run it place the whole thing in a file called nodetest.py in circlelib
and run "python nodetest.py -v".
>>>> begin nodetest.py
from __future__ import generators
import time
import unittest
import hash
import node
import proxy
import utility
class Test(unittest.TestCase):
def makeConnectedNodes(self, numNodes):
nodes = [node.Node() for x in range(numNodes)]
for n in nodes: n.start(proxy=None)
connected = 0
while not connected:
utility._daemon_action_timeout()
connected = 1
for n in nodes:
if not n.is_connected(): connected = 0
return nodes
def testRpc(self):
n0, n1 = self.makeConnectedNodes(numNodes=2)
class Handler:
def handle(self, request, address, callId):
return "rpc handled"
n0.add_handler(msg_name="nodetest", how=Handler())
finishedDict = {"finished":0}
def callMethod():
ticket, template, wait = n1.call(address=n0.address,
query=("nodetest",))
if wait: yield "call", (n1, ticket)
result = n1.get_reply(ticket,template)
self.assertEquals(result, "rpc handled")
finishedDict["finished"] = 1
utility.start_thread(callMethod())
while not finishedDict["finished"]:
utility._daemon_action_timeout()
def testData(self):
n0, n1 = self.makeConnectedNodes(numNodes=2)
publishedName = "testData-%f" % time.time()
publishedData = {"type":"test-data", "attr":"value"}
n0.publish(name=hash.hash_of(publishedName), info=publishedData)
for x in range(1000):
time.sleep(0.01)
utility._daemon_action_timeout()
pipe = n0.retrieve(hash.hash_of(publishedName))
foundAddress = None
try:
while not pipe.finished():
for address, data in pipe.read_all():
assert not foundAddress
self.assertEquals(data, publishedData)
foundAddress = address
utility._daemon_action_timeout()
time.sleep(1)
finally:
pipe.stop()
self.assertEquals(foundAddress, n0.address)
if __name__ == "__main__":
unittest.main()
<<<< end nodetest.py
_______________________________________________
Circle-discuss mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/circle-discuss