def test_workerSleep(self): """ twitter collector should sleep if not keywords found """ RawStreamQueue.drop_collection() SocketSession.drop_collection() kill = threading.Event() self.assertEqual(len(SocketSession.get_keywords()),0) w = TwitterWorker(kill) w.setDaemon(True) w.start() time.sleep(1) kill.set() self.assertEqual(RawStreamQueue.objects.count(), 0)
def test_worker(self): """ test single twitter worker """ s = SocketSession(ip='x') s.keywords = ['google','bieber'] s.save() kill = threading.Event() w = TwitterWorker(kill) w.setDaemon(True) w.start() # sleep is needed in order to get at least couple of tweets time.sleep(2) kill.set() self.assertGreater(RawStreamQueue.objects.count(), 0)
def test_worker(self): """ test single twitter worker """ s = SocketSession(ip='x') s.keywords = ['google','bieber'] s.save() kill = threading.Event() w = TwitterWorker(kill) w.setDaemon(True) w.start() while not RawStreamQueue.objects.count(): time.sleep(0.1) kill.set() self.assertGreater(RawStreamQueue.objects.count(), 0)
def test_workerSleep(self): """ twitter collector should sleep if not keywords found """ RawStreamQueue.drop_collection() SocketSession.drop_collection() kill = threading.Event() self.assertEqual(len(SocketSession.get_keywords()), 0) w = TwitterWorker(kill) w.setDaemon(True) w.start() time.sleep(1) kill.set() self.assertEqual(RawStreamQueue.objects.count(), 0)
def test_worker(self): """ test single twitter worker """ s = SocketSession(ip='x') s.keywords = ['google', 'bieber'] s.save() kill = threading.Event() w = TwitterWorker(kill) w.setDaemon(True) w.start() while not RawStreamQueue.objects.count(): time.sleep(0.1) kill.set() self.assertGreater(RawStreamQueue.objects.count(), 0)
def start(self): twitter_worker = TwitterWorker(self.kill) twitter_worker.setDaemon(True) twitter_worker.start() self.pool.append(twitter_worker)