PhpiredisStreamConnectionTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Connection;
  11. /**
  12. * @group ext-phpiredis
  13. * @requires extension phpiredis
  14. */
  15. class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
  16. {
  17. const CONNECTION_CLASS = 'Predis\Connection\PhpiredisStreamConnection';
  18. // ******************************************************************** //
  19. // ---- INTEGRATION TESTS --------------------------------------------- //
  20. // ******************************************************************** //
  21. /**
  22. * @group connected
  23. * @group slow
  24. * @requires PHP 5.4
  25. * @expectedException \Predis\Connection\ConnectionException
  26. */
  27. public function testThrowsExceptionOnReadWriteTimeout()
  28. {
  29. $profile = $this->getCurrentProfile();
  30. $connection = $this->createConnectionWithParams(array(
  31. 'read_write_timeout' => 0.5,
  32. ), true);
  33. $connection->executeCommand($profile->createCommand('brpop', array('foo', 3)));
  34. }
  35. /**
  36. * @medium
  37. * @group connected
  38. * @expectedException \Predis\Protocol\ProtocolException
  39. */
  40. public function testThrowsExceptionOnProtocolDesynchronizationErrors()
  41. {
  42. $connection = $this->createConnection();
  43. $stream = $connection->getResource();
  44. $connection->writeRequest($this->getCurrentProfile()->createCommand('ping'));
  45. stream_socket_recvfrom($stream, 1);
  46. $connection->read();
  47. }
  48. /**
  49. * @group connected
  50. */
  51. public function testPersistentParameterWithFalseLikeValues()
  52. {
  53. if ($this->isHHVM()) {
  54. $this->markTestSkipped('This test does not currently work on HHVM.');
  55. }
  56. $connection1 = $this->createConnectionWithParams(array('persistent' => 0));
  57. $this->assertNonPersistentConnection($connection1);
  58. $connection2 = $this->createConnectionWithParams(array('persistent' => false));
  59. $this->assertNonPersistentConnection($connection2);
  60. $connection3 = $this->createConnectionWithParams(array('persistent' => '0'));
  61. $this->assertNonPersistentConnection($connection3);
  62. $connection4 = $this->createConnectionWithParams(array('persistent' => 'false'));
  63. $this->assertNonPersistentConnection($connection4);
  64. }
  65. /**
  66. * @group connected
  67. */
  68. public function testPersistentParameterWithTrueLikeValues()
  69. {
  70. if ($this->isHHVM()) {
  71. $this->markTestSkipped('This test does not currently work on HHVM.');
  72. }
  73. $connection1 = $this->createConnectionWithParams(array('persistent' => 1));
  74. $this->assertPersistentConnection($connection1);
  75. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  76. $this->assertPersistentConnection($connection2);
  77. $connection3 = $this->createConnectionWithParams(array('persistent' => '1'));
  78. $this->assertPersistentConnection($connection3);
  79. $connection4 = $this->createConnectionWithParams(array('persistent' => 'true'));
  80. $this->assertPersistentConnection($connection4);
  81. $connection1->disconnect();
  82. }
  83. /**
  84. * @group connected
  85. */
  86. public function testPersistentConnectionsToSameNodeShareResource()
  87. {
  88. if ($this->isHHVM()) {
  89. $this->markTestSkipped('This test does not currently work on HHVM.');
  90. }
  91. $connection1 = $this->createConnectionWithParams(array('persistent' => true));
  92. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  93. $this->assertPersistentConnection($connection1);
  94. $this->assertPersistentConnection($connection2);
  95. $this->assertSame($connection1->getResource(), $connection2->getResource());
  96. $connection1->disconnect();
  97. }
  98. /**
  99. * @group connected
  100. */
  101. public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
  102. {
  103. if ($this->isHHVM()) {
  104. $this->markTestSkipped('This test does not currently work on HHVM.');
  105. }
  106. $connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
  107. $connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));
  108. $this->assertPersistentConnection($connection1);
  109. $this->assertPersistentConnection($connection2);
  110. $this->assertNotSame($connection1->getResource(), $connection2->getResource());
  111. }
  112. }