sleep example


class SlidingWindowTest extends TestCase
{
    public function testGetExpirationTime()
    {
        $window = new SlidingWindow('foo', 10);
        $this->assertSame(2 * 10, $window->getExpirationTime());
        $this->assertSame(2 * 10, $window->getExpirationTime());

        $data = serialize($window);
        sleep(10);
        $cachedWindow = unserialize($data);
        $this->assertSame(10, $cachedWindow->getExpirationTime());

        $new = SlidingWindow::createFromPreviousWindow($cachedWindow, 15);
        $this->assertSame(2 * 15, $new->getExpirationTime());

        usleep(10.1);
        $this->assertIsInt($new->getExpirationTime());
    }

    public function testInvalidInterval()
    {
public function testShutdownFunctions() {
    $arg1 = $this->randomMachineName();
    $arg2 = $this->randomMachineName();
    $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);

    // If using PHP-FPM then fastcgi_finish_request() will have been fired     // returning the response before shutdown functions have fired.     // @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions()     $server_using_fastcgi = strpos($this->getSession()->getPage()->getContent(), 'The function fastcgi_finish_request exists when serving the request.');
    if ($server_using_fastcgi) {
      // We need to wait to ensure that the shutdown functions have fired.       sleep(1);
    }
    $this->assertEquals([$arg1$arg2], \Drupal::state()->get('_system_test_first_shutdown_function'));
    $this->assertEquals([$arg1$arg2], \Drupal::state()->get('_system_test_second_shutdown_function'));

    if (!$server_using_fastcgi) {
      // Make sure exceptions displayed through       // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly       // escaped.       $this->assertSession()->responseContains('Drupal is <blink>awesome</blink>.');
    }
  }

}
$ran = false;
            foreach ($this->generators as $generator) {
                foreach ($generator->getMessages() as $message) {
                    $this->handlers[$message::class]($message);
                    $ran = true;
                }
            }

            if (!$ran) {
                if (0 < $sleep = (int) ($options['sleep'] - 1e6 * ($this->clock->now()->format('U.u') - $start->format('U.u')))) {
                    $this->clock->sleep($sleep / 1e6);
                }
            }
        }
    }

    public function stop(): void
    {
        $this->shouldStop = true;
    }
}
public function locked(Smarty $smarty, Smarty_Template_Cached $cached)
    {
        // theoretically locking_timeout should be checked against time_limit (max_execution_time)         $start = microtime(true);
        $hadLock = null;
        while ($this->hasLock($smarty$cached)) {
            $hadLock = true;
            if (microtime(true) - $start > $smarty->locking_timeout) {
                // abort waiting for lock release                 return false;
            }
            sleep(1);
        }
        return $hadLock;
    }

    public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
    {
        // check if lock exists         return false;
    }

    public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
    {
private static $server;

    public static function setUpBeforeClass(): void
    {
        $spec = [
            1 => ['file', '/dev/null', 'w'],
            2 => ['file', '/dev/null', 'w'],
        ];
        if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8054', $spec$pipes, __DIR__.'/Fixtures/response-functional')) {
            throw new SkippedTestSuiteError('PHP server unable to start.');
        }
        sleep(1);
    }

    public static function tearDownAfterClass(): void
    {
        if (self::$server) {
            proc_terminate(self::$server);
            proc_close(self::$server);
        }
    }

    /** * @dataProvider provideCookie */
$cache->save($item->set($value));
        $item = $cache->getItem('bar');
        $setCacheItemExpiry($item, 0.0);
        $cache->save($item->set($value));
        $item = $cache->getItem('baz');
        $cache->save($item->set($value));

        $this->assertSame($value$this->cache->getItem('foo')->get());
        $this->assertSame($value$this->cache->getItem('bar')->get());
        $this->assertSame($value$this->cache->getItem('baz')->get());

        sleep(1);
        $this->assertSame($value$this->cache->getItem('foo')->get());
        $this->assertSame($value$this->cache->getItem('bar')->get());
        $this->assertFalse($this->cache->getItem('baz')->isHit());
    }
}
$this->assertSame(0444, fileperms($expected_filename) & 0777);
    $this->assertSame(0777, fileperms($expected_directory) & 0777);

    // Ensure the root directory for the bin has a .htaccess file denying web     // access.     $this->assertSame(file_get_contents($expected_root_directory . '/.htaccess'), FileSecurity::htaccessLines());

    // Ensure that if the file is replaced with an untrusted one (due to another     // script's file upload vulnerability), it does not get loaded. Since mtime     // granularity is 1 second, we cannot prevent an attack that happens within     // a second of the initial save().     sleep(1);
    for ($i = 0; $i < 2; $i++) {
      $php = new $this->storageClass($this->settings);
      $GLOBALS['hacked'] = FALSE;
      $untrusted_code = "<?php\n" . '$GLOBALS["hacked"] = TRUE;';
      chmod($expected_directory, 0700);
      chmod($expected_filename, 0700);
      if ($i) {
        // Now try to write the file in such a way that the directory mtime         // changes and invalidates the hash.         file_put_contents($expected_filename . '.tmp', $untrusted_code);
        rename($expected_filename . '.tmp', $expected_filename);
      }


    /** * @dataProvider getAcceptData */
    public function testAccept($mode$expected)
    {
        if (!\is_callable($mode)) {
            switch ($mode) {
                case SortableIterator::SORT_BY_ACCESSED_TIME:
                    touch(self::toAbsolute('.git'));
                    sleep(1);
                    touch(self::toAbsolute('.bar')time());
                    break;
                case SortableIterator::SORT_BY_CHANGED_TIME:
                    sleep(1);
                    file_put_contents(self::toAbsolute('test.php'), 'foo');
                    sleep(1);
                    file_put_contents(self::toAbsolute('test.py'), 'foo');
                    break;
                case SortableIterator::SORT_BY_MODIFIED_TIME:
                    file_put_contents(self::toAbsolute('test.php'), 'foo');
                    sleep(1);
                    


        ++$this->restartCounter;
        if ($this->restartCounter < $this->restartThreshold) {
            return;
        }

        $this->stop();
        if (0 < $sleep = $this->restartThresholdSleep) {
            $this->getLogger()->debug(sprintf('Email transport "%s" sleeps for %d seconds after stopping', __CLASS__, $sleep));

            sleep($sleep);
        }
        $this->start();
        $this->restartCounter = 0;
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    /** * @return void */
$this->assertGreaterThan($before(float) $now->format('U.u'));
        $this->assertLessThan($after(float) $now->format('U.u'));
    }

    public function testSleep()
    {
        $clock = new MonotonicClock();
        $tz = $clock->now()->getTimezone()->getName();

        $before = microtime(true);
        $clock->sleep(1.5);
        $now = (float) $clock->now()->format('U.u');
        usleep(10);
        $after = microtime(true);

        $this->assertGreaterThanOrEqual($before + 1.499999, $now);
        $this->assertLessThan($after$now);
        $this->assertLessThan(1.9, $now - $before);
        $this->assertSame($tz$clock->now()->getTimezone()->getName());
    }

    public function testWithTimeZone()
    {
$t2 = $this->createMock(TransportInterface::class);
        $t2->method('supports')->with($message)->willReturn(true);
        $t2->expects($this->exactly(3))
            ->method('send')
            ->willReturnOnConsecutiveCalls(
                new SentMessage($message, 't2'),
                new SentMessage($message, 't2'),
                $this->throwException($this->createMock(TransportExceptionInterface::class))
            );
        $t = new FailoverTransport([$t1$t2], 40);
        $t->send($message);
        sleep(4);
        $t->send($message);
        sleep(4);

        $this->expectException(RuntimeException::class);
        $this->expectExceptionMessage('All transports failed.');

        $t->send($message);
    }

    public function testSendOneDeadButRecover()
    {
        
    $this->drupalGet('system-test/lock-acquire');
    $this->assertSession()->pageTextContains($lock_acquired);
    // The other request has finished, thus it should have released its lock.     $this->assertTrue($lock->acquire('system_test_lock_acquire'), 'Lock acquired by this request.');
    // This request holds the lock, so the other request cannot acquire it.     $this->drupalGet('system-test/lock-acquire');
    $this->assertSession()->pageTextContains($lock_not_acquired);
    $lock->release('system_test_lock_acquire');

    // Try a very short timeout and lock breaking.     $this->assertTrue($lock->acquire('system_test_lock_acquire', 0.5), 'Lock acquired by this request.');
    sleep(1);
    // The other request should break our lock.     $this->drupalGet('system-test/lock-acquire');
    $this->assertSession()->pageTextContains($lock_acquired);
    // We cannot renew it, since the other thread took it.     $this->assertFalse($lock->acquire('system_test_lock_acquire'), 'Lock cannot be extended by this request.');

    // Check the shut-down function.     $lock_acquired_exit = 'TRUE: Lock successfully acquired in \Drupal\system_test\Controller\SystemTestController::lockExit()';
    $this->drupalGet('system-test/lock-exit');
    $this->assertSession()->pageTextContains($lock_acquired_exit);
    $this->assertTrue($lock->acquire('system_test_lock_exit'), 'Lock acquired by this request after the other request exits.');
  }
$this->assertEquals('contrib_module_two', $item->data[1][0], 'Queue holds tasks for contrib module one.');

    // Test: Run cron for a second time and check if tasks are not added to     // the queue twice.     locale_cron();

    // Check whether no more tasks are added to the queue.     $queue = \Drupal::queue('locale_translation', TRUE);
    $this->assertEquals(2, $queue->numberOfItems(), 'Queue holds tasks for one project.');

    // Ensure last checked is updated to a greater time than the initial value.     sleep(1);
    // Test: Execute cron and check if tasks are executed correctly.     // Run cron to process the tasks in the queue.     $this->cronRun();

    drupal_static_reset('locale_translation_get_file_history');
    $history = locale_translation_get_file_history();
    $initial = $initial_history['contrib_module_two']['de'];
    $current = $history['contrib_module_two']['de'];
    // Verify that the translation of contrib_module_one is imported and     // updated.     $this->assertGreaterThan($initial->timestamp, $current->timestamp);
    
if (is_resource($server)) {
      if ($io->isVerbose()) {
        // Write a blank line so that server output and the useful information are         // visually separated.         $io->writeln('');
      }
      $server_status = proc_get_status($server);
      while ($server_status['running']) {
        if ($io->isVerbose()) {
          fpassthru($pipes[2]);
        }
        sleep(1);
        $server_status = proc_get_status($server);
      }
    }
    return proc_close($server);
  }

  /** * Gets the site path. * * Defaults to 'sites/default'. For testing purposes this can be overridden * using the DRUPAL_DEV_SITE_PATH environment variable. * * @return string * The site path to use. */


    public function testMaxLifetime()
    {
        $cache = new ArrayAdapter(0, false, 1);

        $item = $cache->getItem('foo');
        $item->expiresAfter(2);
        $cache->save($item->set(123));

        $this->assertTrue($cache->hasItem('foo'));
        sleep(1);
        $this->assertFalse($cache->hasItem('foo'));
    }

    public function testMaxItems()
    {
        $cache = new ArrayAdapter(0, false, 0, 2);

        $cache->save($cache->getItem('foo'));
        $cache->save($cache->getItem('bar'));
        $cache->save($cache->getItem('buz'));

        
Home | Imprint | This part of the site doesn't use cookies.