-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from bugsnag/fix-crash-in-oom-bootstrapper
Fix possible crash in the OOM bootstrapper
- Loading branch information
Showing
7 changed files
with
134 additions
and
7 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
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
47 changes: 47 additions & 0 deletions
47
tests/phpt/oom_bootstrapper_should_not_crash_when_bugsnag_is_missing.phpt
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,47 @@ | ||
--TEST-- | ||
The OomBootstrapper should not crash when bugsnag is not in the DI container | ||
--FILE-- | ||
<?php | ||
|
||
use Bugsnag\BugsnagLaravel\OomBootstrapper; | ||
|
||
function app($alias = null) { | ||
echo "'app' was called!\n"; | ||
|
||
if ($alias === 'bugsnag') { | ||
return null; | ||
} | ||
|
||
if ($alias !== null) { | ||
throw new UnexpectedValueException("Unknown alias '{$alias}' given"); | ||
} | ||
|
||
throw new BadFunctionCallException("This fake 'app' should always be called with an alias"); | ||
} | ||
|
||
require __DIR__.'/../../src/OomBootstrapper.php'; | ||
|
||
(new OomBootstrapper())->bootstrap(); | ||
|
||
ini_set('memory_limit', '5M'); | ||
|
||
$i = 0; | ||
|
||
gc_disable(); | ||
|
||
while ($i++ < 12345678) { | ||
$a = new stdClass; | ||
$a->b = $a; | ||
} | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_MAJOR_VERSION < 7) { | ||
echo "SKIP - PHP 5 does not run OOM in this test"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d | ||
'app' was called! |
59 changes: 59 additions & 0 deletions
59
tests/phpt/oom_bootstrapper_should_not_crash_when_bugsnag_is_present.phpt
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,59 @@ | ||
--TEST-- | ||
The OomBootstrapper should not crash when bugsnag is in the DI container | ||
--FILE-- | ||
<?php | ||
|
||
use Bugsnag\BugsnagLaravel\OomBootstrapper; | ||
|
||
class FakeClient | ||
{ | ||
public function getMemoryLimitIncrease() | ||
{ | ||
echo "'getMemoryLimitIncrease' was called!\n"; | ||
|
||
return 12345; | ||
} | ||
} | ||
|
||
function app($alias = null) { | ||
echo "'app' was called!\n"; | ||
|
||
if ($alias === 'bugsnag') { | ||
return new FakeClient(); | ||
} | ||
|
||
if ($alias !== null) { | ||
throw new UnexpectedValueException("Unknown alias '{$alias}' given"); | ||
} | ||
|
||
throw new BadFunctionCallException("This fake 'app' should always be called with an alias"); | ||
} | ||
|
||
require __DIR__.'/../../src/OomBootstrapper.php'; | ||
|
||
(new OomBootstrapper())->bootstrap(); | ||
|
||
ini_set('memory_limit', '5M'); | ||
|
||
$i = 0; | ||
|
||
gc_disable(); | ||
|
||
while ($i++ < 12345678) { | ||
$a = new stdClass; | ||
$a->b = $a; | ||
} | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_MAJOR_VERSION < 7) { | ||
echo "SKIP - PHP 5 does not run OOM in this test"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d | ||
'app' was called! | ||
'getMemoryLimitIncrease' was called! | ||
'getMemoryLimitIncrease' was called! |