From 98929ca9838a60d5dc8a5f454ab101170f1975bc Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 9 Apr 2024 21:13:28 +0200 Subject: [PATCH] [ticket/17077] Add test for posting lock PHPBB3-17077 --- tests/lock/posting_test.php | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/lock/posting_test.php diff --git a/tests/lock/posting_test.php b/tests/lock/posting_test.php new file mode 100644 index 0000000000..e9a9cdfffb --- /dev/null +++ b/tests/lock/posting_test.php @@ -0,0 +1,54 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +use phpbb\cache\driver\file as file_cache; +use phpbb\config\config; +use phpbb\lock\posting; + +class phpbb_lock_posting_test extends phpbb_test_case +{ + /** @var \phpbb\cache\driver\file */ + protected $cache; + + /** @var config */ + protected $config; + + /** @var posting */ + protected $lock; + + public function setUp(): void + { + $this->cache = new file_cache(__DIR__ . '/../tmp/'); + $this->cache->purge(); // ensure cache is clean + $this->config = new config([ + 'flood_interval' => 15, + ]); + $this->lock = new posting($this->cache, $this->config); + } + + public function test_lock_acquire() + { + $this->assertTrue($this->lock->acquire(100, 'foo')); + $this->assertFalse($this->lock->acquire(100, 'foo')); + + $this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock')); + $this->lock->release(); + $this->assertFalse($this->cache->_exists(sha1('100foo') . '_posting_lock')); + + $this->assertTrue($this->lock->acquire(100, 'foo')); + $this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock')); + $this->lock->release(); + $this->lock->release(); // double release has no effect + $this->assertFalse($this->cache->_exists(sha1('100foo') . '_posting_lock')); + } +} \ No newline at end of file