'L{DatagramProtocol.stopProtocol} is called asynchronously (ie, not
re-entrantly) when C{stopListening} is used to stop the datagram
transport.'

def test_stopProtocolScheduling(self):

    class DisconnectingProtocol(DatagramProtocol, ):
        started = False
        stopped = False
        inStartProtocol = False
        stoppedInStart = False
        def startProtocol(self):
            self.started = True
            self.inStartProtocol = True
            self.transport.stopListening()
            self.inStartProtocol = False
        def stopProtocol(self):
            self.stopped = True
            self.stoppedInStart = self.inStartProtocol
            reactor.stop()
    reactor = self.buildReactor()
    protocol = DisconnectingProtocol()
    self.getListeningPort(reactor, protocol)
    self.runReactor(reactor)
    self.assertTrue(protocol.started)
    self.assertTrue(protocol.stopped)
    self.assertFalse(protocol.stoppedInStart)
