summaryrefslogtreecommitdiff
path: root/buildscripts/resmokelib/testing/testcases/sleeptest.py
blob: e62fa9698edcf73ef2b0fc352fc5c0585783daff (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
"""The unittest.TestCase for sleeping a given amount of time."""

import time

from buildscripts.resmokelib.testing.testcases import interface


class SleepTestCase(interface.TestCase):
    """SleepTestCase class."""

    REGISTERED_NAME = "sleep_test"

    def __init__(self, logger, sleep_duration_secs):
        """Initialize the SleepTestCase with the duration to sleep for."""

        sleep_duration_secs = int(sleep_duration_secs)

        interface.TestCase.__init__(self, logger, "Sleep",
                                    "{:d} seconds".format(sleep_duration_secs))

        self.__sleep_duration_secs = sleep_duration_secs

    def run_test(self):
        """Execute sleep."""
        time.sleep(self.__sleep_duration_secs)
        self.return_code = 0

    def as_command(self):
        """Return the command invocation used to run the test."""
        return "sleep {:d}".format(self.__sleep_duration_secs)