'SQL Queue', 'description' => 'Test SQL-backed queue items', 'group' => 'Queue', ); } /* ----------------------- Queue providers ----------------------- */ /* Define a list of queue providers which should be tested */ /** * Return a list of persistent and transient queue providers */ function getQueueSpecs() { $queueSpecs = array(); $queueSpecs[] = array( array( 'type' => 'Sql', 'name' => 'test-queue', )); return $queueSpecs; } /* ----------------------- Per-provider tests ----------------------- */ function setUp() { parent::setUp(); $this->queueService = CRM_Queue_Service::singleton(TRUE); } function tearDown() { CRM_Utils_Time::resetTime(); $tablesToTruncate = array('civicrm_queue_item'); $this->quickCleanup($tablesToTruncate); } /** * Create a few queue items; alternately enqueue and dequeue various * * @dataProvider getQueueSpecs */ function testPriorities($queueSpec) { $this->queue = $this->queueService->create($queueSpec); $this->assertTrue($this->queue instanceof CRM_Queue_Queue); $this->queue->createItem(array( 'test-key' => 'a', )); $this->queue->createItem(array( 'test-key' => 'b', )); $this->queue->createItem(array( 'test-key' => 'c', )); $this->assertEquals(3, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('a', $item->data['test-key']); $this->queue->deleteItem($item); $this->assertEquals(2, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('b', $item->data['test-key']); $this->queue->deleteItem($item); $this->queue->createItem( array( 'test-key' => 'start', ), array( 'weight' => -1, ) ); $this->queue->createItem( array( 'test-key' => 'end', ), array( 'weight' => 1, ) ); $this->queue->createItem(array( 'test-key' => 'd', )); $this->assertEquals(4, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('start', $item->data['test-key']); $this->queue->deleteItem($item); $this->assertEquals(3, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('c', $item->data['test-key']); $this->queue->deleteItem($item); $this->assertEquals(2, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('d', $item->data['test-key']); $this->queue->deleteItem($item); $this->assertEquals(1, $this->queue->numberOfItems()); $item = $this->queue->claimItem(); $this->assertEquals('end', $item->data['test-key']); $this->queue->deleteItem($item); $this->assertEquals(0, $this->queue->numberOfItems()); } }