Source

pecl-ev / tests / 05_timer.phpt

Full commit
Ruslan Osmanov 1d04e11 



Ruslan Osmanov dae692a 
Ruslan Osmanov 1d04e11 



Ruslan Osmanov ba91e77 

Ruslan Osmanov 1d04e11 
Ruslan Osmanov dae692a 


Ruslan Osmanov 1d04e11 



Ruslan Osmanov dae692a 
Ruslan Osmanov 4a67c01 
Ruslan Osmanov ba91e77 
Ruslan Osmanov 1d04e11 
Ruslan Osmanov ba91e77 
Ruslan Osmanov 1d04e11 














Ruslan Osmanov dae692a 

Ruslan Osmanov 1d04e11 



Ruslan Osmanov dae692a 
Ruslan Osmanov 4a67c01 
Ruslan Osmanov ba91e77 
Ruslan Osmanov 1d04e11 
Ruslan Osmanov ba91e77 
Ruslan Osmanov 1d04e11 













Ruslan Osmanov dae692a 

Ruslan Osmanov 1d04e11 


Ruslan Osmanov ba91e77 
Ruslan Osmanov 1d04e11 
Ruslan Osmanov dae692a 


Ruslan Osmanov 1d04e11 
































--TEST--
Check for EvTimer functionality
--FILE--
<?php 
//error_reporting(0);

$fudge = 0.02;
$id = 1;

$base = Ev::now();
$prev = Ev::now();

$timer = array();
$periodic = array();

for ($i = 1; $i <= 5; ++$i) {
	$t = $i * $i * 1.735435336;
	$t -= (int) $t;

	$tmp_timer = new EvTimer($t, 0, function ($w, $r)
		use (&$id, &$prev, $base, $i, $t, $fudge) {
			$now = Ev::now();

			Ev::verify();

			echo $now + $fudge >= $prev ? "" : "not ", "ok ", ++$id,
				" # t0 $i $now + $fudge >= $prev\n";
			echo $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id,
				" # t1 $now + $fudge >= $base + $t\n";

			if (! ($id % 3)) {
				$t *= 0.0625;
				$w->set($t, 0);
				$w->start();
				$t = $now + $t - $base;
			}

			$prev = $now;
		});
	$tmp_timer->start();
	$timer[] = $tmp_timer;

	$t = $i * $i * 1.375475771;
	$t -= (int) $t;

	$tmp_periodic = new EvPeriodic($base + $t, 0, NULL, function ($w, $r)
		use (&$id, &$prev, $base, $i, $t) {
			$now = Ev::now();

			Ev::verify();

			echo $now >= $prev ? "" : "not ", "ok ", ++$id,
				" # p0 $i $now >= $prev\n";
			echo $now >= $base + $t ? "" : "not ", "ok ", ++$id,
				" # p1 $i $now >= $base + $t\n";

			if (! ($id % 3)) {
   				$t *= 1.0625;
         		$w->set($base + $t, 0);
         		$w->start();
			}

			$prev = $now;
		});
	$tmp_periodic->start();
	$periodic[] = $tmp_periodic;
}

echo "ok 1\n";
Ev::run();
echo "ok 32\n";

$timer = null;
$periodic = null;
?>
--EXPECTF--
ok 1
ok 2 %s
ok 3 %s
ok 4 %s
ok 5 %s
ok 6 %s
ok 7 %s
ok 8 %s
ok 9 %s
ok 10 %s
ok 11 %s
ok 12 %s
ok 13 %s
ok 14 %s
ok 15 %s
ok 16 %s
ok 17 %s
ok 18 %s
ok 19 %s
ok 20 %s
ok 21 %s
ok 22 %s
ok 23 %s
ok 24 %s
ok 25 %s
ok 26 %s
ok 27 %s
ok 28 %s
ok 29 %s
ok 30 %s
ok 31 %s
ok 32