Make WordPress Core


Ignore:
Timestamp:
10/10/2017 11:45:35 PM (9 years ago)
Author:
pento
Message:

Database: Fix a test failing on MySQL 5.7 and MariaDB 10.2.

On newer versions of MySQL, an error was being thrown when creating a table with an index that we wanted to be silently truncated.

To avoid this, the test now tries to use a newer InnoDB file format where available, and skips the test when that happens.

Props pento, danielbachhuber, straussd.
Fixes #41716.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dbdelta.php

    r40339 r41818  
    362362                }
    363363
    364                 $table_name = 'test_truncated_index';
    365 
    366                 $create = "CREATE TABLE $table_name (\n a varchar(255) COLLATE utf8mb4_unicode_ci,\n KEY a (a)\n)";
     364                // This table needs to be actually created
     365                remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
     366                remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
     367
     368                $table_name = "{$wpdb->prefix}test_truncated_index";
     369
     370                $create = "
     371                        CREATE TABLE $table_name (
     372                                a varchar(255) COLLATE utf8mb4_unicode_ci,
     373                                KEY a_key (a)
     374                        ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC";
     375
    367376                $wpdb->query( $create );
    368377
     378                $index = $wpdb->get_row( "SHOW INDEXES FROM $table_name WHERE Key_name='a_key';" );
     379
    369380                $actual = dbDelta( $create, false );
     381
     382                $wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
     383
     384                if ( 191 != $index->Sub_part ) {
     385                        $this->markTestSkipped( "This test requires the index to be truncated." );
     386                }
    370387
    371388                $this->assertSame( array(), $actual );
Note: See TracChangeset for help on using the changeset viewer.