예제 #1
0
def test_progress2(queue, worker):
    queue.enqueue(ProgressJob, progress_interval=1)
    worker.start(1)
    worker.wait_queue()
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data
                if "progress" in d["message"] and d["level"] == "DEBUG"]) >= 5
예제 #2
0
파일: test_worker.py 프로젝트: susca/core4
def test_binary_out(queue, worker, mongodb):
    job = queue.enqueue(BinaryOutputTestJob)
    worker.start(3)
    worker.wait_queue()
    assert mongodb.core4test.sys.stdout.count_documents({}) == 1
    doc = mongodb.core4test.sys.stdout.find_one()
    assert doc["_id"] == job._id
    assert doc["stdout"] == b"evil payload \xDE\xAD\xBE\xEF."
예제 #3
0
파일: test_worker.py 프로젝트: susca/core4
def test_restart_inactive(queue, worker):
    job = queue.enqueue(RestartInactiveTest)
    worker.start(1)
    while True:
        j = queue.find_job(job._id)
        if j.state == "inactive":
            break
    queue.restart_job(job._id)
    worker.wait_queue()
예제 #4
0
def test_progress3(queue, worker):

    queue.enqueue(ProgressJob)
    worker.start(1)
    worker.wait_queue()
    data = list(queue.config.sys.log.find())
    print([(d["level"], d["message"]) for d in data])
    assert sum([
        1 for d in data if "progress" in d["message"] and d["level"] == "DEBUG"
    ]) == 1
예제 #5
0
def test_zombie(queue, worker):
    job = queue.enqueue(NoProgressJob, zombie_time=1)
    worker.start(1)
    worker.wait_queue()
    assert queue.config.sys.journal.count_documents({}) == 1
    assert queue.config.sys.queue.count_documents({}) == 0
    job = queue.find_job(job._id)
    assert job.zombie_at is not None
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data
                if "successfully set zombie job" in d["message"]]) == 1
예제 #6
0
def test_progress1(queue, worker):
    # fh = open("/tmp/test.txt", "w", encoding="utf-8")
    # fh.write("%s\n" %(os.path.abspath(os.curdir)))
    # fh.write("%s\n" %(sys.executable))
    # fh.close()
    queue.enqueue(ProgressJob)
    worker.start(1)
    worker.wait_queue()
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data
                if "progress" in d["message"] and d["level"] == "DEBUG"]) == 2
예제 #7
0
def test_success_after_failure(queue, worker):
    import tests.project.work
    queue.enqueue(tests.project.work.ErrorJob, success=True)
    worker.start(1)
    worker.wait_queue()
    data = list(queue.config.sys.log.find())
    assert sum([1 for d in data if "done execution" in d["message"]]) == 3
    assert sum([1 for d in data if
                "done execution with [failed]" in d["message"]]) == 2
    assert sum([1 for d in data if
                "done execution with [complete]" in d["message"]]) == 1
예제 #8
0
파일: test_worker.py 프로젝트: susca/core4
def test_stdout(queue, worker, mongodb):
    job = queue.enqueue(OutputTestJob)
    worker.start(3)
    worker.wait_queue()
    assert mongodb.core4test.sys.stdout.count_documents({}) == 1
    doc = mongodb.core4test.sys.stdout.find_one()
    print(doc)
    assert doc["_id"] == job._id
    assert ("this output comes from tests.be.test_worker.OutputTestJob"
            in doc["stdout"])
    assert ("this comes from echo" in doc["stdout"])
    assert ("this comes from C" in doc["stdout"])
예제 #9
0
파일: test_worker.py 프로젝트: susca/core4
def test_failed_deferred(queue, worker):
    job = queue.enqueue(RestartFailedTest)
    worker.start(1)
    while True:
        j = queue.find_job(job._id)
        if j.state == "failed":
            break
    queue.restart_job(job._id)
    worker.wait_queue()
    assert queue.config.sys.journal.count_documents({}) == 1
    assert queue.config.sys.queue.count_documents({}) == 0
    job = queue.find_job(job._id)
    assert job.trial == 2
    assert job.state == core4.queue.job.STATE_COMPLETE
예제 #10
0
파일: test_worker.py 프로젝트: susca/core4
def test_project_maintenance(queue, worker):
    job = queue.enqueue(core4.queue.helper.job.example.DummyJob)
    worker.start(1)
    while queue.config.sys.queue.count_documents({}) > 0:
        time.sleep(1)
    curr = worker.worker[0].cycle["total"]
    queue.enter_maintenance("core4")
    assert queue.config.sys.queue.count_documents({}) == 0
    job = queue.enqueue(core4.queue.helper.job.example.DummyJob)
    assert queue.config.sys.queue.count_documents({}) == 1
    while worker.worker[0].cycle["total"] < curr + 10:
        time.sleep(1)
    assert queue.config.sys.queue.count_documents({}) == 1
    queue.leave_maintenance("core4")
    worker.wait_queue()
    assert queue.config.sys.queue.count_documents({}) == 0
예제 #11
0
파일: test_worker.py 프로젝트: susca/core4
def test_restart_killed(queue, worker):
    job = queue.enqueue(RestartKilledTest)
    worker.start(1)
    while True:
        j = queue.find_job(job._id)
        if j.state == "running":
            break
    queue.kill_job(job._id)
    while True:
        j = queue.find_job(job._id)
        if j.state == "killed":
            break
    new_id = queue.restart_job(job._id)
    queue.restart_job(new_id)
    # queue.remove_job(job._id)
    worker.wait_queue()
예제 #12
0
파일: test_worker.py 프로젝트: susca/core4
def test_kill(queue, worker):
    job = queue.enqueue(ForeverJob, zombie_time=2)
    worker.start(1)
    while True:
        job = queue.find_job(job._id)
        if job.locked and job.locked["pid"]:
            break
    queue.kill_job(job._id)
    while True:
        job = queue.find_job(job._id)
        if job.state == "killed":
            break
    queue.remove_job(job._id)
    worker.wait_queue()
    assert queue.config.sys.journal.count_documents({}) == 1
    assert queue.config.sys.queue.count_documents({}) == 0
    job = queue.find_job(job._id)
    assert job.state == "killed"
    assert job.killed_at is not None
예제 #13
0
파일: test_worker.py 프로젝트: susca/core4
def test_restart_error(queue, worker):
    job = queue.enqueue(RestartErrorTest)
    worker.start(1)
    while True:
        j = queue.find_job(job._id)
        if j.state == "error":
            break
    new_id = queue.restart_job(job._id)
    worker.wait_queue()
    assert queue.config.sys.journal.count_documents({}) == 2
    assert queue.config.sys.queue.count_documents({}) == 0
    parent = queue.find_job(job._id)
    assert parent.state == core4.queue.job.STATE_ERROR
    child = queue.find_job(new_id)
    assert child.state == core4.queue.job.STATE_COMPLETE
    assert parent.enqueued["child_id"] == child._id
    assert child.enqueued["parent_id"] == parent._id
    assert parent.enqueued["parent_id"] is None
    assert "child_id" not in child.enqueued
    assert queue.config.sys.lock.count_documents({}) == 0
예제 #14
0
파일: test_worker.py 프로젝트: susca/core4
def test_ok(queue, worker):
    queue.enqueue(core4.queue.helper.job.example.DummyJob, sleep=0)
    worker.start(1)
    worker.wait_queue()