Issue #94: added more tests for acquiring a lock with timeout jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 11 Dec 2017 14:11:56 +0000
branchjv
changeset 1963 d1eb7b03018a
parent 1962 19bb5e423587
child 1964 47797e5b62a6
Issue #94: added more tests for acquiring a lock with timeout
RegressionTests__RecursionLockTests.st
--- a/RegressionTests__RecursionLockTests.st	Mon Dec 11 11:05:39 2017 +0000
+++ b/RegressionTests__RecursionLockTests.st	Mon Dec 11 14:11:56 2017 +0000
@@ -321,6 +321,64 @@
     p2 resume.
 
     "Created: / 11-12-2017 / 10:22:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_critical_09a
+
+    | p1 p2 |
+
+    p1 := [
+        lock critical:[ 
+            Delay waitForMilliseconds: 1000.  
+        ].
+    ] newProcess.
+
+    p2 := [ 
+        | timeouted |
+
+        timeouted := false.
+        Delay waitForMilliseconds: 100. "/ Give p1 chance to lock the thread.
+        self assert: lock owner == p1.
+        self assert: lock count == 1.         
+        lock critical: [ Delay waitForMilliseconds: 10 ] "/ Some tiny work.
+            timeoutMs: 500
+           ifBlocking: [ timeouted := true ].
+        self assert: timeouted.
+    ] newProcess.
+
+    p1 resume.
+    p2 resume.
+
+    "Created: / 11-12-2017 / 14:09:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_critical_09b
+
+    | p1 p2 |
+
+    p1 := [
+        lock critical:[ 
+            Delay waitForMilliseconds: 500.  
+        ].
+    ] newProcess.
+
+    p2 := [ 
+        | timeouted |
+
+        timeouted := false.
+        Delay waitForMilliseconds: 100. "/ Give p1 chance to lock the thread.
+        self assert: lock owner == p1.
+        self assert: lock count == 1.         
+        lock critical: [ Delay waitForMilliseconds: 10 ] "/ Some tiny work.
+            timeoutMs: 1000
+           ifBlocking: [ timeouted := true ].
+        self assert: timeouted not.
+    ] newProcess.
+
+    p1 resume.
+    p2 resume.
+
+    "Created: / 11-12-2017 / 14:09:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !RecursionLockTests class methodsFor:'documentation'!