Esempio n. 1
0
def test_project_process(queue):
    queue.enqueue(core4.queue.helper.job.example.DummyJob)
    worker = core4.queue.worker.CoreWorker()
    worker.at = core4.util.node.now()
    worker.work_jobs()
    while queue.config.sys.queue.count_documents({}) > 0:
        print("waiting")
        time.sleep(1)
Esempio n. 2
0
def test_no_resources(queue):
    job = queue.enqueue(core4.queue.helper.job.example.DummyJob)
    worker1 = WorkerNoCPU(name="testRes_1")
    worker2 = WorkerNoCPU(name="testRes_2")
    worker3 = WorkerNoRAM(name="testRes_3")
    worker4 = WorkerNoRAM(name="testRes_4")
    for worker in (worker1, worker2, worker3, worker4):
        worker.at = core4.util.node.now()
        worker.work_jobs()
    assert queue.config.sys.queue.count_documents({"state": "pending"}) == 1
    worker5 = WorkerHasRes(name="testRes")
    worker5.at = core4.util.node.now()
    worker5.work_jobs()
    while queue.config.sys.queue.count_documents({}) > 0:
        time.sleep(1)
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data if "skipped job" in d["message"]]) == 4
    assert sum([1 for d in data if "start execution" in d["message"]]) == 1
Esempio n. 3
0
def test_no_resources_force(queue):
    job = queue.enqueue(core4.queue.helper.job.example.DummyJob, force=True)
    worker = WorkerNoCPU(name="testRes_1")
    worker.at = core4.util.node.now()
    worker.work_jobs()
    while queue.config.sys.queue.count_documents({}) > 0:
        time.sleep(1)
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data if "start execution" in d["message"]]) == 1
    job2 = queue.enqueue(core4.queue.helper.job.example.DummyJob, force=True,
                         node="testRes2")
    worker2 = WorkerNoRAM(name="testRes2")
    worker2.at = core4.util.node.now()
    worker2.work_jobs()
    while queue.config.sys.queue.count_documents({}) > 0:
        time.sleep(1)
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data if "start execution" in d["message"]]) == 2
Esempio n. 4
0
def test_job_exception_logging(queue):
    job = queue.enqueue(ExceptionJob)
    worker = core4.queue.worker.CoreWorker()
    worker.at = core4.util.node.mongo_now()
    worker.work_jobs()

    def waiter(_id):
        while True:
            j = queue.config.sys.journal.find_one({"_id": _id})
            if j is not None:
                print("found state", j["state"])
                break

    waiter(job._id)

    job = queue.enqueue(ExceptionJob)
    worker.work_jobs()
    waiter(job._id)

    job = queue.enqueue(ExceptionJob)
    worker.work_jobs()

    while True:
        j = queue.config.sys.queue.find_one()
        if j["state"] == "error":
            break
    while True:
        j = queue.config.sys.log.find_one({"level": "CRITICAL"})
        if j is not None:
            break
    data = list(queue.config.sys.log.find(sort=[("epoch", 1)]))
    debugs = sum([
        1 for i in data
        if i["identifier"] == str(job._id) and i["level"] == "DEBUG"
    ])
    assert debugs == 3