-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tests randomly fails time to time trying to increase the the sleep time
- Loading branch information
Showing
10 changed files
with
72 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: php | ||
|
||
sudo: false | ||
sudo: required | ||
|
||
cache: | ||
directories: | ||
|
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,40 @@ | ||
<?php | ||
|
||
namespace Http\Client\Socket\Tests; | ||
|
||
/** | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
final class Semaphore | ||
{ | ||
private static $openConnections = 0; | ||
|
||
/** | ||
* Busy waiting for my turn to go. | ||
* | ||
* @return bool | ||
*/ | ||
public static function acquire() | ||
{ | ||
$tries = 1; | ||
while (self::$openConnections > 0) { | ||
sleep($tries++); | ||
if ($tries > 5) { | ||
return false; | ||
} | ||
} | ||
self::$openConnections++; | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Signal that you are done. | ||
*/ | ||
public static function release() | ||
{ | ||
// Do no be too quick | ||
usleep(500000); | ||
self::$openConnections--; | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
2D | ||
2F |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<?php | ||
|
||
require_once __DIR__."/../Semaphore.php"; | ||
|
||
$socketServer = stream_socket_server('127.0.0.1:19999'); | ||
$client = stream_socket_accept($socketServer); | ||
|
||
fclose($client); | ||
\Http\Client\Socket\Tests\Semaphore::release(); |
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
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