Added locking to short URL creation when checking if URL exists

This commit is contained in:
Alejandro Celaya
2021-05-02 10:33:27 +02:00
parent bf0c679a48
commit 3ff4ac84c4
9 changed files with 68 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Entity\Domain;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
use Shlinkio\Shlink\Core\Model\Visitor;
@@ -180,12 +181,18 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->flush();
self::assertTrue($this->repo->shortCodeIsInUse('my-cool-slug'));
self::assertFalse($this->repo->shortCodeIsInUse('my-cool-slug', 'doma.in'));
self::assertFalse($this->repo->shortCodeIsInUse('slug-not-in-use'));
self::assertFalse($this->repo->shortCodeIsInUse('another-slug'));
self::assertFalse($this->repo->shortCodeIsInUse('another-slug', 'example.com'));
self::assertTrue($this->repo->shortCodeIsInUse('another-slug', 'doma.in'));
self::assertTrue($this->repo->shortCodeIsInUse(ShortUrlIdentifier::fromShortCodeAndDomain('my-cool-slug')));
self::assertFalse($this->repo->shortCodeIsInUse(
ShortUrlIdentifier::fromShortCodeAndDomain('my-cool-slug', 'doma.in'),
));
self::assertFalse($this->repo->shortCodeIsInUse(ShortUrlIdentifier::fromShortCodeAndDomain('slug-not-in-use')));
self::assertFalse($this->repo->shortCodeIsInUse(ShortUrlIdentifier::fromShortCodeAndDomain('another-slug')));
self::assertFalse($this->repo->shortCodeIsInUse(
ShortUrlIdentifier::fromShortCodeAndDomain('another-slug', 'example.com'),
));
self::assertTrue($this->repo->shortCodeIsInUse(
ShortUrlIdentifier::fromShortCodeAndDomain('another-slug', 'doma.in'),
));
}
/** @test */