aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/lib/classes/FileLockTest.php
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-05-10 22:36:06 +0000
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-05-10 22:36:06 +0000
commitc054faf90288a75fc3680480434ba93b7f5b287b (patch)
tree0ced27539a1824ae6fd507899f84b67c12c6360d /tests/unit/lib/classes/FileLockTest.php
parent021a1958f0d4a881396b37bb4cf436c8525b1d62 (diff)
rework locking and drop CRONJOBS_ESCALATION setting, fixes #771
Closes #771 Merge request studip/studip!592
Diffstat (limited to 'tests/unit/lib/classes/FileLockTest.php')
-rw-r--r--tests/unit/lib/classes/FileLockTest.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/unit/lib/classes/FileLockTest.php b/tests/unit/lib/classes/FileLockTest.php
new file mode 100644
index 0000000..b593794
--- /dev/null
+++ b/tests/unit/lib/classes/FileLockTest.php
@@ -0,0 +1,44 @@
+<?php
+/*
+ * Copyright (c) 2022 Elmar Ludwig
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+class FileLockTest extends \Codeception\Test\Unit
+{
+ public function testAquireLock()
+ {
+ $lock = new FileLock('test');
+ $lock2 = new FileLock('test');
+
+ $this->assertTrue($lock->tryLock());
+ $lock->release();
+
+ $this->assertTrue($lock2->tryLock());
+ $lock2->release();
+ }
+
+ public function testBusyLock()
+ {
+ $lock = new FileLock('test');
+ $lock2 = new FileLock('test');
+
+ $data = ['foo' => '42'];
+ $this->assertTrue($lock->tryLock($data));
+
+ // test updating a lock
+ $data = ['foo' => 'bar'];
+ $this->assertTrue($lock->tryLock($data));
+
+ // aquiring the lock should fail
+ $data = [];
+ $this->assertFalse($lock2->tryLock($data));
+ $this->assertEquals('bar', $data['foo']);
+
+ $lock->release();
+ }
+}