ReadySchedulerTest.php 975 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace EasySwoole\Component\Tests;
  3. use EasySwoole\Component\ReadyScheduler;
  4. use PHPUnit\Framework\TestCase;
  5. use Swoole\Coroutine;
  6. class ReadySchedulerTest extends TestCase
  7. {
  8. function testNormal()
  9. {
  10. ReadyScheduler::getInstance()->addItem('worker');
  11. ReadyScheduler::getInstance()->addItem('rpc');
  12. ReadyScheduler::getInstance()->addItem('fastCache');
  13. go(function (){
  14. Coroutine::sleep(1);
  15. ReadyScheduler::getInstance()->ready('worker');
  16. ReadyScheduler::getInstance()->ready('rpc');
  17. });
  18. $this->assertEquals(false,ReadyScheduler::getInstance()->waitReady(['rpc','worker'],0.1));
  19. $this->assertEquals(true,ReadyScheduler::getInstance()->waitReady('rpc'));
  20. $this->assertEquals(true,ReadyScheduler::getInstance()->waitReady(['rpc','worker']));
  21. $this->assertEquals(false,ReadyScheduler::getInstance()->waitReady(['rpc','worker','fastCache'],1.1));
  22. }
  23. }