File tree Expand file tree Collapse file tree 5 files changed +33
-1
lines changed
Expand file tree Collapse file tree 5 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,18 @@ public function owner()
150150 */
151151 public function isOwnedByCurrentProcess ()
152152 {
153- return $ this ->getCurrentOwner () === $ this ->owner ;
153+ return $ this ->isOwnedBy ($ this ->owner );
154+ }
155+
156+ /**
157+ * Determine whether this lock is owned by the given identifier.
158+ *
159+ * @param string|null $owner
160+ * @return bool
161+ */
162+ public function isOwnedBy ($ owner )
163+ {
164+ return $ this ->getCurrentOwner () === $ owner ;
154165 }
155166
156167 /**
Original file line number Diff line number Diff line change @@ -104,9 +104,12 @@ public function testOtherOwnerDoesNotOwnLockAfterRestore()
104104 Cache::lock ('foo ' )->forceRelease ();
105105
106106 $ firstLock = Cache::lock ('foo ' , 10 );
107+ $ this ->assertTrue ($ firstLock ->isOwnedBy (null ));
107108 $ this ->assertTrue ($ firstLock ->get ());
109+ $ this ->assertTrue ($ firstLock ->isOwnedBy ($ firstLock ->owner ()));
108110
109111 $ secondLock = Cache::store ('file ' )->restoreLock ('foo ' , 'other_owner ' );
112+ $ this ->assertTrue ($ secondLock ->isOwnedBy ($ firstLock ->owner ()));
110113 $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
111114 }
112115}
Original file line number Diff line number Diff line change @@ -97,9 +97,12 @@ public function testOtherOwnerDoesNotOwnLockAfterRestore()
9797 Cache::store ('memcached ' )->lock ('foo ' )->forceRelease ();
9898
9999 $ firstLock = Cache::store ('memcached ' )->lock ('foo ' , 10 );
100+ $ this ->assertTrue ($ firstLock ->isOwnedBy (null ));
100101 $ this ->assertTrue ($ firstLock ->get ());
102+ $ this ->assertTrue ($ firstLock ->isOwnedBy ($ firstLock ->owner ()));
101103
102104 $ secondLock = Cache::store ('memcached ' )->restoreLock ('foo ' , 'other_owner ' );
105+ $ this ->assertTrue ($ secondLock ->isOwnedBy ($ firstLock ->owner ()));
103106 $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
104107 }
105108}
Original file line number Diff line number Diff line change @@ -126,9 +126,12 @@ public function testOtherOwnerDoesNotOwnLockAfterRestore()
126126 Cache::store ('redis ' )->lock ('foo ' )->forceRelease ();
127127
128128 $ firstLock = Cache::store ('redis ' )->lock ('foo ' , 10 );
129+ $ this ->assertTrue ($ firstLock ->isOwnedBy (null ));
129130 $ this ->assertTrue ($ firstLock ->get ());
131+ $ this ->assertTrue ($ firstLock ->isOwnedBy ($ firstLock ->owner ()));
130132
131133 $ secondLock = Cache::store ('redis ' )->restoreLock ('foo ' , 'other_owner ' );
134+ $ this ->assertTrue ($ secondLock ->isOwnedBy ($ firstLock ->owner ()));
132135 $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
133136 }
134137}
Original file line number Diff line number Diff line change @@ -56,4 +56,16 @@ public function testExpiredLockCanBeRetrieved()
5656
5757 $ otherLock ->release ();
5858 }
59+
60+ public function testOtherOwnerDoesNotOwnLockAfterRestore ()
61+ {
62+ $ firstLock = Cache::store ('database ' )->lock ('foo ' );
63+ $ this ->assertTrue ($ firstLock ->isOwnedBy (null ));
64+ $ this ->assertTrue ($ firstLock ->get ());
65+ $ this ->assertTrue ($ firstLock ->isOwnedBy ($ firstLock ->owner ()));
66+
67+ $ secondLock = Cache::store ('database ' )->restoreLock ('foo ' , 'other_owner ' );
68+ $ this ->assertTrue ($ secondLock ->isOwnedBy ($ firstLock ->owner ()));
69+ $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
70+ }
5971}
You can’t perform that action at this time.
0 commit comments