'Run the Conch server against the Conch client.  Set up several different
channels which exercise different behaviors and wait for them to
complete.  Verify that the channels with errors log them.'

def test_subsystemsAndGlobalRequests(self):

    channel = self._ourServerOurClientTest()
    def cbSubsystem(channel):
        self.channel = channel
        return self.assertFailure(channel.conn.sendRequest(channel, 'subsystem', common.NS('not-crazy'), 1), Exception)
    channel.addCallback(cbSubsystem)
    def cbNotCrazyFailed(ignored):
        channel = self.channel
        return channel.conn.sendRequest(channel, 'subsystem', common.NS('crazy'), 1)
    channel.addCallback(cbNotCrazyFailed)
    def cbGlobalRequests(ignored):
        channel = self.channel
        d1 = channel.conn.sendGlobalRequest('foo', 'bar', 1)
        d2 = channel.conn.sendGlobalRequest('foo-2', 'bar2', 1)
        d2.addCallback(self.assertEqual, 'data')
        d3 = self.assertFailure(channel.conn.sendGlobalRequest('bar', 'foo', 1), Exception)
        return defer.gatherResults([d1, d2, d3])
    channel.addCallback(cbGlobalRequests)
    def disconnect(ignored):
        self.assertEqual(self.realm.avatar.globalRequests, {'foo': 'bar', 'foo_2': 'bar2'})
        channel = self.channel
        channel.conn.transport.expectedLoseConnection = True
        channel.conn.serviceStopped()
        channel.loseConnection()
    channel.addCallback(disconnect)
    return channel
