Problem/Motivation

2 tesst fails on PHP 8.1rc4 because usleep() expects integer argument but microtime(TRUE) returns float

- core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageTest.php
- core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php

See https://3v4l.org/TTo7O

Steps to reproduce

Ref to CI
and

$ php -r '$t=microtime(TRUE)+0.5;usleep(($t - microtime(TRUE)) * 1000000);'
PHP Deprecated:  Implicit conversion from float 499994.99320983887 to int loses precision in Command line code on line 1

Deprecated: Implicit conversion from float 499994.99320983887 to int loses precision in Command line code on line 1

Proposed resolution

fix code

Remaining tasks

review, commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

no

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
Issue tags: +PHP 8.1
StatusFileSize
new874 bytes
andypost’s picture

https://3v4l.org/OQ2va only one deprecation now

andypost’s picture

Title: core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageTest.php triggers deprecations on PHP 8.1 » usleep() usage triggers deprecations on PHP 8.1
Issue summary: View changes
StatusFileSize
new741 bytes
new1.58 KB

found one more hunk to fix by checking usage of usleep() in core

re-title and updated IS

andypost’s picture

StatusFileSize
new1.59 KB
new1.58 KB

Fix CS

daffie’s picture

StatusFileSize
new1.58 KB

I think that the reason that the testbot is failing for PHP 8.1-rc4 is that we should first multiply with a million and after that do the casting to an integer value. The required precision gets lost if you do it in the reverse order.

alexpott’s picture

Segfault! Wow nice.

andypost’s picture

I can't reproduce it locally, guess it needs specific conditions or set of libs

daffie’s picture

Maybe a bug in PHP 8.1?

alexpott’s picture

@daffie it might be a bug in RC4 that's been fixed - I only have the latest dev version.

andypost’s picture

How to find which docker image is used in CI to run it locally? I'm using custom Alpinelinux docker image based on https://pkgs.alpinelinux.org/packages?name=php81-*&branch=edge&arch=x86_64 and can't reproduce it locally(

daffie’s picture

I have DDEV with PHP 8.1 rc-2 and I can confirm that I get the "Segmentation fault" error on my local machine.
Without the patch applied I get the same "Segmentation fault" error on my local machine.

To me, it looks like the error is fixed in PHP 8.1-dev.

andypost’s picture

@daffie how you able to reproduce? just running test?

/var/www/html/web $ php --ri pdo_sqlite

pdo_sqlite

PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.36.0
/var/www/html/web $ php -v
PHP 8.1.0RC4 (cli) (built: Oct 13 2021 14:06:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0RC4, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0RC4, Copyright (c), by Zend Technologies
daffie’s picture

@daffie how you able to reproduce? just running test?

Yes, just running a single test. Sometimes it will pass and sometimes it will fail.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

I think segfault needs infra issue but the patch is good to go

Added I'm using this script to test

seq 64 | parallel -j 8 "echo job {#} of {= '$_=total_jobs()' =} && php81 vendor/bin/phpunit -c core/phpunit.xml.dist core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageTest.php"

  • catch committed 54147fd on 9.3.x
    Issue #3244533 by andypost, daffie: usleep() usage triggers deprecations...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 54147fd and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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