-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: process event support add: process timeout support add: mutex example fix: readme fix: lock bugs
- Loading branch information
Showing
4 changed files
with
427 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
include '../src/MProcess.php'; | ||
include '../src/QueueTable.php'; | ||
$retry = 100; | ||
while ($retry--) { | ||
$steps = rand(1, 9) * (10 ** rand(1, 3)); | ||
$zoom = rand(3, 9); | ||
$process = new ZV\MProcess(10, $steps, 64); | ||
$process['test'] = $steps; | ||
$process->on_init(function () use ($process, $steps) { | ||
for ($i = 0; $i < $steps; $i++) { | ||
$process->push(9999); | ||
} | ||
})->do(function ($index, $count) use ($zoom, $process, $steps) { | ||
if ($index == 0) { | ||
for ($i = 0; $i < $steps * ($zoom - 1); $i++) { | ||
$process->push(999); | ||
} | ||
} | ||
while (true) { | ||
// test for pop/shift | ||
$task = rand(0, 1) ? $process->shift() : $process->pop(); | ||
// | ||
$task > 0 && $process->incr('result'); | ||
if ($task === null) { | ||
break; | ||
} | ||
} | ||
})->wait(); | ||
|
||
|
||
echo '======TestRound(' . $retry . ')======', PHP_EOL; | ||
|
||
if ($process->atomic('result') != $steps * $zoom) { | ||
echo 'Failed=', $process->atomic('result'), PHP_EOL; | ||
} else { | ||
echo 'Succed=', $process->atomic('result'), PHP_EOL; | ||
} | ||
if ($process['test'] != $steps) { | ||
echo 'KeyFailed', PHP_EOL; | ||
} else { | ||
echo 'KeySucced', PHP_EOL; | ||
} | ||
echo PHP_EOL; | ||
} |
Oops, something went wrong.