Skip to content

Commit a378dc5

Browse files
committed
fix: preserve Reddit monitor lock refreshes
1 parent 0766b34 commit a378dc5

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

inc/Tracking/RedditCommentDomainStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public static function refreshLock( string $token ): bool {
116116
'token' => $token,
117117
'expires_at' => time() + ( 30 * MINUTE_IN_SECONDS ),
118118
);
119+
if ( $current === $replacement ) {
120+
return true;
121+
}
119122
return self::replaceLock( $current, $replacement );
120123
}
121124

tests/Unit/Abilities/Reddit/RedditCommentDomainMonitorAbilityTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ public function test_lock_is_non_autoloaded_and_only_owner_can_release_it(): voi
213213
$token = RedditCommentDomainStore::acquireLock();
214214
$this->assertIsString( $token );
215215
$this->assertWPError( RedditCommentDomainStore::acquireLock() );
216+
$this->assertTrue( RedditCommentDomainStore::refreshLock( $token ) );
217+
$this->assertTrue( RedditCommentDomainStore::refreshLock( $token ), 'A same-second owner refresh must remain idempotent.' );
218+
$this->assertFalse( RedditCommentDomainStore::refreshLock( 'different-owner' ) );
216219
RedditCommentDomainStore::releaseLock( 'different-owner' );
217220
$this->assertWPError( RedditCommentDomainStore::acquireLock() );
218221

0 commit comments

Comments
 (0)