switched to threads, so that unit test coverage reports properly

This commit is contained in:
fawce
2012-02-12 23:09:17 -05:00
parent 269b72f356
commit 21afa42f3a
2 changed files with 11 additions and 4 deletions
+9 -2
View File
@@ -5,6 +5,7 @@ import multiprocessing
import zmq
import json
import copy
import threading
import qsim.util as qutil
import qsim.messaging as qmsg
@@ -32,7 +33,7 @@ class Simulator(object):
self.merge_address = "tcp://127.0.0.1:{port}".format(port=10103)
self.result_address = "tcp://127.0.0.1:{port}".format(port=10104)
def launch(self):
def simulate(self):
self.feed = DataFeed(self.sources.keys(), self.data_address, self.feed_address, qmsg.Sync(self,"DataFeed"))
self.launch_component("DataFeed", self.feed)
for name, data_source in self.sources.iteritems():
@@ -66,8 +67,14 @@ class Simulator(object):
self.sync_components()
client_proc.join() #wait for client to complete processing
def launch_component(self, name, component):
qutil.LOGGER.info("starting {name}".format(name=name))
thread = threading.Thread(target=component.run)
thread.start()
return thread
def launch_component_proc(self, name, component):
qutil.LOGGER.info("starting {name}".format(name=name))
proc = multiprocessing.Process(target=component.run)
proc.start()
+2 -2
View File
@@ -30,7 +30,7 @@ class MessagingTestCase(unittest.TestCase):
sources = {"ret1":ret1, "ret2":ret2}
client = TestClient(self, expected_msg_count=800)
sim = Simulator(sources, {}, client)
sim.launch()
sim.simulate()
self.assertEqual(sim.feed.data_buffer.pending_messages(), 0,
"The feed should be drained of all messages, found {n} remaining."
@@ -51,7 +51,7 @@ class MessagingTestCase(unittest.TestCase):
transforms = {"mavg1":mavg1, "mavg2":mavg2}
client = TestClient(self, expected_msg_count=800)
sim = Simulator(sources, transforms, client)
sim.launch()
sim.simulate()
self.assertEqual(sim.feed.data_buffer.pending_messages(), 0, "The feed should be drained of all messages.")