diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-26 14:18:01 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:38:19 +0200 |
commit | fd1ddad98df45bc3c18be7980c1cbe68ce6b219c (patch) | |
tree | e4017d3c979604f40e78cdc305f0ab191aedd4b9 /tests/bookmark/BookmarkInitializerTest.php | |
parent | 458b6b9918ec27154dd45416947bb93bedb97109 (diff) | |
download | Shaarli-fd1ddad98df45bc3c18be7980c1cbe68ce6b219c.tar.gz Shaarli-fd1ddad98df45bc3c18be7980c1cbe68ce6b219c.tar.zst Shaarli-fd1ddad98df45bc3c18be7980c1cbe68ce6b219c.zip |
Add mutex on datastore I/O operations
To make sure that there is no concurrent operation on the datastore file.
Fixes #1132
Diffstat (limited to 'tests/bookmark/BookmarkInitializerTest.php')
-rw-r--r-- | tests/bookmark/BookmarkInitializerTest.php | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index 25704004..0c8420ce 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use malkusch\lock\mutex\NoMutex; | ||
5 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
6 | use Shaarli\History; | 7 | use Shaarli\History; |
7 | use Shaarli\TestCase; | 8 | use Shaarli\TestCase; |
@@ -34,11 +35,15 @@ class BookmarkInitializerTest extends TestCase | |||
34 | /** @var BookmarkInitializer instance */ | 35 | /** @var BookmarkInitializer instance */ |
35 | protected $initializer; | 36 | protected $initializer; |
36 | 37 | ||
38 | /** @var NoMutex */ | ||
39 | protected $mutex; | ||
40 | |||
37 | /** | 41 | /** |
38 | * Initialize an empty BookmarkFileService | 42 | * Initialize an empty BookmarkFileService |
39 | */ | 43 | */ |
40 | public function setUp(): void | 44 | public function setUp(): void |
41 | { | 45 | { |
46 | $this->mutex = new NoMutex(); | ||
42 | if (file_exists(self::$testDatastore)) { | 47 | if (file_exists(self::$testDatastore)) { |
43 | unlink(self::$testDatastore); | 48 | unlink(self::$testDatastore); |
44 | } | 49 | } |
@@ -47,7 +52,7 @@ class BookmarkInitializerTest extends TestCase | |||
47 | $this->conf = new ConfigManager(self::$testConf); | 52 | $this->conf = new ConfigManager(self::$testConf); |
48 | $this->conf->set('resource.datastore', self::$testDatastore); | 53 | $this->conf->set('resource.datastore', self::$testDatastore); |
49 | $this->history = new History('sandbox/history.php'); | 54 | $this->history = new History('sandbox/history.php'); |
50 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 55 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
51 | 56 | ||
52 | $this->initializer = new BookmarkInitializer($this->bookmarkService); | 57 | $this->initializer = new BookmarkInitializer($this->bookmarkService); |
53 | } | 58 | } |
@@ -59,7 +64,7 @@ class BookmarkInitializerTest extends TestCase | |||
59 | { | 64 | { |
60 | $refDB = new \ReferenceLinkDB(); | 65 | $refDB = new \ReferenceLinkDB(); |
61 | $refDB->write(self::$testDatastore); | 66 | $refDB->write(self::$testDatastore); |
62 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 67 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
63 | $this->initializer = new BookmarkInitializer($this->bookmarkService); | 68 | $this->initializer = new BookmarkInitializer($this->bookmarkService); |
64 | 69 | ||
65 | $this->initializer->initialize(); | 70 | $this->initializer->initialize(); |
@@ -90,7 +95,7 @@ class BookmarkInitializerTest extends TestCase | |||
90 | $this->bookmarkService->save(); | 95 | $this->bookmarkService->save(); |
91 | 96 | ||
92 | // Reload from file | 97 | // Reload from file |
93 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 98 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
94 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); | 99 | $this->assertEquals($refDB->countLinks() + 3, $this->bookmarkService->count()); |
95 | 100 | ||
96 | $bookmark = $this->bookmarkService->get(43); | 101 | $bookmark = $this->bookmarkService->get(43); |
@@ -121,7 +126,7 @@ class BookmarkInitializerTest extends TestCase | |||
121 | public function testInitializeNonExistentDataStore(): void | 126 | public function testInitializeNonExistentDataStore(): void |
122 | { | 127 | { |
123 | $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); | 128 | $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); |
124 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 129 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, $this->mutex, true); |
125 | 130 | ||
126 | $this->initializer->initialize(); | 131 | $this->initializer->initialize(); |
127 | 132 | ||