WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/30/2015 01:08:49 PM (6 years ago)
Author:
boonebgorges
Message:

Prevent Multisite term tests from hitting database for 'db_version'.

[34718] introduced a 'db_version' check to term meta functions, to ensure that
they don't run when the term meta schema is not yet in place. This call to
get_option() causes a database hit during Multisite tests, due to the
presence of the WP_INSTALLING constant. See #31130. The extra database
queries are causing cache tests to fail.

In similar cases, we have markTestSkipped() when is_multisite(). Because
the term meta API is so extensive - term meta caches can be primed anywhere a
WP_Query loop is fired up - we implement a more generous workaround in this
case. To prevent get_option( 'db_version' ) from hitting the database during
multisite unit tests, we use a 'pre_option_' filter.

Heaven help us.

See #34091.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r34638 r34719  
    5656
    5757        add_filter( 'wp_mail', array( $this, 'set_wp_mail_globals' ) );
     58
     59        /*
     60         * During multisite tests, WP_INSTALLING forces `get_option()` to miss the cache, which causes problems
     61         * with our query-counting cache tests. As a workaround in the case of tests that require checking
     62         * 'db_version' (such as any test that uses the Term Meta API), we filter 'pre_option_db_version' and
     63         * avoid hitting the database.
     64         *
     65         * See #31130.
     66         */
     67        if ( is_multisite() ) {
     68            $this->db_version = get_option( 'db_version' );
     69            add_filter( 'pre_option_db_version', array( $this, 'db_version' ) );
     70        }
    5871    }
    5972
     
    618631        }
    619632    }
     633
     634    /**
     635     * Return the current database version without hitting the database.
     636     *
     637     * This is used to bypass cache problems with some multisite tests. See #31130.
     638     *
     639     * @todo Don't do this anymore once #31130 is fixed.
     640     *
     641     * @since 4.4.0
     642     */
     643    public function db_version() {
     644        return $this->db_version;
     645    }
    620646}
Note: See TracChangeset for help on using the changeset viewer.