有一个带有测试套件的Laravel应用程序,可以在大约3分钟内完全运行。
大约2分钟左右,测试冻结约60094ms。每次它都是不同的测试,因此它似乎与任何特定的测试都不相关。
所有测试都没有失败,只是经历了奇怪的延迟。 是什么原因导致PhpUnit延迟60秒?
You should really fix these slow tests (>200ms)...
1. 60094ms to run Tests\Feature\Superadmin\BusinessActivityTest:testDestroyBusinessActivityProductionProcess
2. 3357ms to run Tests\Feature\AccessTokenTest:testOauthToken
3. 1124ms to run Tests\Feature\Superadmin\ArticleTest:testUpdateArticleForAdmin
4. 969ms to run Tests\Feature\VtaDocumentTest:testUploadVehiclesFileHappyPathWithFilePDF
5. 737ms to run Tests\Feature\VtaDocumentTest:testUploadCertificateFilePDF
...and there are 22 more above your threshold hidden from view
Time: 2.46 minutes, Memory: 144.25MB
答案 0 :(得分:0)
关闭Internet可以避免此问题。
在Print PHP Call Stack的帮助下调试并获取卡住进程的堆栈痕迹后,发现线程被卡在MixPanel代码中。
[New LWP 2893]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f04c2136bf9 in poll () from /lib/x86_64-linux-gnu/libc.so.6
{main}@/usr/local/bin/phpunit:0
main@/usr/local/bin/phpunit:594
run@phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:159
doRun@phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:203
run@phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:587
run@phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php:750
run@phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php:750
run@phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php:750
run@phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:798
runBare@phar:///usr/local/bin/phpunit/phpunit/Framework/TestResult.php:665
tearDown@phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:887
flush@/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:142
flush@/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1152
__destruct@/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1174
flush@/app/vendor/mixpanel/mixpanel-php/lib/Producers/MixpanelBaseProducer.php:96
_persist@/app/vendor/mixpanel/mixpanel-php/lib/Producers/MixpanelBaseProducer.php:117
persist@/app/vendor/mixpanel/mixpanel-php/lib/Producers/MixpanelBaseProducer.php:217
_write@/app/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php:122
fwrite@/app/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php:210
此外,在MixPanel中创建新用户的事件导致事件被发送。
现在测试已与MixPanel正确分离,不再有突然的延迟。