mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
Running exhaustive tests with env var IMPALA_USE_PYTHON3_TESTS=true reveals some tests that require adjustment. This patch made such adjustment, which mostly revolves around encoding differences and string vs bytes type in Python3. This patch also switch the default to run pytest with Python3 by setting IMPALA_USE_PYTHON3_TESTS=true. The following are the details: Change hash() function in conftest.py to crc32() to produce deterministic hash. Hash randomization is enabled by default since Python 3.3 (see https://docs.python.org/3/reference/datamodel.html#object.__hash__). This cause test sharding (like --shard_tests=1/2) produce inconsistent set of tests per shard. Always restart minicluster during custom cluster tests if --shard_tests argument is set, because test order may change and affect test correctness, depending on whether running on fresh minicluster or not. Moved one test case from delimited-latin-text.test to test_delimited_text.py for easier binary comparison. Add bytes_to_str() as a utility function to decode bytes in Python3. This is often needed when inspecting the return value of subprocess.check_output() as a string. Implement DataTypeMetaclass.__lt__ to substitute DataTypeMetaclass.__cmp__ that is ignored in Python3 (see https://peps.python.org/pep-0207/). Fix WEB_CERT_ERR difference in test_ipv6.py. Fix trivial integer parsing in test_restart_services.py. Fix various encoding issues in test_saml2_sso.py, test_shell_commandline.py, and test_shell_interactive.py. Change timeout in Impala.for_each_impalad() from sys.maxsize to 2^31-1. Switch to binary comparison in test_iceberg.py where needed. Specify text mode when calling tempfile.NamedTemporaryFile(). Simplify create_impala_shell_executable_dimension to skip testing dev and python2 impala-shell when IMPALA_USE_PYTHON3_TESTS=true. The reason is that several UTF-8 related tests in test_shell_commandline.py break in Python3 pytest + Python2 impala-shell combo. This skipping already happen automatically in build OS without system Python2 available like RHEL9 (IMPALA_SYSTEM_PYTHON2 env var is empty). Removed unused vector argument and fixed some trivial flake8 issues. Several test logic require modification due to intermittent issue in Python3 pytest. These include: Add _run_query_with_client() in test_ranger.py to allow reusing a single Impala client for running several queries. Ensure clients are closed when the test is done. Mark several tests in test_ranger.py with SkipIfFS.hive because they run queries through beeline + HiveServer2, but Ozone and S3 build environment does not start HiveServer2 by default. Increase the sleep period from 0.1 to 0.5 seconds per iteration in test_statestore.py and mark TestStatestore to execute serially. This is because TServer appears to shut down more slowly when run concurrently with other tests. Handle the deprecation of Thread.setDaemon() as well. Always force_restart=True each test method in TestLoggingCore, TestShellInteractiveReconnect, and TestQueryRetries to prevent them from reusing minicluster from previous test method. Some of these tests destruct minicluster (kill impalad) and will produce minidump if metrics verifier for next tests fail to detect healthy minicluster state. Testing: Pass exhaustive tests with IMPALA_USE_PYTHON3_TESTS=true. Change-Id: I401a93b6cc7bcd17f41d24e7a310e0c882a550d4 Reviewed-on: http://gerrit.cloudera.org:8080/23319 Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
117 lines
4.9 KiB
Python
117 lines
4.9 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
import socket
|
|
|
|
import pytest
|
|
|
|
# Follow tests/shell/test_shell_interactive.py naming.
|
|
from impala_shell.impala_shell import ImpalaShell as ImpalaShellClass
|
|
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
|
|
from tests.common.impala_service import ImpaladService
|
|
from tests.common.test_dimensions import create_client_protocol_dimension
|
|
from tests.common.test_vector import ImpalaTestVector
|
|
from tests.shell.util import get_impalad_port, get_shell_cmd, ImpalaShell, spawn_shell
|
|
from tests.verifiers.metric_verifier import MetricVerifier
|
|
|
|
NUM_QUERIES = 'impala-server.num-queries'
|
|
|
|
|
|
class TestShellInteractiveReconnect(CustomClusterTestSuite):
|
|
""" Check if interactive shell is using the current DB after reconnecting """
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(force_restart=True)
|
|
def test_manual_reconnect(self):
|
|
# Iterate over test vector within test function to avoid restarting cluster.
|
|
for vector in\
|
|
[ImpalaTestVector([value]) for value in create_client_protocol_dimension()]:
|
|
p = ImpalaShell(vector)
|
|
p.send_cmd("USE functional")
|
|
# Connect without arguments works because the custom cluster will have the default
|
|
# HS2 and Beeswax ports.
|
|
p.send_cmd("CONNECT")
|
|
p.send_cmd("SHOW TABLES")
|
|
|
|
result = p.get_result()
|
|
assert "alltypesaggmultifilesnopart" in result.stdout, result.stdout
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(force_restart=True)
|
|
def test_auto_reconnect(self):
|
|
impalad = ImpaladService(socket.getfqdn())
|
|
|
|
# Iterate over test vector within test function to avoid restarting cluster.
|
|
for vector in\
|
|
[ImpalaTestVector([value]) for value in create_client_protocol_dimension()]:
|
|
p = ImpalaShell(vector)
|
|
# ImpalaShell startup may issue query to get server info - get num queries after
|
|
# starting shell.
|
|
start_num_queries = impalad.get_metric_value(NUM_QUERIES)
|
|
p.send_cmd("USE functional")
|
|
|
|
# wait for the USE command to finish
|
|
impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
|
|
assert impalad.wait_for_num_in_flight_queries(0)
|
|
|
|
self._start_impala_cluster([])
|
|
|
|
p.send_cmd("SHOW TABLES")
|
|
result = p.get_result()
|
|
assert "alltypesaggmultifilesnopart" in result.stdout, result.stdout
|
|
|
|
@pytest.mark.execute_serially
|
|
@CustomClusterTestSuite.with_args(force_restart=True)
|
|
def test_auto_reconnect_after_impalad_died(self):
|
|
"""Test reconnect after restarting the remote impalad without using connect;"""
|
|
# Use pexpect instead of ImpalaShell() since after using get_result() in ImpalaShell()
|
|
# to check Disconnect, send_cmd() will no longer have any effect so we can not check
|
|
# reconnect.
|
|
impalad = ImpaladService(socket.getfqdn())
|
|
|
|
# Iterate over test vector within test function to avoid restarting cluster.
|
|
for vector in\
|
|
[ImpalaTestVector([value]) for value in create_client_protocol_dimension()]:
|
|
proc = spawn_shell(get_shell_cmd(vector))
|
|
proc.expect("{0}] default>".format(get_impalad_port(vector)))
|
|
# ImpalaShell startup may issue query to get server info - get num queries after
|
|
# starting shell.
|
|
start_num_queries = impalad.get_metric_value(NUM_QUERIES)
|
|
proc.sendline("use tpch;")
|
|
|
|
# wait for the USE command to finish
|
|
impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
|
|
assert impalad.wait_for_num_in_flight_queries(0)
|
|
|
|
# Disconnect
|
|
self.cluster.impalads[0].kill()
|
|
proc.sendline("show tables;")
|
|
# Search from [1:] since the square brackets "[]" are special characters in regex
|
|
proc.expect(ImpalaShellClass.DISCONNECTED_PROMPT[1:])
|
|
# Restarting Impalad
|
|
self.cluster.impalads[0].start()
|
|
# Check reconnect
|
|
proc.sendline("show tables;")
|
|
proc.expect("nation")
|
|
proc.expect("{0}] tpch>".format(get_impalad_port(vector)))
|
|
proc.sendeof()
|
|
proc.wait()
|
|
|
|
# Ensure no sessions or queries are left dangling.
|
|
verifier = MetricVerifier(self.impalad_test_service)
|
|
verifier.verify_metrics_are_zero()
|