Commit 6f1c45c6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

runUnitTest: ZODB is removed on '--save', so also remove all the tables of the SQL database.

Assuming that the test database already exists and 'movement' table already
contains data (from past execution for example), on '--save' before this
commit:
  1. Create a new ERP5 Site:
     1. Install erp5_mysql_innodb_catalog.
     2. Call ERP5Site_reindexAll(clear_catalog=True) (from ERP5Generator.setupIndex()).
        => At this point, erp5_mysql_innodb_catalog tables are recreated.
  2. Install erp5_movement_table_catalog or any bt5 adding a new SQL table.
     => This does not recreate the table and leave the existing data as it is.
  3. Dump MySQL database to dump.sql.
  => dump.sql contains 'INSERT INTO' for 'movement' table *before* this '--save'.

This fixes random customer Unit Tests failures on SQL queries accessing
'movement' table directly and getting {non-existing,past executions}
Movements.
parent ff50a1c2
......@@ -56,11 +56,25 @@ if load:
_print("Could not find MySQL dump (%r), will recreate catalog ... " % dump_sql_path)
os.environ['erp5_tests_recreate_catalog'] = '1'
_print("Restoring static files ... ")
elif save and not (neo_storage or zeo_client) and os.path.exists(data_fs_path):
elif save:
if not (neo_storage or zeo_client) and os.path.exists(data_fs_path):
_print("About to remove existing Data.fs %s (press Ctrl+C to abort)" % data_fs_path)
time.sleep(5)
os.remove(data_fs_path)
# Whether passing --save or not passing both --load and --save, the catalog
# must be cleared of data from previous execution if any
if not load:
_print("Catalog will be recreated to clear data (if any) from previous execution")
import Products.ZMySQLDA.db
sql_db = Products.ZMySQLDA.db.DB(os.environ['erp5_sql_connection_string'])
table_list = sql_db.tables()
if table_list:
sql_db.query('DROP TABLE ' +
','.join('`%s`' % table['TABLE_NAME'] for table in table_list))
# Close SQL connection
del sql_db
zeo_server_pid = None
node_pid_list = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment