class SocketListenerTestCase(unittest.TestCase): @deferred(timeout=30) def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix="test-connector-") self.socket = os.path.join(self.tmpdir, "sl.sock") self.sl = SocketListener(self.socket) return self.sl.startService() @deferred(timeout=30) def tearDown(self): d = self.sl.stopService() d.addCallback(lambda _x: shutil.rmtree(self.tmpdir)) return d @deferred(timeout=10) def testSocketToNode(self): """Transfert entre un socket UNIX et le bus""" msg_sent = "event|dummy|dummy|dummy|dummy|dummy" msg_sent_dict = { "type": "event", "timestamp": "dummy", "host": "dummy", "service": "dummy", "state": "dummy", "message": "dummy", } consumer = ConsumerStub() self.sl.consumer = consumer # client reactor.connectUNIX(self.socket, SendingFactory(msg_sent)) d = defer.Deferred() def get_output(): self.assertEqual(len(consumer.written), 1) msg = consumer.written[0] d.callback(msg) def check_msg(msg): print msg self.assertEquals(msg, msg_sent_dict) # On laisse un peu de temps pour traiter reactor.callLater(0.5, get_output) d.addCallback(check_msg) return d
def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix="test-connector-") self.socket = os.path.join(self.tmpdir, "sl.sock") self.sl = SocketListener(self.socket) return self.sl.startService()