]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add unit test for "advertised_ip_addresses" feature and fix bug in that feature uncov...
authorZooko O'Whielacronx <zooko@zooko.com>
Wed, 23 May 2007 22:08:55 +0000 (15:08 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Wed, 23 May 2007 22:08:55 +0000 (15:08 -0700)
src/allmydata/node.py
src/allmydata/test/test_node.py [new file with mode: 0644]

index 750e61fb1072d45baed4706f872872919ca117b2..c55fd413fd771011c8746c1c7b6e22cdd05acde6 100644 (file)
@@ -111,7 +111,7 @@ class Node(service.MultiService):
                     (addr, dummy, aportnum,) = mo.groups()
                     if aportnum is None:
                         aportnum = portnum
-                    addresses.append("%s:%d" % (addr, aportnum,))
+                    addresses.append("%s:%d" % (addr, int(aportnum),))
         except EnvironmentError:
             pass
 
diff --git a/src/allmydata/test/test_node.py b/src/allmydata/test/test_node.py
new file mode 100644 (file)
index 0000000..ad223a8
--- /dev/null
@@ -0,0 +1,43 @@
+
+from twisted.trial import unittest
+from twisted.internet import defer, reactor
+from twisted.python import log
+
+from foolscap import Tub, Referenceable
+from foolscap.eventual import flushEventualQueue
+from twisted.application import service
+from allmydata.node import Node
+from allmydata.util import idlib, testutil
+
+class LoggingMultiService(service.MultiService):
+    def log(self, msg):
+        pass
+
+class TestNode(Node):
+    CERTFILE='DEFAULT_CERTFILE_BLANK'
+    PORTNUMFILE='DEFAULT_PORTNUMFILE_BLANK'
+
+class TestCase(unittest.TestCase, testutil.SignalMixin):
+    def setUp(self):
+        self.parent = LoggingMultiService()
+        self.parent.startService()
+    def tearDown(self):
+        log.msg("%s.tearDown" % self.__class__.__name__)
+        d = defer.succeed(None)
+        d.addCallback(lambda res: self.parent.stopService())
+        d.addCallback(flushEventualQueue)
+        return d
+
+    def test_advertised_ip_addresses(self):
+        open('advertised_ip_addresses','w').write('1.2.3.4:5')
+
+        n = TestNode()
+        n.setServiceParent(self.parent)
+        d = n.when_tub_ready()
+
+        def _check_addresses(ignored_result):
+            self.failUnless("1.2.3.4:5" in n.tub.registerReference(n), n.tub.registerReference(n))
+
+        d.addCallback(_check_addresses)
+        return d
+