]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_node.py
add unit test for "advertised_ip_addresses" feature and fix bug in that feature uncov...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_node.py
1
2 from twisted.trial import unittest
3 from twisted.internet import defer, reactor
4 from twisted.python import log
5
6 from foolscap import Tub, Referenceable
7 from foolscap.eventual import flushEventualQueue
8 from twisted.application import service
9 from allmydata.node import Node
10 from allmydata.util import idlib, testutil
11
12 class LoggingMultiService(service.MultiService):
13     def log(self, msg):
14         pass
15
16 class TestNode(Node):
17     CERTFILE='DEFAULT_CERTFILE_BLANK'
18     PORTNUMFILE='DEFAULT_PORTNUMFILE_BLANK'
19
20 class TestCase(unittest.TestCase, testutil.SignalMixin):
21     def setUp(self):
22         self.parent = LoggingMultiService()
23         self.parent.startService()
24     def tearDown(self):
25         log.msg("%s.tearDown" % self.__class__.__name__)
26         d = defer.succeed(None)
27         d.addCallback(lambda res: self.parent.stopService())
28         d.addCallback(flushEventualQueue)
29         return d
30
31     def test_advertised_ip_addresses(self):
32         open('advertised_ip_addresses','w').write('1.2.3.4:5')
33
34         n = TestNode()
35         n.setServiceParent(self.parent)
36         d = n.when_tub_ready()
37
38         def _check_addresses(ignored_result):
39             self.failUnless("1.2.3.4:5" in n.tub.registerReference(n), n.tub.registerReference(n))
40
41         d.addCallback(_check_addresses)
42         return d
43