Make WordPress Core

Opened 10 years ago

Closed 17 months ago

Last modified 14 months ago

#31463 closed defect (bug) (fixed)

Avoid reaching inside the object cache object in tests

Reported by: rmccue's profile rmccue Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description

It'd be really fantastically great if WP_UnitTestCase::flush_cache could keep its hands off my internal properties. :)

Right now, flush_cache reaches into $wp_object_cache and messes with a bunch of internal properties:

$wp_object_cache->group_ops = array();
$wp_object_cache->stats = array();
$wp_object_cache->memcache_debug = array();
$wp_object_cache->cache = array();

If we could just not do that, that'd be greaaaat.

Attachments (1)

31463.diff (569 bytes) - added by voldemortensen 10 years ago.

Download all attachments as: .zip

Change History (14)

#1 @wonderboymusic
10 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.2

#3 @voldemortensen
10 years ago

  • Keywords has-patch added; needs-patch removed

I couldn't find anywhere that was actually setting these properties anyway. I don't know if I'm missing something but I don't see a purpose for these lines. The $wp_object_cache->cache = array(); seems to be redundant as that's what wp_cache_flush does.

#4 @dd32
10 years ago

@voldemortensen FWIW, those lines are included for external object caches, not the core classes. Those properties, and __remoteset are used by Memcache, but others might use something different (I don't think __remoteset is even used in a published object cache, I think it's only used by the internal wp.com one)

See https://plugins.trac.wordpress.org/browser/memcached/tags/2.0.2/object-cache.php#L189 and https://plugins.trac.wordpress.org/browser/memcached-redux/tags/0.1.3/object-cache.php#L215

I guess we'd have to add a new method/parameter to do this, and even possibly include the back-compat code here.

#5 @DrewAPicture
10 years ago

  • Milestone changed from 4.2 to Future Release

Moving off of the 4.2 milestone as this is a release-independent change.

#6 @spacedmonkey
17 months ago

@SergeyBiryukov Could we use wp_cache_flush_runtime here?

This ticket was mentioned in PR #4417 on WordPress/wordpress-develop by @spacedmonkey.


17 months ago
#7

  • Keywords has-unit-tests added

#8 @spacedmonkey
17 months ago

  • Keywords commit added
  • Milestone changed from Future Release to 6.3
  • Owner set to spacedmonkey
  • Status changed from new to assigned

This ticket was mentioned in Slack in #hosting-community by spacedmonkey. View the logs.


17 months ago

@tillkruess commented on PR #4417:


17 months ago
#10

LGTM

#11 @spacedmonkey
17 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 55741:

Build/Test Tools: Call wp_cache_flush_runtime in WP_UnitTestCase.

In WP_UnitTestCase::flush_cache method, the properties of the global $wp_object_cache object were manaully being reset to flush the cache. The function wp_cache_flush_runtime was added in [52772] and is designed to reset any class properties to default values. Using wp_cache_flush_runtime improve compatibility with third party object caches, as it allows developers to define their own wp_cache_flush_runtime function.

Props rmccue, johnbillion, wonderboymusic, boonebgorges, voldemortensen, dd32, DrewAPicture, tillkruess, spacedmonkey.
Fixes #31463.

Note: See TracTickets for help on using tickets.