|  |  |  | @ -1,6 +1,7 @@ | 
		
	
		
			
				|  |  |  |  | from tests import RQTestCase | 
		
	
		
			
				|  |  |  |  | from tests import testjob | 
		
	
		
			
				|  |  |  |  | from tests import testjob, failing_job | 
		
	
		
			
				|  |  |  |  | from rq import Queue, Worker | 
		
	
		
			
				|  |  |  |  | from rq.job import Job | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class TestWorker(RQTestCase): | 
		
	
	
		
			
				
					|  |  |  | @ -19,4 +20,33 @@ class TestWorker(RQTestCase): | 
		
	
		
			
				|  |  |  |  |         fooq.enqueue(testjob, name='Frank') | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(w.work(burst=True), True, 'Expected at least some work done.') | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     def test_work_is_unreadable(self): | 
		
	
		
			
				|  |  |  |  |         """Worker processes unreadable job.""" | 
		
	
		
			
				|  |  |  |  |         q = Queue() | 
		
	
		
			
				|  |  |  |  |         failure_q = Queue('failure') | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(failure_q.count, 0) | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(q.count, 0) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         # NOTE: We have to fake this enqueueing for this test case. | 
		
	
		
			
				|  |  |  |  |         # What we're simulating here is a call to a function that is not | 
		
	
		
			
				|  |  |  |  |         # importable from the worker process. | 
		
	
		
			
				|  |  |  |  |         job = Job(failing_job, 3) | 
		
	
		
			
				|  |  |  |  |         pickled_job = job.pickle() | 
		
	
		
			
				|  |  |  |  |         invalid_data = pickled_job.replace( | 
		
	
		
			
				|  |  |  |  |                 'failing_job', 'nonexisting_job') | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         # We use the low-level internal function to enqueue any data (bypassing | 
		
	
		
			
				|  |  |  |  |         # validity checks) | 
		
	
		
			
				|  |  |  |  |         q._push(invalid_data) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(q.count, 1) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         # All set, we're going to process it | 
		
	
		
			
				|  |  |  |  |         w = Worker([q]) | 
		
	
		
			
				|  |  |  |  |         w.work(burst=True)   # should silently pass | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(q.count, 0) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         self.assertEquals(failure_q.count, 1) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | 
 |