Current State

One unit test exists: ExponentialMovingAverageTest — covers the EMA utility class with 4 data-provider cases. Everything else is untested.

Recommended Test Coverage

Unit Tests (mock all dependencies, fast)

MonitoredQueueTest — The decorator is the core of the module.
- claimItem() dispatches PROCESSING_STARTED with correct timestamp and queue ref
- deleteItem() dispatches PROCESSING_COMPLETED
- releaseItem() dispatches PROCESSING_ABORTED
- createItem(), numberOfItems(), createQueue(), deleteQueue() proxy to the wrapped queue unchanged
- garbageCollection() calls through only when wrapped queue implements QueueGarbageCollectionInterface
- getName() returns the name passed at construction

MonitoredQueueFactoryTest — Verify the factory decoration.
- get() returns a MonitoredQueue wrapping the real queue
- The wrapped queue's name matches what was requested

QueueItemEventTest — Simple value object, but worth a quick sanity test.
- Getters return what was passed to the constructor
- Event name constants are the expected strings

QueueStatisticManagerTest — Plugin manager + event routing.
- getDefinitions() returns plugins sorted by order
- onEvent() calls the correct method on subscribed plugins (e.g., PROCESSING_COMPLETED calls trackCompletion)
- resetStatistics() calls reset() on every plugin for every queue
- getSubscribedEvents() returns the three expected event names

ProcessingRateTest — The most complex statistic plugin.
- Returns 0 or null when no data has been collected
- After multiple PROCESSING_COMPLETED events at known intervals, getValue() returns the expected rate
- formatValue() scales correctly (items/second vs items/minute vs items/hour)
- reset() clears stored state

ProcessingTimeTest
- trackStart() stores item ID keyed state
- trackCompletion() calculates duration from stored start time
- getValue() returns the EMA of processing durations
- formatValue() delegates to DateIntervalStatistic trait correctly

QueueTimeTest
- Calculates event timestamp - item->created correctly
- Handles items without a created property gracefully (or documents that it doesn't)

EstimatedTimeToFinishTest
- Returns numberOfItems / processingRate when both are available
- Returns null/0 when processing rate is 0 (division by zero guard)
- formatValue() produces a readable interval

Kernel Tests (boot Drupal, real plugin discovery)

QueueStatsServiceIntegrationTest — Verify the service container wiring.
- The queue service returns a MonitoredQueueFactory instance
- plugin.manager.queue_stat discovers all 5 statistic plugins
- Creating a queue via the factory and processing an item through claim/delete triggers events that update statistic state

ListBlockTest — The block plugin renders correctly.
- Block build produces a table render array with expected structure
- Queue/statistic filtering config works (selected queues only, selected stats only)
- hide_if_empty config hides rows when the chosen stat is empty

What to Skip (for now)

- AdminForm — thin UI glue, low logic density, better tested via functional/browser tests later
- DynamicLocalTasks — depends on Queue UI module presence, niche integration
- MonitoredQueueUIManager / QueueStatsServiceProvider — Queue UI integration, optional and hard to test in isolation without that module installed

Priority Order

1. MonitoredQueueTest — highest value, core decorator logic, easy to write with mocks
2. ProcessingRateTest and ProcessingTimeTest — most complex calculation logic
3. QueueStatisticManagerTest — event routing is the glue that makes everything work
4. EstimatedTimeToFinishTest and QueueTimeTest — simpler plugins, quick wins
5. QueueStatsServiceIntegrationTest (kernel) — confirms wiring works end-to-end
6. ListBlockTest (kernel) — render output verification

Test Location

All tests go queue_stats/test/src/ following the existing structure:
- test/src/Unit/ for unit tests
- test/src/Kernel/ for kernel tests

Group annotation: @group queue_stats

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

benstallings created an issue. See original summary.

benstallings’s picture

Issue summary: View changes

benstallings’s picture

Assigned: benstallings » Unassigned
Status: Active » Needs review