-
Notifications
You must be signed in to change notification settings - Fork 85
Migration: Re-use async batch infrastructure #1343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
26a7110
Migration: Re-use async batch infrastructure
obenland 0902256
Merge branch 'trunk' into update/migration-async-jobs
obenland 4ddc3d0
Update to using new async_batch approach
obenland 181ae02
Update return type
obenland 8677298
Remove test for removed functionality
obenland 89b9d90
Merge branch 'trunk' into update/migration-async-jobs
obenland 23d54e4
Merge branch 'trunk' into update/migration-async-jobs
obenland 1e5f8ba
Merge branch 'trunk' into update/migration-async-jobs
obenland f98c706
Merge branch 'trunk' into update/migration-async-jobs
obenland 69bcfb7
Replace hardcoded async batch allowlist with extensible registration …
obenland 681aa0c
Register Dispatcher callbacks
obenland ef10921
Merge branch 'trunk' into update/migration-async-jobs
obenland 8fc596b
Update includes/class-migration.php
obenland b83a7e5
Merge branch 'trunk' into update/migration-async-jobs
pfefferle e1f2093
Merge branch 'trunk' into update/migration-async-jobs
obenland a29c90c
Merge branch 'trunk' into update/migration-async-jobs
obenland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,12 @@ | |
|
||
namespace Activitypub\Tests; | ||
|
||
use Activitypub\Migration; | ||
use Activitypub\Comment; | ||
use Activitypub\Activity\Actor; | ||
use Activitypub\Collection\Actors; | ||
use Activitypub\Collection\Extra_Fields; | ||
use Activitypub\Collection\Followers; | ||
use Activitypub\Collection\Outbox; | ||
use Activitypub\Comment; | ||
use Activitypub\Migration; | ||
use Activitypub\Scheduler; | ||
|
||
/** | ||
* Test class for Activitypub Migrate. | ||
|
@@ -167,23 +166,6 @@ | |
$this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ); | ||
} | ||
|
||
/** | ||
* Tests scheduling of migration. | ||
* | ||
* @covers ::maybe_migrate | ||
*/ | ||
public function test_migration_scheduling() { | ||
update_option( 'activitypub_db_version', '0.0.1' ); | ||
|
||
Migration::maybe_migrate(); | ||
|
||
$schedule = \wp_next_scheduled( 'activitypub_migrate', array( '0.0.1' ) ); | ||
$this->assertNotFalse( $schedule ); | ||
|
||
// Clean up. | ||
delete_option( 'activitypub_db_version' ); | ||
} | ||
|
||
/** | ||
* Test migrate to 4.1.0. | ||
* | ||
|
@@ -396,12 +378,12 @@ | |
Comment::register_comment_types(); | ||
|
||
// Create test comments. | ||
$post_id = $this->factory->post->create( | ||
$post_id = self::factory()->post->create( | ||
array( | ||
'post_author' => 1, | ||
) | ||
); | ||
$comment_id = $this->factory->comment->create( | ||
$comment_id = self::factory()->comment->create( | ||
array( | ||
'comment_post_ID' => $post_id, | ||
'comment_approved' => '1', | ||
|
@@ -419,41 +401,6 @@ | |
wp_delete_post( $post_id, true ); | ||
} | ||
|
||
/** | ||
* Test update_comment_counts() with existing valid lock. | ||
* | ||
* @covers ::update_comment_counts | ||
*/ | ||
public function test_update_comment_counts_with_existing_valid_lock() { | ||
// Register comment types. | ||
Comment::register_comment_types(); | ||
|
||
// Set a lock. | ||
Migration::lock(); | ||
|
||
Migration::update_comment_counts( 10, 0 ); | ||
|
||
// Verify a scheduled event was created. | ||
$next_scheduled = wp_next_scheduled( | ||
'activitypub_update_comment_counts', | ||
array( | ||
'batch_size' => 10, | ||
'offset' => 0, | ||
) | ||
); | ||
$this->assertNotFalse( $next_scheduled ); | ||
|
||
// Clean up. | ||
delete_option( 'activitypub_migration_lock' ); | ||
wp_clear_scheduled_hook( | ||
'activitypub_update_comment_counts', | ||
array( | ||
'batch_size' => 10, | ||
'offset' => 0, | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Test create post outbox items. | ||
* | ||
|
@@ -525,43 +472,15 @@ | |
$this->assertEquals( 5, count( $outbox_items ) ); | ||
} | ||
|
||
/** | ||
* Test async upgrade functionality. | ||
* | ||
* @covers ::async_upgrade | ||
* @covers ::lock | ||
* @covers ::unlock | ||
* @covers ::create_post_outbox_items | ||
*/ | ||
public function test_async_upgrade() { | ||
// Test that lock prevents simultaneous upgrades. | ||
Migration::lock(); | ||
Migration::async_upgrade( 'create_post_outbox_items' ); | ||
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items' ) ); | ||
$this->assertNotFalse( $scheduled ); | ||
Migration::unlock(); | ||
|
||
// Test scheduling next batch when callback returns more work. | ||
Migration::async_upgrade( 'create_post_outbox_items', 1, 0 ); // Small batch size to force multiple batches. | ||
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items', 1, 1 ) ); | ||
$this->assertNotFalse( $scheduled ); | ||
|
||
// Test no scheduling when callback returns null (no more work). | ||
Migration::async_upgrade( 'create_post_outbox_items', 100, 1000 ); // Large offset to ensure no posts found. | ||
$this->assertFalse( | ||
\wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items', 100, 1100 ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Test async upgrade with multiple arguments. | ||
* | ||
* @covers ::async_upgrade | ||
Check warning on line 478 in tests/includes/class-test-migration.php
|
||
*/ | ||
public function test_async_upgrade_multiple_args() { | ||
// Test that multiple arguments are passed correctly. | ||
Migration::async_upgrade( 'update_comment_counts', 50, 100 ); | ||
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'update_comment_counts', 50, 150 ) ); | ||
Scheduler::async_batch( array( Migration::class, 'update_comment_counts' ), 50, 100 ); | ||
$scheduled = \wp_next_scheduled( 'activitypub_async_batch', array( array( Migration::class, 'update_comment_counts' ), 50, 150 ) ); | ||
$this->assertFalse( $scheduled, 'Should not schedule next batch when no comments found' ); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.