From 3e7ac1f9ab176601876e3474fa3c6eb1660880a2 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 16 Jun 2020 23:52:31 +0300 Subject: [PATCH] Added retries to test_mysql_federated --- tests/integration/test_mysql_protocol/test.py | 77 ++++++++++++------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/tests/integration/test_mysql_protocol/test.py b/tests/integration/test_mysql_protocol/test.py index e2c02239ae9..4ab225aee20 100644 --- a/tests/integration/test_mysql_protocol/test.py +++ b/tests/integration/test_mysql_protocol/test.py @@ -139,39 +139,62 @@ def test_mysql_client(mysql_client, server_address): def test_mysql_federated(mysql_server, server_address): - node.query('''DROP DATABASE IF EXISTS mysql_federated''', settings={"password": "123"}) - node.query('''CREATE DATABASE mysql_federated''', settings={"password": "123"}) - node.query('''CREATE TABLE mysql_federated.test (col UInt32) ENGINE = Log''', settings={"password": "123"}) - node.query('''INSERT INTO mysql_federated.test VALUES (0), (1), (5)''', settings={"password": "123"}) + # For some reason it occasionally fails without retries. + retries = 100 + for try_num in range(retries): + node.query('''DROP DATABASE IF EXISTS mysql_federated''', settings={"password": "123"}) + node.query('''CREATE DATABASE mysql_federated''', settings={"password": "123"}) + node.query('''CREATE TABLE mysql_federated.test (col UInt32) ENGINE = Log''', settings={"password": "123"}) + node.query('''INSERT INTO mysql_federated.test VALUES (0), (1), (5)''', settings={"password": "123"}) - code, (stdout, stderr) = mysql_server.exec_run(''' - mysql - -e "DROP SERVER IF EXISTS clickhouse;" - -e "CREATE SERVER clickhouse FOREIGN DATA WRAPPER mysql OPTIONS (USER 'default', PASSWORD '123', HOST '{host}', PORT {port}, DATABASE 'mysql_federated');" - -e "DROP DATABASE IF EXISTS mysql_federated;" - -e "CREATE DATABASE mysql_federated;" - '''.format(host=server_address, port=server_port), demux=True) + code, (stdout, stderr) = mysql_server.exec_run(''' + mysql + -e "DROP SERVER IF EXISTS clickhouse;" + -e "CREATE SERVER clickhouse FOREIGN DATA WRAPPER mysql + OPTIONS (USER 'default', PASSWORD '123', HOST '{host}', PORT {port}, DATABASE 'mysql_federated');" + -e "DROP DATABASE IF EXISTS mysql_federated;" + -e "CREATE DATABASE mysql_federated;" + '''.format(host=server_address, port=server_port), demux=True) - if code != 0: - print(stdout) - print(stderr) - assert code == 0 + if code != 0: + print("stdout", stdout) + print("stderr", stderr) + if try_num + 1 < retries and "Can't connect to local MySQL server through socket" in stderr: + time.sleep(1) + continue + assert code == 0 - code, (stdout, stderr) = mysql_server.exec_run(''' - mysql - -e "CREATE TABLE mysql_federated.test(`col` int UNSIGNED) ENGINE=FEDERATED CONNECTION='clickhouse';" - -e "SELECT * FROM mysql_federated.test ORDER BY col;" - '''.format(host=server_address, port=server_port), demux=True) + code, (stdout, stderr) = mysql_server.exec_run(''' + mysql + -e "CREATE TABLE mysql_federated.test(`col` int UNSIGNED) ENGINE=FEDERATED CONNECTION='clickhouse';" + -e "SELECT * FROM mysql_federated.test ORDER BY col;" + '''.format(host=server_address, port=server_port), demux=True) - assert stdout == '\n'.join(['col', '0', '1', '5', '']) + if code != 0: + print("stdout", stdout) + print("stderr", stderr) + if try_num + 1 < retries and "Can't connect to local MySQL server through socket" in stderr: + time.sleep(1) + continue + assert code == 0 - code, (stdout, stderr) = mysql_server.exec_run(''' - mysql - -e "INSERT INTO mysql_federated.test VALUES (0), (1), (5);" - -e "SELECT * FROM mysql_federated.test ORDER BY col;" - '''.format(host=server_address, port=server_port), demux=True) + assert stdout == '\n'.join(['col', '0', '1', '5', '']) - assert stdout == '\n'.join(['col', '0', '0', '1', '1', '5', '5', '']) + code, (stdout, stderr) = mysql_server.exec_run(''' + mysql + -e "INSERT INTO mysql_federated.test VALUES (0), (1), (5);" + -e "SELECT * FROM mysql_federated.test ORDER BY col;" + '''.format(host=server_address, port=server_port), demux=True) + + if code != 0: + print("stdout", stdout) + print("stderr", stderr) + if try_num + 1 < retries and "Can't connect to local MySQL server through socket" in stderr: + time.sleep(1) + continue + assert code == 0 + + assert stdout == '\n'.join(['col', '0', '0', '1', '1', '5', '5', '']) def test_python_client(server_address):