From e86365ca0ffba680d5aefce6098baa35752b9681 Mon Sep 17 00:00:00 2001 From: AD7six Date: Thu, 22 Jan 2015 10:59:33 +0000 Subject: [PATCH] Add a failing test for session concurrency problems --- .../Session/DatabaseSessionTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php b/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php index b39a32516..440b52263 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php @@ -191,4 +191,34 @@ class DatabaseSessionTest extends CakeTestCase { $storage->gc(); $this->assertFalse($storage->read('foo')); } + +/** + * testConcurrentInsert + * + * @return void + */ + public function testConcurrentInsert() { + ClassRegistry::removeObject('Session'); + + $mockedModel = $this->getMockForModel( + 'SessionTestModel', + array('exists'), + array('alias' => 'MockedSessionTestModel', 'table' => 'sessions') + ); + Configure::write('Session.handler.model', 'MockedSessionTestModel'); + + $mockedModel->expects($this->any()) + ->method('exists') + ->will($this->returnValue(false)); + + $this->storage = new DatabaseSession(); + + $this->storage->write('foo', 'Some value'); + $return = $this->storage->read('foo'); + $this->assertSame('Some value', $return); + + $this->storage->write('foo', 'Some other value'); + $return = $this->storage->read('foo'); + $this->assertSame('Some other value', $return); + } }