def test_acceptDescriptorInheritance(self): """ If a L{TwistdSlaveProcess} specifies some file descriptors to be inherited, they should be inherited by the subprocess. """ dspm = DelayedStartupProcessMonitor() dspm.reactor = InMemoryProcessSpawner() # Most arguments here will be ignored, so these are bogus values. slave = TwistdSlaveProcess( twistd = "bleh", tapname = "caldav", configFile = "/does/not/exist", id = 10, interfaces = '127.0.0.1', inheritFDs = [3, 7], inheritSSLFDs = [19, 25], ) dspm.addProcessObject(slave, {}) dspm.startService() self.addCleanup(dspm.consistency.cancel) # We can easily stub out spawnProcess, because caldav calls it, but a # bunch of callLater calls are buried in procmon itself, so we need to # use the real clock. oneProcessTransport = yield dspm.reactor.waitForOneProcess() self.assertEquals(oneProcessTransport.childFDs, {0: 'w', 1: 'r', 2: 'r', 3: 3, 7: 7, 19: 19, 25: 25})
def test_metaDescriptorInheritance(self): """ If a L{TwistdSlaveProcess} specifies a meta-file-descriptor to be inherited, it should be inherited by the subprocess, and a configuration argument should be passed that indicates to the subprocess. """ dspm = DelayedStartupProcessMonitor() dspm.reactor = InMemoryProcessSpawner() class FakeFD: def __init__(self, n): self.fd = n def fileno(self): return self.fd class FakeDispatcher: n = 3 def addSocket(self): self.n += 1 return FakeFD(self.n) # Most arguments here will be ignored, so these are bogus values. slave = TwistdSlaveProcess( twistd = "bleh", tapname = "caldav", configFile = "/does/not/exist", id = 10, interfaces = '127.0.0.1', metaSocket = FakeDispatcher().addSocket() ) dspm.addProcessObject(slave, {}) dspm.startService() self.addCleanup(dspm.consistency.cancel) oneProcessTransport = yield dspm.reactor.waitForOneProcess() self.assertIn("MetaFD=4", oneProcessTransport.args) self.assertEquals( oneProcessTransport.args[oneProcessTransport.args.index("MetaFD=4")-1], '-o', "MetaFD argument was not passed as an option" ) self.assertEquals(oneProcessTransport.childFDs, {0: 'w', 1: 'r', 2: 'r', 4: 4})