Changeset 29939
- Timestamp:
- 10/17/2014 07:16:26 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/cron.php
r29732 r29939 21 21 */ 22 22 function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 23 // don't schedule a duplicate if there's already an identical event due in the next 10 minutes23 // don't schedule a duplicate if there's already an identical event due within 10 minutes of it 24 24 $next = wp_next_scheduled($hook, $args); 25 if ( $next && $next <= $timestamp + 10 * MINUTE_IN_SECONDS ) 26 return; 25 if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) { 26 return; 27 } 27 28 28 29 $crons = _get_cron_array(); -
trunk/tests/phpunit/tests/cron.php
r25368 r29939 215 215 // duplicate events far apart should work normally 216 216 $hook = rand_str(); 217 $args = array( rand_str());218 $ts1 = strtotime( '+30 minutes');219 $ts2 = strtotime( '+3 minutes');217 $args = array( rand_str() ); 218 $ts1 = strtotime( '+30 minutes' ); 219 $ts2 = strtotime( '+3 minutes' ); 220 220 221 221 // first one works … … 224 224 wp_schedule_single_event( $ts2, $hook, $args ); 225 225 226 // the next event should be at + 5 minutes, not +3227 $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args) );226 // the next event should be at +3 minutes, even though that one was scheduled second 227 $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) ); 228 228 wp_unschedule_event( $ts2, $hook, $args ); 229 // following event at +30 minutes should be there too 230 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 231 } 232 233 function test_not_duplicate_event_reversed() { 234 // duplicate events far apart should work normally regardless of order 235 $hook = rand_str(); 236 $args = array( rand_str() ); 237 $ts1 = strtotime( '+3 minutes' ); 238 $ts2 = strtotime( '+30 minutes' ); 239 240 // first one works 241 wp_schedule_single_event( $ts1, $hook, $args ); 242 // second works too 243 wp_schedule_single_event( $ts2, $hook, $args ); 244 245 // the next event should be at +3 minutes 246 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 247 wp_unschedule_event( $ts1, $hook, $args ); 229 248 // following event should be there too 230 $this->assertEquals( $ts 1, wp_next_scheduled($hook, $args) );249 $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) ); 231 250 } 232 251 }
Note: See TracChangeset
for help on using the changeset viewer.