Skip to content
Snippets Groups Projects
Commit fb24b240 authored by catch's avatar catch
Browse files

Issue #3513618 by mstrelan, mondrake: [random test failure] ConnectionUnitTest::testOpenQueryClose

parent c0490079
Branches
Tags
3 merge requests!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #472788 passed with warnings
Pipeline: drupal

#472819

    Pipeline: drupal

    #472815

      Pipeline: drupal

      #472810

        +4
        ......@@ -95,7 +95,39 @@ protected function assertConnection(int $id): void {
        * @internal
        */
        protected function assertNoConnection(int $id): void {
        $this->assertArrayNotHasKey($id, $this->monitor->query($this->getQuery()['processlist'])->fetchAllKeyed(0, 0));
        // Wait up to 100ms to give the database engine sufficient time to react.
        $this->assertTrue($this->waitFor(0.1, function () use ($id) {
        $key = $this->monitor->query($this->getQuery()['processlist'])->fetchAllKeyed(0, 0);
        return !array_key_exists($id, $key);
        }));
        }
        /**
        * Wait for a callback to return a truthy value.
        *
        * @param int|float $timeout
        * Number of seconds to wait for.
        * @param callable $callback
        * The callback to call.
        *
        * @return mixed
        * The result of the callback.
        */
        protected function waitFor(int|float $timeout, callable $callback): mixed {
        $start = microtime(TRUE);
        $end = $start + $timeout;
        do {
        $result = call_user_func($callback, $this);
        if ($result) {
        break;
        }
        usleep(10000);
        } while (microtime(TRUE) < $end);
        return $result;
        }
        /**
        ......@@ -106,8 +138,6 @@ protected function assertNoConnection(int $id): void {
        public function testOpenClose(): void {
        // Close the connection.
        Database::closeConnection(static::TEST_TARGET_CONNECTION);
        // Wait 20ms to give the database engine sufficient time to react.
        usleep(20000);
        // Verify that we are back to the original connection count.
        $this->assertNoConnection($this->id);
        ......@@ -122,8 +152,6 @@ public function testOpenQueryClose(): void {
        // Close the connection.
        Database::closeConnection(static::TEST_TARGET_CONNECTION);
        // Wait 20ms to give the database engine sufficient time to react.
        usleep(20000);
        // Verify that we are back to the original connection count.
        $this->assertNoConnection($this->id);
        ......@@ -138,8 +166,6 @@ public function testOpenQueryPrefetchClose(): void {
        // Close the connection.
        Database::closeConnection(static::TEST_TARGET_CONNECTION);
        // Wait 20ms to give the database engine sufficient time to react.
        usleep(20000);
        // Verify that we are back to the original connection count.
        $this->assertNoConnection($this->id);
        ......@@ -171,8 +197,6 @@ public function testOpenSelectQueryClose(): void {
        // Close the connection.
        Database::closeConnection(static::TEST_TARGET_CONNECTION);
        // Wait 20ms to give the database engine sufficient time to react.
        usleep(20000);
        // Verify that we are back to the original connection count.
        $this->assertNoConnection($this->id);
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment