class CheckRemoteAccount(object): def setup(self): self.server = SimpleServer() self.account = MockAccount() def check_wait_for_http(self): """Check waiting without timeout""" self.server.start(delay_sec=0.0) self.account.wait_for_http_service(port=self.server.port, headers={}, timeout=10, path="/") def check_wait_for_http_timeout(self): """Check waiting with timeout""" timeout = 1 start = time.time() self.server.start(delay_sec=5) try: self.account.wait_for_http_service(port=self.server.port, headers={}, timeout=timeout, path='/') raise Exception("Should have timed out waiting for server to start") except TimeoutError: # expected behavior. Now check that we're reasonably close to the expected timeout # This is a fairly loose check since there are various internal timeouts that can affect the overall # timing actual_timeout = time.time() - start assert abs(actual_timeout - timeout) / timeout < 1 def teardown(self): self.server.stop()
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_sizes(self): empty = NodeContainer() assert 0 == empty.size() assert 0 == len(empty) nodes = [ClusterNode(MockAccount())] container = NodeContainer(nodes) assert 1 == container.size() assert 1 == len(container)
def check_add_and_remove(self): nodes = [ ClusterNode(MockAccount()), ClusterNode(MockAccount()), ClusterNode(MockAccount()), ClusterNode(MockAccount()), ClusterNode(MockAccount()) ] container = NodeContainer([]) assert 0 == len(container) container.add_node(nodes[0]) container.add_node(nodes[1]) container.add_node(nodes[2]) container2 = container.clone() i = 0 for node in container: assert nodes[i] == node i += 1 assert 3 == len(container) container.remove_node(nodes[0]) with pytest.raises(NodeNotPresentError): container.remove_node(nodes[0]) assert 2 == len(container) assert 3 == len(container2)
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)
def setup(self): self.server = SimpleServer() self.account = MockAccount()