@@ -215,13 +215,28 @@ public function testRegenerateSessionIdWriteWithoutClose(): void
215215 $ oldData = '__ci_last_regenerate|i:1664607454;role|s:5:"guest"; ' ;
216216 $ this ->assertTrue ($ handler ->write ($ oldSessionId , $ oldData ));
217217
218- // During PHP session_regenerate_id(), write() is called with the new ID
219- // while the lock for the old session ID is still held.
218+ $ memcached = $ this ->getPrivateProperty ($ handler , 'memcached ' );
219+ $ this ->assertInstanceOf (Memcached::class, $ memcached );
220+
221+ $ prefix = 'ci_session: ' . $ this ->sessionName . ': ' ;
222+ $ memcached ->get ($ prefix . $ oldSessionId . ':lock ' );
223+ $ this ->assertSame (Memcached::RES_SUCCESS , $ memcached ->getResultCode ());
224+
225+ // Exercise write() with a different session ID without closing the handler.
220226 $ newData = '__ci_last_regenerate|i:1664607500;role|s:5:"admin"; ' ;
221227 $ this ->assertTrue ($ handler ->write ($ newSessionId , $ newData ));
228+
229+ $ this ->assertFalse ($ memcached ->get ($ prefix . $ oldSessionId . ':lock ' ));
230+ $ this ->assertSame (Memcached::RES_NOTFOUND , $ memcached ->getResultCode ());
231+
232+ $ memcached ->get ($ prefix . $ newSessionId . ':lock ' );
233+ $ this ->assertSame (Memcached::RES_SUCCESS , $ memcached ->getResultCode ());
234+
222235 $ this ->assertTrue ($ handler ->close ());
236+ $ this ->assertFalse ($ memcached ->get ($ prefix . $ newSessionId . ':lock ' ));
237+ $ this ->assertSame (Memcached::RES_NOTFOUND , $ memcached ->getResultCode ());
223238
224- // Verify the old lock was released and the new session data is readable
239+ // Verify that both session IDs retain their respective data.
225240 $ handler2 = $ this ->getInstance ();
226241 $ this ->assertTrue ($ handler2 ->open ($ this ->sessionSavePath , $ this ->sessionName ));
227242 $ this ->assertSame ($ oldData , $ handler2 ->read ($ oldSessionId ));
0 commit comments