44import pymysql .cursors
55import pytest
66from helpers .cluster import ClickHouseCluster
7+ from helpers .test_tools import assert_eq_with_retry
78from psycopg2 .extensions import ISOLATION_LEVEL_AUTOCOMMIT
89
910cluster = ClickHouseCluster (__file__ )
@@ -200,26 +201,43 @@ def test_sqlite_odbc_hashed_dictionary(started_cluster):
200201 node1 .exec_in_container (["bash" , "-c" , "echo 'INSERT INTO t2 values(1, 2, 3);' | sqlite3 {}" .format (sqlite_db )],
201202 privileged = True , user = 'root' )
202203
203- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" ) == "3\n "
204- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" ) == "1\n " # default
204+ node1 .query ("SYSTEM RELOAD DICTIONARY sqlite3_odbc_hashed" )
205+ first_update_time = node1 .query ("SELECT last_successful_update_time FROM system.dictionaries WHERE name = 'sqlite3_odbc_hashed'" )
206+ print ("First update time" , first_update_time )
207+
208+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" , "3" )
209+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" , "1" ) # default
210+
211+ second_update_time = node1 .query ("SELECT last_successful_update_time FROM system.dictionaries WHERE name = 'sqlite3_odbc_hashed'" )
212+ # Reloaded with new data
213+ print ("Second update time" , second_update_time )
214+ while first_update_time == second_update_time :
215+ second_update_time = node1 .query ("SELECT last_successful_update_time FROM system.dictionaries WHERE name = 'sqlite3_odbc_hashed'" )
216+ print ("Waiting dictionary to update for the second time" )
217+ time .sleep (0.1 )
205218
206- time .sleep (5 ) # first reload
207219 node1 .exec_in_container (["bash" , "-c" , "echo 'INSERT INTO t2 values(200, 2, 7);' | sqlite3 {}" .format (sqlite_db )],
208220 privileged = True , user = 'root' )
209221
210222 # No reload because of invalidate query
211- time .sleep (5 )
212- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" ) == "3\n "
213- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" ) == "1\n " # still default
223+ third_update_time = node1 .query ("SELECT last_successful_update_time FROM system.dictionaries WHERE name = 'sqlite3_odbc_hashed'" )
224+ print ("Third update time" , second_update_time )
225+ counter = 0
226+ while third_update_time == second_update_time :
227+ third_update_time = node1 .query ("SELECT last_successful_update_time FROM system.dictionaries WHERE name = 'sqlite3_odbc_hashed'" )
228+ time .sleep (0.1 )
229+ if counter > 50 :
230+ break
231+ counter += 1
232+
233+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" , "3" )
234+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" , "1" ) # still default
214235
215236 node1 .exec_in_container (["bash" , "-c" , "echo 'REPLACE INTO t2 values(1, 2, 5);' | sqlite3 {}" .format (sqlite_db )],
216237 privileged = True , user = 'root' )
217238
218- # waiting for reload
219- time .sleep (5 )
220-
221- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" ) == "5\n "
222- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" ) == "7\n " # new value
239+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(1))" , "5" )
240+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_hashed', 'Z', toUInt64(200))" , "7" )
223241
224242
225243def test_sqlite_odbc_cached_dictionary (started_cluster ):
@@ -241,18 +259,16 @@ def test_sqlite_odbc_cached_dictionary(started_cluster):
241259 node1 .exec_in_container (["bash" , "-c" , "echo 'REPLACE INTO t3 values(1, 2, 12);' | sqlite3 {}" .format (sqlite_db )],
242260 privileged = True , user = 'root' )
243261
244- time .sleep (5 )
245-
246- assert node1 .query ("select dictGetUInt8('sqlite3_odbc_cached', 'Z', toUInt64(1))" ) == "12\n "
262+ assert_eq_with_retry (node1 , "select dictGetUInt8('sqlite3_odbc_cached', 'Z', toUInt64(1))" , "12" )
247263
248264
249265def test_postgres_odbc_hached_dictionary_with_schema (started_cluster ):
250266 conn = get_postgres_conn ()
251267 cursor = conn .cursor ()
252268 cursor .execute ("insert into clickhouse.test_table values(1, 'hello'),(2, 'world')" )
253- time . sleep ( 5 )
254- assert node1 . query ( "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(1))" ) == "hello\n "
255- assert node1 . query ( "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(2))" ) == "world\n "
269+ node1 . query ( "SYSTEM RELOAD DICTIONARY postgres_odbc_hashed" )
270+ assert_eq_with_retry ( node1 , "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(1))" , "hello" )
271+ assert_eq_with_retry ( node1 , "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(2))" , "world" )
256272
257273
258274def test_postgres_odbc_hached_dictionary_no_tty_pipe_overflow (started_cluster ):
@@ -265,7 +281,7 @@ def test_postgres_odbc_hached_dictionary_no_tty_pipe_overflow(started_cluster):
265281 except Exception as ex :
266282 assert False , "Exception occured -- odbc-bridge hangs: " + str (ex )
267283
268- assert node1 . query ( "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(3))" ) == "xxx\n "
284+ assert_eq_with_retry ( node1 , "select dictGetString('postgres_odbc_hashed', 'column2', toUInt64(3))" , "xxx" )
269285
270286
271287def test_postgres_insert (started_cluster ):
@@ -310,7 +326,7 @@ def test_bridge_dies_with_parent(started_cluster):
310326 clickhouse_pid = node1 .get_process_pid ("clickhouse server" )
311327 time .sleep (1 )
312328
313- for i in range (5 ):
329+ for i in range (30 ):
314330 time .sleep (1 ) # just for sure, that odbc-bridge caught signal
315331 bridge_pid = node1 .get_process_pid ("odbc-bridge" )
316332 if bridge_pid is None :
0 commit comments