Exemple #1
0
    def test_recent_running_job(self):
        """
        The job has just been switched to running. Initially though, there is
        no cluster script. The cluster script is only created after the status
        was at least checked once.
        """
        with tempfile.TemporaryDirectory() as temp_sub_dir:
            with tempfile.TemporaryDirectory() as temp_scratch_dir:
                logger.debug("temporary cluster scratch dir: {}".format(
                    temp_scratch_dir))
                job_id = 1234

                def create_this_cluster_script(*a, **kw):
                    make_cluster_script(job_id, temp_sub_dir, temp_scratch_dir)
                    logger.info("Cluster script created" + "*" * 80)
                    logger.info("Content of sub_dir: {}".format(
                        os.listdir(temp_sub_dir)))

                with before_after.after(
                        "utils.jobinfo.status.get_cluster_script_from_list",
                        create_this_cluster_script):
                    job_status, job_dir = \
                        get_job_status_and_job_dir_from_sub_dir(
                            job_id=job_id, sub_dir=temp_sub_dir, recent=True)
                self.assertEqual(job_status, Job.JOB_STATUS_RUNNING)
                self.assertEqual(job_dir, temp_scratch_dir)
    def test_after(self):
        def after_fn(*a):
            test_functions.test_list.append(2)

        with after('before_after.tests.test_functions.sample_fn', after_fn):
            test_functions.sample_fn(1)

        self.assertEqual(test_functions.test_list, [1, 2])
Exemple #3
0
 def ingest(indexes: list[int], interleave=True):
     if interleave and len(indexes) > 1:
         with before_after.after(
             "ampel.ztf.ingest.ZiMongoMuxer.ZiMongoMuxer._get_dps",
             lambda *args: ingest(indexes[1:], interleave),
         ):
             _ingest(indexes[:1])
     else:
         _ingest(indexes)
    def test_after_once(self):
        def after_fn(*a):
            test_functions.test_list.append(2)

        with after('before_after.tests.test_functions.sample_fn',
                   after_fn,
                   once=True):
            test_functions.sample_fn(1)
            test_functions.sample_fn(3)

        self.assertEqual(test_functions.test_list, [1, 2, 3])
Exemple #5
0
    def test_locking_increment_race(self):
        def erroring_locking_increment():
            # Trying to get a lock when the other thread has it will cause a
            # CouldNotLock exception - catch it here or the test will fail
            with self.assertRaises(db.CouldNotLock):
                incrmnt.locking_increment()

        with before_after.after('incrmnt.db.get_count',
                                erroring_locking_increment):
            incrmnt.locking_increment()

        count = db.get_count()
        self.assertEqual(count, 1)
    def test_locking_increment_race(self):
        def erroring_locking_increment():
            # Trying to get a lock when the other thread has it will cause a
            # CouldNotLock exception - catch it here or the test will fail
            with self.assertRaises(db.CouldNotLock):
                incrmnt.locking_increment()

        with before_after.after(
                'incrmnt.db.get_count', erroring_locking_increment):
            incrmnt.locking_increment()

        count = db.get_count()
        self.assertEqual(count, 1)
Exemple #7
0
    def test_increment_race(self):
        with before_after.after('incrmnt.db.get_count', incrmnt.increment):
            incrmnt.increment()

        count = db.get_count()
        self.assertEqual(count, 1)  # Should be 2
    def test_increment_race(self):
        with before_after.after('incrmnt.db.get_count', incrmnt.increment):
            incrmnt.increment()

        count = db.get_count()
        self.assertEqual(count, 1)  # Should be 2