File tree Expand file tree Collapse file tree 4 files changed +70
-1
lines changed Expand file tree Collapse file tree 4 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ public function owner()
148
148
*
149
149
* @return bool
150
150
*/
151
- protected function isOwnedByCurrentProcess ()
151
+ public function isOwnedByCurrentProcess ()
152
152
{
153
153
return $ this ->getCurrentOwner () === $ this ->owner ;
154
154
}
Original file line number Diff line number Diff line change @@ -95,4 +95,27 @@ public function testLocksCanBeReleasedUsingOwnerToken()
95
95
96
96
$ this ->assertTrue (Cache::lock ('foo ' )->get ());
97
97
}
98
+
99
+ public function testOwnerStatusCanBeCheckedAfterRestoringLock ()
100
+ {
101
+ Cache::lock ('foo ' )->forceRelease ();
102
+
103
+ $ firstLock = Cache::lock ('foo ' , 10 );
104
+ $ this ->assertTrue ($ firstLock ->get ());
105
+ $ owner = $ firstLock ->owner ();
106
+
107
+ $ secondLock = Cache::store ('file ' )->restoreLock ('foo ' , $ owner );
108
+ $ this ->assertTrue ($ secondLock ->isOwnedByCurrentProcess ());
109
+ }
110
+
111
+ public function testOtherOwnerDoesNotOwnLockAfterRestore ()
112
+ {
113
+ Cache::lock ('foo ' )->forceRelease ();
114
+
115
+ $ firstLock = Cache::lock ('foo ' , 10 );
116
+ $ this ->assertTrue ($ firstLock ->get ());
117
+
118
+ $ secondLock = Cache::store ('file ' )->restoreLock ('foo ' , 'other_owner ' );
119
+ $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
120
+ }
98
121
}
Original file line number Diff line number Diff line change @@ -80,4 +80,27 @@ public function testMemcachedLocksCanBeReleasedUsingOwnerToken()
80
80
81
81
$ this ->assertTrue (Cache::store ('memcached ' )->lock ('foo ' )->get ());
82
82
}
83
+
84
+ public function testOwnerStatusCanBeCheckedAfterRestoringLock ()
85
+ {
86
+ Cache::store ('memcached ' )->lock ('foo ' )->forceRelease ();
87
+
88
+ $ firstLock = Cache::store ('memcached ' )->lock ('foo ' , 10 );
89
+ $ this ->assertTrue ($ firstLock ->get ());
90
+ $ owner = $ firstLock ->owner ();
91
+
92
+ $ secondLock = Cache::store ('memcached ' )->restoreLock ('foo ' , $ owner );
93
+ $ this ->assertTrue ($ secondLock ->isOwnedByCurrentProcess ());
94
+ }
95
+
96
+ public function testOtherOwnerDoesNotOwnLockAfterRestore ()
97
+ {
98
+ Cache::store ('memcached ' )->lock ('foo ' )->forceRelease ();
99
+
100
+ $ firstLock = Cache::store ('memcached ' )->lock ('foo ' , 10 );
101
+ $ this ->assertTrue ($ firstLock ->get ());
102
+
103
+ $ secondLock = Cache::store ('memcached ' )->restoreLock ('foo ' , 'other_owner ' );
104
+ $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
105
+ }
83
106
}
Original file line number Diff line number Diff line change @@ -108,4 +108,27 @@ public function testRedisLocksCanBeReleasedUsingOwnerToken()
108
108
109
109
$ this ->assertTrue (Cache::store ('redis ' )->lock ('foo ' )->get ());
110
110
}
111
+
112
+ public function testOwnerStatusCanBeCheckedAfterRestoringLock ()
113
+ {
114
+ Cache::store ('redis ' )->lock ('foo ' )->forceRelease ();
115
+
116
+ $ firstLock = Cache::store ('redis ' )->lock ('foo ' , 10 );
117
+ $ this ->assertTrue ($ firstLock ->get ());
118
+ $ owner = $ firstLock ->owner ();
119
+
120
+ $ secondLock = Cache::store ('redis ' )->restoreLock ('foo ' , $ owner );
121
+ $ this ->assertTrue ($ secondLock ->isOwnedByCurrentProcess ());
122
+ }
123
+
124
+ public function testOtherOwnerDoesNotOwnLockAfterRestore ()
125
+ {
126
+ Cache::store ('redis ' )->lock ('foo ' )->forceRelease ();
127
+
128
+ $ firstLock = Cache::store ('redis ' )->lock ('foo ' , 10 );
129
+ $ this ->assertTrue ($ firstLock ->get ());
130
+
131
+ $ secondLock = Cache::store ('redis ' )->restoreLock ('foo ' , 'other_owner ' );
132
+ $ this ->assertFalse ($ secondLock ->isOwnedByCurrentProcess ());
133
+ }
111
134
}
You can’t perform that action at this time.
0 commit comments