summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/session.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-15 04:15:41 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-15 04:15:41 +0000
commit4a9cd0fcc1374a852044bb5cc8893f978862bf67 (patch)
treed066f39a2331b91fc4e42ac0c790285a0d68289f /modules/simpletest/tests/session.test
parent5ab7658c0d49c6b88a0e09eb64e2caa53200d320 (diff)
downloadbrdo-4a9cd0fcc1374a852044bb5cc8893f978862bf67.tar.gz
brdo-4a9cd0fcc1374a852044bb5cc8893f978862bf67.tar.bz2
#744384 by c960657: Do not write unchanged sessions to the database.
Diffstat (limited to 'modules/simpletest/tests/session.test')
-rw-r--r--modules/simpletest/tests/session.test42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test
index 8eef2b985..88931a8eb 100644
--- a/modules/simpletest/tests/session.test
+++ b/modules/simpletest/tests/session.test
@@ -181,6 +181,48 @@ class SessionTestCase extends DrupalWebTestCase {
}
/**
+ * Test that sessions are only saved when necessary.
+ */
+ function testSessionWrite() {
+ $user = $this->drupalCreateUser(array('access content'));
+ $this->drupalLogin($user);
+
+ $sql = 'SELECT u.access, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.uid = :uid';
+ $times1 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
+
+ // Before every request we sleep one second to make sure that if the session
+ // is saved, its timestamp will change.
+
+ // Modify the session.
+ sleep(1);
+ $this->drupalGet('session-test/set/foo');
+ $times2 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
+ $this->assertEqual($times2->access, $times1->access, t('Users table was not updated.'));
+ $this->assertNotEqual($times2->timestamp, $times1->timestamp, t('Sessions table was updated.'));
+
+ // Write the same value again, i.e. do not modify the session.
+ sleep(1);
+ $this->drupalGet('session-test/set/foo');
+ $times3 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
+ $this->assertEqual($times3->access, $times1->access, t('Users table was not updated.'));
+ $this->assertEqual($times3->timestamp, $times2->timestamp, t('Sessions table was not updated.'));
+
+ // Do not change the session.
+ sleep(1);
+ $this->drupalGet('');
+ $times4 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
+ $this->assertEqual($times4->access, $times3->access, t('Users table was not updated.'));
+ $this->assertEqual($times4->timestamp, $times3->timestamp, t('Sessions table was not updated.'));
+
+ // Force updating of users and sessions table once per second.
+ variable_set('session_write_interval', 0);
+ $this->drupalGet('');
+ $times5 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
+ $this->assertNotEqual($times5->access, $times4->access, t('Users table was updated.'));
+ $this->assertNotEqual($times5->timestamp, $times4->timestamp, t('Sessions table was updated.'));
+ }
+
+ /**
* Reset the cookie file so that it refers to the specified user.
*
* @param $uid User id to set as the active session.