Need better sid generation in UserBlocksUnitTests->testWhosOnlineBlock()
andypost - June 26, 2009 - 21:48
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | user system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | boombatower |
| Status: | closed |
| Issue tags: | PIFR 2.x blocker |
Description
sid is primary key so mostly md5(microtime()) is the same and second insert failed with
'UserBlocksUnitTests', 'exception',
'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ''3886465a51d1dfce61c06aa04f332ecd'' for key 1',
'Uncaught exception', 'PDOStatement->execute()', 1691,
'/home/drupaltesting/web/public/sites/drupaltesting.deekayen.net/files/checkout/includes/database/database.inc'This happens in modules\user\user.test
<?php
$this->insertSession();
$this->insertSession();
...
private function insertSession(array $fields = array()) {
$fields += array(
'uid' => 0,
'sid' => md5(microtime()),
'timestamp' => REQUEST_TIME,
);
?>
#1
I cant understand a logic of test.
<?php$schema['sessions'] = array(
...
'sid' => array(
'description' => "Primary key: A session ID. The value is generated by PHP's Session API.",
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
...
'primary key' => array('sid'),
?>
#2
More descriptive title
modules\user\user.test
testWhosOnlineBlock()#3
On which OS / hardware are you running this test?
I agree that inserting rows into the database is really not a good method for testing the who's online block... it will fail for non DB session.inc, and session.inc is supposed to remain pluggable.
#4
Stable error when using php-apc - on debian 5 (apache2 php 5.2.6)
#5
I got the error on Ubuntu 8.04 Hardy with eaccelerator 0.9.5.3 and PHP 5.2.4 Suhosin.
#6
Suppose using md5(microtime()) is not a good random generator mainly.
#7
Test still passes locally and would seem to solve problem.
#8
I think this was my test. :) Let's change it to md5(mt_rand()) and see if that fixes it.
#9
Fix cross-post.
#10
Looks good for me. Need some reviews except mine...
#11
How about using the PHP function actually intended for unique IDs:
md5(uniqid(mt_rand(), true))#12
Looks great. Lets not hold up PIFR any longer, eh?
#13
Committed to CVS HEAD. Thanks!
#14
Automatically closed -- issue fixed for 2 weeks with no activity.