Ejemplo n.º 1
0
    def test_database_roundtrip(self):
        # job should not change on round trip from database
        job = Job(self.dbconn)
        db_job = Job.locate(job.job_id, self.dbconn)
        for field in job.__dict__:
            self.assertEqual(job.__dict__[field], db_job.__dict__[field], 'field %s does not match' % field)

        job.pending(self.dbconn)
        db_job = Job.locate(job.job_id, self.dbconn)
        for field in job.__dict__:
            self.assertEqual(job.__dict__[field], db_job.__dict__[field], 'field %s does not match' % field)

        job.run(self.dbconn, 0)
        db_job = Job.locate(job.job_id, self.dbconn)
        for field in job.__dict__:
            self.assertEqual(job.__dict__[field], db_job.__dict__[field], 'field %s does not match' % field)

        job.finish(self.dbconn)
        db_job = Job.locate(job.job_id, self.dbconn)
        for field in job.__dict__:
            self.assertEqual(job.__dict__[field], db_job.__dict__[field], 'field %s does not match' % field)
Ejemplo n.º 2
0
    def test_heartbeat(self):
        job = Job()
        self.assertIs(job.last_heartbeat_time, None)

        # heartbeat should give us a datetime
        job.heartbeat()
        self.assertEqual(type(job.last_heartbeat_time), type(datetime.datetime.now()))

        # heartbeats should increase
        last_heartbeat = job.last_heartbeat_time
        job.heartbeat()
        self.assertTrue(job.last_heartbeat_time > last_heartbeat)

        # heartbeat should match in json
        json_job = json.loads(job.get_json())
        self.assertEqual(json_job['last_heartbeat_time'], str(job.last_heartbeat_time))

        # heartbeat should match after database round trip
        job = Job(self.dbpath)
        db_job = Job.locate(job.job_id, self.dbpath)
        self.assertEqual(job.last_heartbeat_time, db_job.last_heartbeat_time)
        job.heartbeat()
        db_job = Job.locate(job.job_id, self.dbpath)
        self.assertEqual(job.last_heartbeat_time, db_job.last_heartbeat_time)
Ejemplo n.º 3
0
 def test_locate(self):
     # locating a bad job should just be none
     job = Job.locate('00000000-0000-0000-0000-000000000000', self.dbconn)
     self.assertIs(job, None)