Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve flaky tests (WIP) #150

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chris53897
Copy link

No description provided.

Copy link
Owner

@bzikarsky bzikarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I left a few comments.

Furthermore, please separate the unrelated changes into separate commits. I see at least 3 separate changes:

  1. Fix dev extension requriements
  2. Modernize PHPunit API usage (this could be multiple commits or one. If it's one, please list the applied changes in the commit message)
  3. Increase robustness of socket-based tests

$readData = $this->socketClient->read($numBytes);

self::assertEquals($testData, $readData);
}

public function testReadContents(): void
{
$testData = str_repeat("0123456789", mt_rand(1, 10));
$testData = str_repeat("0123456789", random_int(1, 10));
#$testData = str_repeat("0123456789", 10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do after tests are stable.

stream_copy_to_stream($connection, $connection, strlen($testData));
self::assertEquals(strlen($testData), stream_copy_to_stream($connection, $connection, strlen($testData)));

usleep(300);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These timeouts repeat across multiple tests, it may be worth tp put them behind a descriptive constant? At least add a comment why that "random" sleep is required and how you chose the length of the timeout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to remove this, after root cause is found. Because that depends froms system to system i guess. I was just playing around with the numbers to test it.


$numBytes = $this->socketClient->write($testData);
self::assertEquals(strlen($testData), $numBytes);

// lower timeout for server-socket
stream_set_timeout($this->serverSocket, 0, 100);
self::assertTrue(stream_set_timeout($this->serverSocket, 0, 100));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You ported a bunch of self:: to $this-> in different code-locations. Any particular reason? It probably makes sense to stick to a homogenous style.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PhpUnit function is not static, and that is why PhpStorm nags about this. I just want to make sure, that this is not the reason for the flaky tests. I guess both versions are correct. That was the offical answer i cheked the last time.

@Chris53897
Copy link
Author

@bzikarsky Thanks for your review. I tried several things to solve the problem. It is not solved to 100% actual.
That is why this PR is in DRAFT (WIP) state.

I hope you can help with the root cause of the problem. After that is found and fixed, many changes of this PR could be reverted (or split in seperate PRs).

Can you reproduce the flaky test locally? What system are you useing local?

@bzikarsky
Copy link
Owner

I'm on Linux on all my platforms. I'm open to not waste a lot of time on debugging this though. It seems not completely unlikely that there is something between PHP, the system calls and the (MacOS) kernel that requires a small waiting time before the socket becomes functional. As this only affects tests I am fine to have a small sleep and a comment on why this exists.

@Chris53897
Copy link
Author

As soon as i have some time, i will split it up in different PRs and refatore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants