Example #1
0
class CheckIterWrapper(object):
    def setup(self):
        self.line_num = 6
        self.eps = 0.01
        self.account = MockAccount()
        self.account.ssh("mkdir -p /tmp")
        self.temp_file = "/tmp/ducktape-test-" + str(random.randint(0, 100000))
        for i in range(self.line_num):
            self.account.ssh("echo " + str(i) + " >> " + self.temp_file)

    def check_iter_wrapper(self):
        output = self.account.ssh_capture("tail " + self.temp_file)
        for i in range(self.line_num):
            assert output.has_next()
            assert output.next().strip() == str(i)
        start = time.time()
        assert output.has_next() == False
        stop = time.time()
        assert stop - start < self.eps, "has_next() should return immediately"

    def check_iter_wrapper_timeout(self):
        output = self.account.ssh_capture("tail -F " + self.temp_file)
        # allow command to be executed before we check output with timeout_sec = 0
        time.sleep(1)
        for i in range(self.line_num):
            assert output.has_next(timeout_sec=0)
            assert output.next().strip() == str(i)
        start = time.time()
        assert output.has_next(timeout_sec=5) == False
        stop = time.time()
        assert (stop - start >= 5) and (
            stop - start
        ) < 5 + self.eps, "has_next() should return right after 5 seconds"

    def teardown(self):
        self.account.ssh("rm -f " + self.temp_file)