Dear list

I may need som advise to get som testing wokring.

I have a server for service a, which creates a client for service b to get som data:

class StateHandler(object):
    implements(State.Iface)

    def __init__(self):
        #do stuff
        self.loaddata()

    @inlineCallbacks
    def loaddata(self):
        try:
            conn = yield ClientCreator(
                reactor,
                TTwisted.ThriftClientProtocol,
                dsClient,
                TBinaryProtocol.TBinaryProtocolFactory()).connectTCP("10.70.10.30", 7246)
                data = yield conn.client.getAllAuthenticationData()
            #process data
            conn.transport.loseConnection()

I use trail to test this service, code is bolow:

class TestStateStore(unittest.TestCase):

    @defer.inlineCallbacks
    def setUp(self):
        self.handler = StateHandler()
        self.processor = State.Processor(self.handler)
        self.pfactory = TBinaryProtocol.TBinaryProtocolFactory()
        self.server = reactor.listenTCP(
            0,
            TTwisted.ThriftServerFactory(self.processor, self.pfactory),
            interface="127.0.0.1")
        self.portNo = self.server.getHost().port
        self.txclient = yield ClientCreator(
            reactor,
            TTwisted.ThriftClientProtocol,
            State.Client,
            self.pfactory).connectTCP("127.0.0.1", self.portNo)
        self.client = self.txclient.client

    @defer.inlineCallbacks
    def tearDown(self):
        self.txclient.transport.loseConnection()
        yield self.server.stopListening()


    def test_dummy(self):
        self.assertEquals(True, True)

When I run test it fails with the following error message.

ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
<DelayedCall 0x29d99e0 [29.9931809902s] called=0 cancelled=0 Client.failIfNotConnected(TimeoutError('',))>

oc.tests.test_state_service.TestStateStore.test_dummy
===============================================================================
[ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
Selectables:
<<class 'twisted.internet.tcp.Client'> to ('10.70.10.30', 7246) at 29d2c10>

oc.tests.test_state_service.TestStateStore.test_dummy
-------------------------------------------------------------------------------
Ran 1 tests in 0.010s

To me it seems like Trail shuts down the reactor and throws an error, due to the fact that the reactor is unclean, because the server client is still active, or at least not cleaned up. How do I work around this problem, any help is very appreciated. 

--
Jonas Brunsgaard