flyingL123
5 months ago
114
1
Testing

PHPUnit - Allowed memory size of 134217728 bytes exhausted

Posted 5 months ago by flyingL123

I'm seeing a strange error with a single PHPUnit test that I have written. I have a test suite of 346 tests. When I run all the tests with vendor/bin/phpunit everything works fine. All the tests use 68.00 MB of memeory. One of the test classes in the suite is tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php. This class has one test in it. When I run that test by itself it also works fine:

vendor/bin/phpunit tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php

Now, here's an excerpt from the test in that class:

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 1;
});

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 2;
});

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 3;
});

Again, this works fine. Now, the only change I make is going to the last assertion and changing it from assertPushedOn to assertNotPushedOn, like this:

Queue::assertNotPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 3;
});

When I do this, and run the test again, I get an error about memory size:

vendor/bin/phpunit tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /root/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php on line 0

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /root/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122

Why does this simple method change suddenly cause a memory issue? Does anyone have any idea?

Please sign in or create an account to participate in this conversation.