Concurrency tests

This commit is contained in:
Nicolas Le Goff
2014-06-30 15:12:01 +02:00
parent 1f17c086ac
commit 7818a5e8e3
6 changed files with 55 additions and 50 deletions

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Doctrine\DBAL\DBALException;
class ACL implements cache_cacheableInterface
{
@@ -1103,7 +1104,16 @@ class ACL implements cache_cacheableInterface
foreach ($base_ids as $base_id) {
if (!isset($this->_rights_bas[$base_id])) {
$stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
try {
$stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
} catch (DBALException $e) {
// if (null !== $e) {
// var_dump(get_class($e->getPrevious()));
// }
if (($e->getCode() == 23000)) {
$to_update[] = $base_id;
}
}
} elseif ($this->_rights_bas[$base_id]['actif'] === false) {
$to_update[] = $base_id;
}
@@ -1429,14 +1439,18 @@ class ACL implements cache_cacheableInterface
$iord = 0;
foreach ($this->get_granted_base([], [$databox->get_sbas_id()]) as $collection) {
$stmt->execute([
':site_id' => $this->app['conf']->get(['main', 'key']),
':usr_id' => $this->user->getId(),
':coll_id' => $collection->get_coll_id(),
':mask_and' => $this->get_mask_and($collection->get_base_id()),
':mask_xor' => $this->get_mask_xor($collection->get_base_id()),
':ord' => $iord++
]);
try {
$stmt->execute([
':site_id' => $this->app['conf']->get(['main', 'key']),
':usr_id' => $this->user->getId(),
':coll_id' => $collection->get_coll_id(),
':mask_and' => $this->get_mask_and($collection->get_base_id()),
':mask_xor' => $this->get_mask_xor($collection->get_base_id()),
':ord' => $iord++
]);
} catch (DBALException $e) {
}
}
$stmt->closeCursor();

View File

@@ -65,7 +65,7 @@ class ManipulatorServiceProviderTest extends ServiceProviderTestCase
[
'Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider',
'manipulator.webhook-delivery',
'Alchemy\Phrasea\Model\Manipulator\WebhookEventDelivery'
'Alchemy\Phrasea\Model\Manipulator\WebhookEventDeliveryManipulator'
],
];
}

View File

@@ -55,10 +55,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase
{
$manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']);
$application = $manipulator->create(
'desktop-app',
'desktop-app2',
ApiApplication::DESKTOP_TYPE,
'Desktop application description',
'http://desktop-app-url.net'
'http://desktop-app2-url.net'
);
$applicationSave = clone $application;
$countBefore = count(self::$DI['app']['repo.api-applications']->findAll());
@@ -77,10 +77,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase
{
$manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']);
$application = $manipulator->create(
'desktop-app',
'desktop-app3',
ApiApplication::DESKTOP_TYPE,
'Desktop application description',
'http://desktop-app-url.net'
'http://desktop-app3-url.net'
);
$application->setName('new-desktop-app');
$manipulator->update($application);
@@ -92,10 +92,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase
{
$manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']);
$application = $manipulator->create(
'desktop-app',
'desktop-app4',
ApiApplication::DESKTOP_TYPE,
'Desktop application description',
'http://desktop-app-url.net'
'http://desktop-app4-url.net'
);
try {
$manipulator->setType($application, 'invalid-type');
@@ -109,20 +109,20 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase
{
$manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']);
$application = $manipulator->create(
'desktop-app',
'desktop-app5',
ApiApplication::DESKTOP_TYPE,
'Desktop application description',
'http://desktop-app-url.net'
'http://desktop-app5-url.net'
);
$manipulator->setRedirectUri($application, 'invalid-url.com');
$this->assertEquals(ApiApplication::NATIVE_APP_REDIRECT_URI, $application->getRedirectUri());
$application = $manipulator->create(
'web-app',
'web-app2',
ApiApplication::WEB_TYPE,
'Desktop application description',
'http://web-app-url.net',
'http://web-app2-url.net',
self::$DI['user'],
'http://web-app-url.net/callback'
);
@@ -138,10 +138,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase
{
$manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']);
$application = $manipulator->create(
'desktop-app',
'desktop-app6',
ApiApplication::DESKTOP_TYPE,
'Desktop application description',
'http://desktop-app-url.net'
'http://desktop-app6-url.net'
);
try {
$manipulator->setWebsiteUrl($application, 'invalid-url.com');

View File

@@ -10,7 +10,7 @@ class WebhookEventManipulatorTest extends \PhraseanetTestCase
{
public function testCreate()
{
$manipulator = new WebhookEventManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.manipulator.webhook-delivery']);
$manipulator = new WebhookEventManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.webhook-delivery']);
$nbEvents = count(self::$DI['app']['repo.webhook-event']->findAll());
$event = $manipulator->create(WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, array(
'feed_id' => self::$DI['feed_public_entry']->getFeed()->getId(), 'entry_id' => self::$DI['feed_public_entry']->getId()
@@ -24,13 +24,9 @@ class WebhookEventManipulatorTest extends \PhraseanetTestCase
$event = $manipulator->create(WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, array(
'feed_id' => self::$DI['feed_public_entry']->getFeed()->getId(), 'entry_id' => self::$DI['feed_public_entry']->getId()
));
$eventMem = clone $event;
$countBefore = count(self::$DI['app']['repo.webhook-event']->findAll());
self::$DI['app']['manipulator.webhook-delivery']->create($event);
$manipulator->delete($event);
$this->assertGreaterThan(count(self::$DI['app']['repo.webhook-event']->findAll()), $countBefore);
$tokens = self::$DI['app']['repo.api-oauth-tokens']->findOauthTokens($eventMem);
$this->assertEquals(0, count($tokens));
}
public function testUpdate()

View File

@@ -48,6 +48,8 @@ abstract class PhraseanetTestCase extends WebTestCase
private function initializeSqliteDB($path = '/tmp/db.sqlite')
{
$path = $path . getmypid();
if (is_file($path)) {
unlink($path);
}
@@ -375,6 +377,14 @@ abstract class PhraseanetTestCase extends WebTestCase
->method('getSubscribedEvents')
->will($this->returnValue([]));
$app['EM.dbal-conf'] = $app->share($app->extend('EM.dbal-conf', function ($conf, $app) {
if (isset($conf['path'])) {
$conf['path'] = $conf['path'].getmypid();
}
return $conf;
}));
$app['EM'] = $app->share($app->extend('EM', function ($em) {
$this->initializeSqliteDB();
@@ -514,9 +524,11 @@ abstract class PhraseanetTestCase extends WebTestCase
*/
public static function giveRightsToUser(Application $app, User $user, $base_ids = null)
{
$app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_GLOBAL_RIGHTS);
$app['acl']->get($user)->give_access_to_sbas(array_keys($app['phraseanet.appbox']->get_databoxes()));
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
$app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_SBAS);
$rights = [
'bas_manage' => '1'
@@ -534,6 +546,12 @@ abstract class PhraseanetTestCase extends WebTestCase
$base_id = $collection->get_base_id();
$app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_BAS);
if ($app['acl']->get($user)->has_access_to_base($base_id)) {
continue;
}
$app['acl']->get($user)->give_access_to_base([$base_id]);
$app['acl']->get($user)->update_rights_to_base($base_id, ['order_master' => true]);

View File

@@ -1,23 +0,0 @@
<?php
use Alchemy\Phrasea\Exception\RuntimeException;
class API_WebhookTest extends \PhraseanetTestCase
{
public function testsNewApiHook()
{
$w = \API_Webhook::create(self::$DI['app']['phraseanet.appbox'], 'new_feed', array('w1', 'salut' => 'you'));
$this->assertInstanceOf('\API_webhook', $w);
$w->delete();
}
public function testNewApiHookObjectNotFound()
{
try {
$w = new \API_Webhook(self::$DI['app']['phraseanet.appbox'], -1);
$this->fail('It should raise an exception');
} catch (RuntimeException $e) {
}
}
}