'L{DistTrialRunner} waits for the worker processes to stop when the
reactor is stopping, and then unlocks the test directory, not trying to
stop the reactor again.'

def test_runWaitForProcessesDeferreds(self):

    functions = []
    workers = []
    class FakeReactorWithEvent(FakeReactor, ):
        def spawnProcess(self, worker, *args, **kwargs):
            worker.makeConnection(FakeTransport())
            workers.append(worker)
        def addSystemEventTrigger(oself, phase, event, function):
            self.assertEqual('before', phase)
            self.assertEqual('shutdown', event)
            functions.append(function)
    workingDirectory = self.runner._workingDirectory
    fakeReactor = FakeReactorWithEvent()
    self.runner.run(TestCase(), fakeReactor)
    def check(ign):
        return deferLater(reactor, 0, realCheck)
    def realCheck():
        localLock = FilesystemLock((workingDirectory + '.lock'))
        self.assertTrue(localLock.lock())
        self.assertEqual(0, fakeReactor.stopCount)
    workers[0].processEnded(Failure(CONNECTION_DONE))
    return functions[0]().addCallback(check)
