PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Pheanstalk/BugfixConnectionTest.php

http://github.com/pda/pheanstalk
PHP | 77 lines | 44 code | 9 blank | 24 comment | 4 complexity | 532f1fdea64e6ecd2a3a0cfce090b68a MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. namespace Pheanstalk;
  3. use PHPUnit\Framework\TestCase;
  4. /**
  5. * Tests for reported/discovered issues & bugs which don't fall into
  6. * an existing category of tests.
  7. * Relies on a running beanstalkd server.
  8. *
  9. */
  10. class BugfixConnectionTest extends TestCase
  11. {
  12. /**
  13. * Issue: NativeSocket's read() doesn't work with jobs larger than 8192 bytes.
  14. *
  15. * @see http://github.com/pda/pheanstalk/issues/4
  16. *
  17. * PHP 5.2.10-2ubuntu6.4 reads nearly double that on the first fread().
  18. * This is probably due to a prior call to fgets() pre-filling the read buffer.
  19. */
  20. public function testIssue4ReadingOver8192Bytes()
  21. {
  22. $length = 8192 * 3;
  23. $pheanstalk = $this->createPheanstalk();
  24. $pheanstalk->put(str_repeat('.', $length));
  25. $job = $pheanstalk->peekReady();
  26. $this->assertEquals(strlen($job->getData()), $length, 'data length: %s');
  27. }
  28. /**
  29. * Issue: NativeSocket's read() cannot read all the bytes we want at once.
  30. *
  31. * @see http://github.com/pda/pheanstalk/issues/issue/16
  32. *
  33. * @author SlNPacifist
  34. */
  35. public function testIssue4ReadingDifferentNumberOfBytes()
  36. {
  37. $pheanstalk = $this->createPheanstalk();
  38. $maxLength = 10000;
  39. $delta = str_repeat('a', 1000);
  40. // Let's repeat 20 times to make problem more obvious on Linux OS (it happens randomly)
  41. for ($i = 0; $i < 16; $i++) {
  42. for ($message = $delta; strlen($message) < $maxLength; $message .= $delta) {
  43. $pheanstalk->put($message);
  44. $job = $pheanstalk->peekReady();
  45. $pheanstalk->delete($job);
  46. $this->assertEquals($job->getData(), $message);
  47. }
  48. }
  49. }
  50. // ----------------------------------------
  51. // private
  52. private function createPheanstalk()
  53. {
  54. $pheanstalk = Pheanstalk::create(SERVER_HOST);
  55. $tube = preg_replace('#[^a-z]#', '', strtolower(__CLASS__));
  56. $pheanstalk
  57. ->useTube($tube)
  58. ->watch($tube)
  59. ->ignore('default');
  60. while (null !== $job = $pheanstalk->peekDelayed()) {
  61. $pheanstalk->delete($job);
  62. }
  63. while (null !== $job = $pheanstalk->peekReady()) {
  64. $pheanstalk->delete($job);
  65. }
  66. return $pheanstalk;
  67. }
  68. }