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

    $this->insertSession();
    $this->insertSession();
...
  private function insertSession(array $fields = array()) {
    $fields += array(
      'uid' => 0,
      'sid' => md5(microtime()),
      'timestamp' => REQUEST_TIME,
    );
CommentFileSizeAuthor
#11 503496_uniqid.patch591 bytesdeekayen
#7 503496-sid.patch697 bytesboombatower

Comments

andypost’s picture

I cant understand a logic of test.

  $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'),
andypost’s picture

Title: Test seems broken » Logic inside UserBlocksUnitTests->testWhosOnlineBlock() out of DB-constraints

More descriptive title

modules\user\user.test testWhosOnlineBlock()

damien tournoud’s picture

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.

andypost’s picture

Stable error when using php-apc - on debian 5 (apache2 php 5.2.6)

deekayen’s picture

I got the error on Ubuntu 8.04 Hardy with eaccelerator 0.9.5.3 and PHP 5.2.4 Suhosin.

andypost’s picture

Suppose using md5(microtime()) is not a good random generator mainly.

boombatower’s picture

Title: Logic inside UserBlocksUnitTests->testWhosOnlineBlock() out of DB-constraints » Need better sid generation in UserBlocksUnitTests->testWhosOnlineBlock()
Component: mysql database » user system
Assigned: Unassigned » boombatower
Status: Active » Needs review
Issue tags: +PIFR 2.x blocker
StatusFileSize
new697 bytes

Test still passes locally and would seem to solve problem.

dave reid’s picture

Title: Need better sid generation in UserBlocksUnitTests->testWhosOnlineBlock() » Logic inside UserBlocksUnitTests->testWhosOnlineBlock() out of DB-constraints
Component: user system » mysql database
Assigned: boombatower » Unassigned
Status: Needs review » Active
Issue tags: -PIFR 2.x blocker

I think this was my test. :) Let's change it to md5(mt_rand()) and see if that fixes it.

boombatower’s picture

Title: Logic inside UserBlocksUnitTests->testWhosOnlineBlock() out of DB-constraints » Need better sid generation in UserBlocksUnitTests->testWhosOnlineBlock()
Component: mysql database » user system
Assigned: Unassigned » boombatower
Status: Active » Needs review
Issue tags: +PIFR 2.x blocker

Fix cross-post.

andypost’s picture

Looks good for me. Need some reviews except mine...

deekayen’s picture

StatusFileSize
new591 bytes

How about using the PHP function actually intended for unique IDs: md5(uniqid(mt_rand(), true))

boombatower’s picture

Status: Needs review » Reviewed & tested by the community

Looks great. Lets not hold up PIFR any longer, eh?

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -PIFR 2.x blocker

Automatically closed -- issue fixed for 2 weeks with no activity.