3 from twisted.trial import unittest
4 from twisted.internet import defer
5 from twisted.python import log
7 from foolscap.eventual import flushEventualQueue
8 from twisted.application import service
9 from allmydata.node import Node, formatTimeTahoeStyle
10 from allmydata.util import testutil
12 class LoggingMultiService(service.MultiService):
17 CERTFILE='DEFAULT_CERTFILE_BLANK'
18 PORTNUMFILE='DEFAULT_PORTNUMFILE_BLANK'
20 class TestCase(unittest.TestCase, testutil.SignalMixin):
22 self.parent = LoggingMultiService()
23 self.parent.startService()
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)
31 def test_advertised_ip_addresses(self):
32 open('advertised_ip_addresses','w').write('1.2.3.4:5')
35 n.setServiceParent(self.parent)
36 d = n.when_tub_ready()
38 def _check_addresses(ignored_result):
39 self.failUnless("1.2.3.4:5" in n.tub.registerReference(n), n.tub.registerReference(n))
41 d.addCallback(_check_addresses)
46 n.log("this is a message")
47 n.log("with %d %s %s", args=(2, "interpolated", "parameters"))
48 n.log("with bogus %d expansion", args=("not an integer",))
50 def test_timestamp(self):
51 # this modified logger doesn't seem to get used during the tests,
52 # probably because we don't modify the LogObserver that trial
53 # installs (only the one that twistd installs). So manually exercise
55 t = formatTimeTahoeStyle("ignored", time.time())
56 self.failUnless("Z" in t)
57 t2 = formatTimeTahoeStyle("ignored", int(time.time()))
58 self.failUnless("Z" in t2)