old_contents: import thoonk
  import unittest
  import math
  
  class TestJob(unittest.TestCase):
  
      def __init__(self, *args, **kwargs):
          unittest.TestCase.__init__(self, *args, **kwargs)
  
      def setUp(self):
          self.ps = thoonk.Pubsub(db=10, listen=True)
          self.ps.redis.flushdb()
  
      def tearDown(self):
          self.ps.close()
  
      def test_10_basic_job(self):
          """JOB publish, retrieve, finish, get result"""
          #publisher
          testjob = self.ps.job("testjob")
          id = testjob.put(9.0)
  
          #worker
          testjobworker = self.ps.job("testjob")
          id_worker, query_worker = testjobworker.get(timeout=3)
          result_worker = math.sqrt(float(query_worker))
          testjobworker.finish(id_worker, result_worker, True)
  
          #publisher gets result
          query_publisher, result_publisher = testjob.get_result(id, 1)
          self.assertEqual(float(result_worker), float(result_publisher), "Job results did not match publish.")
          self.assertEqual(testjob.get_ids(), [])
  
      def test_20_cancel_job(self):
          j = self.ps.job("testjob")
          #publisher
          id = j.put(9.0)
          #worker claims
          id, query = j.get()
          #publisher or worker cancels
          j.cancel(id)
          id2, query2 = j.get()
          self.assertEqual(id, id2)
          #cancel the work again
          j.cancel(id)
          #cleanup -- remove the job from the queue
          j.retract(id)
          self.assertEqual(j.get_ids(), [])
  
  
  suite = unittest.TestLoader().loadTestsFromTestCase(TestJob)
  
  
new_contents: import thoonk
  import unittest
  import math
  
  class TestJob(unittest.TestCase):
  
      def __init__(self, *args, **kwargs):
          unittest.TestCase.__init__(self, *args, **kwargs)
  
      def setUp(self):
          self.ps = thoonk.Pubsub(db=10, listen=True)
          self.ps.redis.flushdb()
  
      def tearDown(self):
          self.ps.close()
  
      def test_10_basic_job(self):
          """JOB publish, retrieve, finish, get result"""
          #publisher
          testjob = self.ps.job("testjob")
          id = testjob.put(9.0)
  
          #worker
          testjobworker = self.ps.job("testjob")
          id_worker, query_worker = testjobworker.get(timeout=3)
          result_worker = math.sqrt(float(query_worker))
          testjobworker.finish(id_worker, result_worker, True)
  
          #publisher gets result
          query_publisher, result_publisher = testjob.get_result(id, 1)
          self.assertEqual(float(result_worker), float(result_publisher), "Job results did not match publish.")
          self.assertEqual(testjob.get_ids(), [])
  
      def test_20_cancel_job(self):
          """Test cancelling a job"""
          j = self.ps.job("testjob")
          #publisher
          id = j.put(9.0)
          #worker claims
          id, query = j.get()
          #publisher or worker cancels
          j.cancel(id)
          id2, query2 = j.get()
          self.assertEqual(id, id2)
          #cancel the work again
          j.cancel(id)
          #cleanup -- remove the job from the queue
          j.retract(id)
          self.assertEqual(j.get_ids(), [])
  
  
  suite = unittest.TestLoader().loadTestsFromTestCase(TestJob)
  
  
subject: Add doc for job cancellation test.