File: test_executors.py

package info (click to toggle)
python-jenkinsapi 0.3.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,500 kB
  • sloc: python: 10,001; xml: 50; makefile: 31; sh: 26
file content (75 lines) | stat: -rw-r--r-- 2,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
System tests for `jenkinsapi.jenkins` module.
"""

import time
import logging
from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB
from jenkinsapi_tests.test_utils.random_strings import random_string

log = logging.getLogger(__name__)


def test_get_executors(jenkins):
    node_name = random_string()
    node_dict = {
        "num_executors": 2,
        "node_description": "Test JNLP Node",
        "remote_fs": "/tmp",
        "labels": "systest_jnlp",
        "exclusive": True,
    }
    jenkins.nodes.create_node(node_name, node_dict)
    executors = jenkins.get_executors(node_name)
    assert executors.count == 2

    for count, execs in enumerate(executors):
        assert count == execs.get_number()
        assert execs.is_idle() is True


def test_running_executor(jenkins):
    node_name = random_string()
    node_dict = {
        "num_executors": 1,
        "node_description": "Test JNLP Node",
        "remote_fs": "/tmp",
        "labels": "systest_jnlp",
        "exclusive": True,
    }
    jenkins.nodes.create_node(node_name, node_dict)
    job_name = "create_%s" % random_string()
    job = jenkins.create_job(job_name, LONG_RUNNING_JOB)
    qq = job.invoke()
    qq.block_until_building()

    if job.is_running() is False:
        time.sleep(1)
    executors = jenkins.get_executors(node_name)
    all_idle = True
    for execs in executors:
        if execs.is_idle() is False:
            all_idle = False
            assert execs.get_progress() != -1
            assert execs.get_current_executable() == qq.get_build_number()
            assert execs.likely_stuck() is False
    assert all_idle is True, "Executor should have been triggered."


def test_idle_executors(jenkins):
    node_name = random_string()
    node_dict = {
        "num_executors": 1,
        "node_description": "Test JNLP Node",
        "remote_fs": "/tmp",
        "labels": "systest_jnlp",
        "exclusive": True,
    }
    jenkins.nodes.create_node(node_name, node_dict)
    executors = jenkins.get_executors(node_name)

    for execs in executors:
        assert execs.get_progress() == -1
        assert execs.get_current_executable() is None
        assert execs.likely_stuck() is False
        assert execs.is_idle() is True