summaryrefslogtreecommitdiffstats
path: root/testing/mozharness/test/test_mozilla_buildbot.py
blob: afc71502675f0d4f648f7f913b9e192716901aac (plain)
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
import gc
import unittest


import mozharness.base.log as log
from mozharness.base.log import ERROR
import mozharness.base.script as script
from mozharness.mozilla.buildbot import BuildbotMixin, TBPL_SUCCESS, \
    TBPL_FAILURE, EXIT_STATUS_DICT


class CleanupObj(script.ScriptMixin, log.LogMixin):
    def __init__(self):
        super(CleanupObj, self).__init__()
        self.log_obj = None
        self.config = {'log_level': ERROR}


def cleanup():
    gc.collect()
    c = CleanupObj()
    for f in ('test_logs', 'test_dir', 'tmpfile_stdout', 'tmpfile_stderr'):
        c.rmtree(f)


class BuildbotScript(BuildbotMixin, script.BaseScript):
    def __init__(self, **kwargs):
        super(BuildbotScript, self).__init__(**kwargs)


# TestBuildbotStatus {{{1
class TestBuildbotStatus(unittest.TestCase):
    # I need a log watcher helper function, here and in test_log.
    def setUp(self):
        cleanup()
        self.s = None

    def tearDown(self):
        # Close the logfile handles, or windows can't remove the logs
        if hasattr(self, 's') and isinstance(self.s, object):
            del(self.s)
        cleanup()

    def test_over_max_log_size(self):
        self.s = BuildbotScript(config={'log_type': 'multi',
                                        'buildbot_max_log_size': 200},
                                initial_config_file='test/test.json')
        self.s.info("foo!")
        self.s.buildbot_status(TBPL_SUCCESS)
        self.assertEqual(self.s.return_code, EXIT_STATUS_DICT[TBPL_FAILURE])

    def test_under_max_log_size(self):
        self.s = BuildbotScript(config={'log_type': 'multi',
                                        'buildbot_max_log_size': 20000},
                                initial_config_file='test/test.json')
        self.s.info("foo!")
        self.s.buildbot_status(TBPL_SUCCESS)
        self.assertEqual(self.s.return_code, EXIT_STATUS_DICT[TBPL_SUCCESS])

# main {{{1
if __name__ == '__main__':
    unittest.main()