Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 20, 2024
1 parent ca8e0b9 commit 5e2f5f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Models/QueueJobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ private function skipLocked(string $sql): string
}

if ($this->db->DBDriver === 'OCI8') {
$sql = preg_replace('/ OFFSET .*/', '', $sql);
$sql = "SELECT * FROM ({$sql}) WHERE ROWNUM = 1";
$sql = str_replace('SELECT *', 'SELECT "id"', $sql);
// prepare final query
$sql = sprintf('SELECT * FROM "%s" WHERE "id" = (%s)', $this->db->prefixTable($this->table), $sql);
}

return $sql .= ' FOR UPDATE SKIP LOCKED';
return $sql . ' FOR UPDATE SKIP LOCKED';
}

/**
Expand All @@ -118,7 +119,7 @@ private function setPriority(BaseBuilder $builder, array $priority): BaseBuilder
if ($priority !== ['default']) {
if ($this->db->DBDriver !== 'MySQLi') {
$builder->orderBy(
'CASE priority '
sprintf('CASE %s ', $this->db->protectIdentifiers('priority'))
. implode(
' ',
array_map(static fn ($value, $key) => "WHEN '{$value}' THEN {$key}", $priority, array_keys($priority))
Expand Down
6 changes: 2 additions & 4 deletions tests/Models/QueueJobModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public function testSkipLocked(): void
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);
$this->assertStringContainsString('WITH (ROWLOCK,UPDLOCK,READPAST) WHERE', $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);
$this->assertStringContainsString('FOR UPDATE SKIP LOCKED', $result);
}
}

Expand Down

0 comments on commit 5e2f5f7

Please sign in to comment.