Beispiel #1
0
class TestComm(unittest.TestCase):
    def setUp(self):
        self.config = {"offer_expiry_interval": 30, "ep_expiry_interval": 30}
        self.hcomm = HTTPComm(self.config)
        self.msg = {"msgid": 2, "a": "b"}
        self.httpd = TestServer("localhost", 8080)
        self.httpd.start()
        self.tcomm = ThreadedComm(self.hcomm)
        self.tcomm.add_agent(MockAgent())

    def tearDown(self):
        self.httpd.shutdown()

    def test_post_message(self):
        self.assertTrue(self.hcomm.post_message(self.msg))

    def test_poll_and_dispatch(self):
        self.hcomm.poll_and_dispatch()
        self.assertEqual(self.hcomm.lastpoll, 1)
        self.hcomm.poll_and_dispatch()
        self.assertEqual(self.hcomm.lastpoll, 1)

    def test_threadcomm(self):
        self.tcomm.start()
        time.sleep(2)
        self.hcomm.post_message(self.msg)
        self.tcomm.post_message(self.msg)
        self.tcomm.poll_and_dispatch()
        time.sleep(2)
        self.tcomm.stop()
Beispiel #2
0
class TestComm(unittest.TestCase):
    def setUp(self):
        self.config = {"offer_expiry_interval": 30, "ep_expiry_interval": 30}
        self.hcomm = HTTPComm(self.config)
        self.msg = {"msgid": 2, "a": "b"}
        self.httpd = TestServer("localhost", 8080)
        self.httpd.start()
        self.tcomm = ThreadedComm(self.hcomm)
        self.tcomm.add_agent(MockAgent())

    def tearDown(self):
        self.httpd.shutdown()

    def test_post_message(self):
        self.assertTrue(self.hcomm.post_message(self.msg))

    def test_poll_and_dispatch(self):
        self.hcomm.poll_and_dispatch()
        self.assertEqual(self.hcomm.lastpoll, 1)
        self.hcomm.poll_and_dispatch()
        self.assertEqual(self.hcomm.lastpoll, 1)

    def test_threadcomm(self):
        self.tcomm.start()
        time.sleep(2)
        self.hcomm.post_message(self.msg)
        self.tcomm.post_message(self.msg)
        self.tcomm.poll_and_dispatch()
        time.sleep(2)
        self.tcomm.stop()
Beispiel #3
0
class TestThreadedComm(unittest.TestCase):

  def setUp(self):
    self.config = { 'offer_expiry_interval' : 1}
    self.url = 'http://localhost:8080/messages'
    self.http_interface = MockHTTPInterface()
    self.agent = MockAgent()
    self.tcomm = ThreadedComm(self.config, self.url)
    self.tcomm.http_interface = self.http_interface
    self.tcomm.add_agent(self.agent)
    self.tcomm.start()
    time.sleep(self.tcomm.sleep_time * 2)

  def tearDown(self):
    time.sleep(self.tcomm.sleep_time * 2)
    self.tcomm.stop()

  def test_post_message(self):
    self.http_interface.reset()
    self.assertTrue(self.tcomm.post_message({}))
    time.sleep(self.tcomm.sleep_time * 2)
    self.assertEqual(len(self.http_interface.post_log), 1)

  def test_poll_and_dispatch(self):
    self.http_interface.reset()
    self.agent.reset()
    time.sleep(self.tcomm.sleep_time * 2)
    self.tcomm.poll_and_dispatch()
    self.assertTrue(len(self.http_interface.poll_log) > 0)
    self.assertTrue(len(self.agent.dispatch_log) > 0)
    self.assertNotEqual(self.tcomm.lastpoll, -1)