File: BugfixConnectionTests.php

package info (click to toggle)
php-pda-pheanstalk 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 836 kB
  • sloc: php: 4,604; xml: 19; makefile: 14
file content (59 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

declare(strict_types=1);

namespace Pheanstalk\Tests\Integration;

use PHPUnit\Framework\Assert;

/**
 * Tests for reported/discovered issues & bugs which don't fall into
 * an existing category of tests.
 * Relies on a running beanstalkd server.
 *
 * @coversNothing
 */
trait BugfixConnectionTests
{
    /**
     * Issue: NativeSocket's read() doesn't work with jobs larger than 8192 bytes.
     *
     * @see http://github.com/pda/pheanstalk/issues/4
     *
     * PHP 5.2.10-2ubuntu6.4 reads nearly double that on the first fread().
     * This is probably due to a prior call to fgets() pre-filling the read buffer.
     */
    public function testIssue4ReadingOver8192Bytes(): void
    {
        $length = 8192 * 3;

        $pheanstalk = $this->getPheanstalk();
        $data = str_repeat('.', $length);
        $jobId = $pheanstalk->put($data);
        $job = $pheanstalk->peek($jobId);
        Assert::assertSame($data, $job->getData());
    }

    /**
     * Issue: NativeSocket's read() cannot read all the bytes we want at once.
     *
     * @see http://github.com/pda/pheanstalk/issues/issue/16
     *
     * @author SlNPacifist
     */
    public function testIssue4ReadingDifferentNumberOfBytes(): void
    {
        $pheanstalk = $this->getPheanstalk();
        $maxLength = 10000;
        $delta = str_repeat('a', 1000);
        // Let's repeat 20 times to make problem more obvious on Linux OS (it happens randomly)
        for ($i = 0; $i < 16; $i++) {
            for ($message = $delta; strlen($message) < $maxLength; $message .= $delta) {
                $jobId = $pheanstalk->put($message);
                $job = $pheanstalk->peek($jobId);
                $pheanstalk->delete($job);
                Assert::assertEquals($job->getData(), $message);
            }
        }
    }
}