-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from michalsn/skip-locked
Add `skipLocked` config for the `database` handler
- Loading branch information
Showing
6 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter Queue. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\Models; | ||
|
||
use CodeIgniter\Queue\Models\QueueJobModel; | ||
use CodeIgniter\Test\ReflectionHelper; | ||
use Tests\Support\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class QueueJobModelTest extends TestCase | ||
{ | ||
use ReflectionHelper; | ||
|
||
public function testQueueJobModel(): void | ||
{ | ||
$model = model(QueueJobModel::class); | ||
$this->assertInstanceOf(QueueJobModel::class, $model); | ||
} | ||
|
||
public function testSkipLocked(): void | ||
{ | ||
$model = model(QueueJobModel::class); | ||
$method = $this->getPrivateMethodInvoker($model, 'skipLocked'); | ||
|
||
$sql = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1'; | ||
$result = $method($sql); | ||
|
||
if ($model->db->DBDriver === 'SQLite3') { | ||
$this->assertSame($sql, $result); | ||
} elseif ($model->db->DBDriver === 'SQLSRV') { | ||
$expected = 'SELECT * FROM queue_jobs WITH (ROWLOCK,UPDLOCK,READPAST) WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1'; | ||
$this->assertSame($expected, $result); | ||
} else { | ||
$expected = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1 FOR UPDATE SKIP LOCKED'; | ||
$this->assertSame($expected, $result); | ||
} | ||
} | ||
|
||
public function testSkipLockedFalse(): void | ||
{ | ||
config('Queue')->database['skipLocked'] = false; | ||
|
||
$model = model(QueueJobModel::class); | ||
$method = $this->getPrivateMethodInvoker($model, 'skipLocked'); | ||
|
||
$sql = 'SELECT * FROM queue_jobs WHERE queue = "test" AND status = 0 AND available_at < 123456 LIMIT 1'; | ||
$result = $method($sql); | ||
|
||
$this->assertSame($sql, $result); | ||
} | ||
} |
This file contains 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