Skip to content

Commit ba11aa9

Browse files
authored
Unwrap RoutingQueue when identifying the queue driver (#4855)
The queue connection is wrapped in a RoutingQueue (#4853) so pushes can be routed by job class. identifyQueueDriver() derived the driver name from the connection's class, so it began reporting 'routing' instead of the real backend (redis/database/sync) in `flarum info` and the admin dashboard. Unwrap a RoutingQueue via its public getDriver() before reading the class name, so the reported driver reflects the actual backend again.
1 parent e73790b commit ba11aa9

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

framework/core/src/Foundation/ApplicationInfoProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Carbon\Carbon;
1313
use Flarum\Database\DatabaseRequirements;
1414
use Flarum\Locale\Translator;
15+
use Flarum\Queue\RoutingQueue;
1516
use Flarum\User\SessionManager;
1617
use Illuminate\Console\Scheduling\Schedule;
1718
use Illuminate\Contracts\Cache\Repository as CacheRepository;
@@ -57,8 +58,13 @@ public function getSchedulerStatus(): string
5758

5859
public function identifyQueueDriver(): string
5960
{
61+
// The connection is wrapped in a RoutingQueue so pushes can be routed by
62+
// job class; the driver underneath is what identifies the queue backend.
63+
$queue = $this->queue instanceof RoutingQueue
64+
? $this->queue->getDriver()
65+
: $this->queue;
6066
// Get class name
61-
$queue = $this->queue::class;
67+
$queue = $queue::class;
6268
// Drop the namespace
6369
$queue = Str::afterLast($queue, '\\');
6470
// Lowercase the class name

framework/core/tests/unit/Foundation/ApplicationInfoProviderTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
use Flarum\Foundation\ApplicationInfoProvider;
1313
use Flarum\Foundation\Config;
1414
use Flarum\Locale\Translator;
15+
use Flarum\Queue\RoutingQueue;
1516
use Flarum\Testing\unit\TestCase;
1617
use Flarum\User\SessionManager;
1718
use Illuminate\Console\Scheduling\Schedule;
1819
use Illuminate\Contracts\Cache\Repository as CacheRepository;
1920
use Illuminate\Contracts\Queue\Queue;
2021
use Illuminate\Database\ConnectionInterface;
22+
use Illuminate\Queue\QueueRoutes;
23+
use Illuminate\Queue\SyncQueue;
2124
use Mockery as m;
2225
use PHPUnit\Framework\Attributes\Test;
2326
use SessionHandlerInterface;
@@ -73,12 +76,34 @@ public function sqlite_driver_is_never_flagged_and_does_not_query_the_server()
7376
$this->assertNull($provider->identifyDatabaseDriverMismatch());
7477
}
7578

79+
#[Test]
80+
public function queue_driver_is_derived_from_the_connection_class()
81+
{
82+
$provider = $this->provider('sqlite', null, new SyncQueue());
83+
84+
$this->assertSame('sync', $provider->identifyQueueDriver());
85+
}
86+
87+
#[Test]
88+
public function queue_driver_reports_the_real_driver_when_wrapped_in_a_routing_queue()
89+
{
90+
// flarum.queue.connection is wrapped in a RoutingQueue so pushes can be
91+
// routed by job class. Reporting "routing" would hide the real backend
92+
// from `flarum info` and the admin dashboard; unwrap to the driver.
93+
$driver = new SyncQueue();
94+
$wrapped = new RoutingQueue($driver, new QueueRoutes());
95+
96+
$provider = $this->provider('sqlite', null, $wrapped);
97+
98+
$this->assertSame('sync', $provider->identifyQueueDriver());
99+
}
100+
76101
/**
77102
* Build a provider with a configured driver and the version string the
78103
* server would report from `select version()`. Pass a null version for
79104
* drivers that should never trigger a version query (pgsql/sqlite).
80105
*/
81-
private function provider(string $configuredDriver, ?string $serverVersion): ApplicationInfoProvider
106+
private function provider(string $configuredDriver, ?string $serverVersion, ?Queue $queue = null): ApplicationInfoProvider
82107
{
83108
$cache = m::mock(CacheRepository::class);
84109
// Execute the cached closure inline so the detection logic is exercised.
@@ -108,7 +133,7 @@ private function provider(string $configuredDriver, ?string $serverVersion): App
108133
$config,
109134
m::mock(SessionManager::class),
110135
m::mock(SessionHandlerInterface::class),
111-
m::mock(Queue::class),
136+
$queue ?? m::mock(Queue::class),
112137
);
113138
}
114139
}

0 commit comments

Comments
 (0)