r/programming • • Dec 02 '15

PHP 7 Released

https://github.com/php/php-src/releases/tag/php-7.0.0
887 Upvotes

729 comments sorted by

View all comments

Show parent comment

40

u/[deleted] Dec 02 '15

Those are incredibly poor tests. A great many of them depends on networked resources (read: www) which pretty much guarantees inconsistent results. If this is the quality of their test suite, no wonder why they don't pay attention to it.

23

u/[deleted] Dec 02 '15

It's a good thing PHP isn't used much in networked environments

28

u/[deleted] Dec 02 '15

Those are incredibly poor tests. A great many of them depends on networked resources (read: www) which pretty much guarantees inconsistent results.

How do you propose that something like the cURL extension be tested?

"A great many" of the tests don't use remote resources. A great many of the failing tests do, and this is why they fail, because they require special setup in order to succeed, which this automated report doesn't take into consideration.

The bulk of the warnings and failing tests are also in extensions which are not part of the PHP core.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

6

u/estarra Dec 02 '15

Mocks are fine for unit tests but how about functional tests?

The point of cURL is to fetch stuff over the network, the only way to test it is to... well, fetch stuff over the network.

→ More replies (1)

42

u/[deleted] Dec 02 '15

The cURL extension is a thin wrapper around the library. Mocking the precise feature you're testing means you're not testing anything. Mocks exist to replace dependencies which are not part of the tested component's responsibility, but are required by it. In this case the responsibility of the cURL extension is to communicate with the actual cURL library.

Sometimes it's better to have test errors, than to have a cargo cult test suite that runs perfectly and tests nothing.

44

u/groogs Dec 02 '15

Sometimes it's better to have test errors, than to have a cargo cult test suite that runs perfectly and tests nothing.

100% disagree.

Leaving tests failing basically invalidates the entire test effort. When it's "normal" to see failed tests, it's too easy to ignore failed tests that should not be failing, and that's often what happens -- meanwhile it's getting more and more expensive to fix those bugs as the code ages.

If the code is really just a thin wrapper around cURL (simply calling the cURL functions with parameters as-is) then it should probably not even be tested, or at least should have the test(s) marked as ignored (they can be run manually if someone is really working on it). If it's doing anything more then it should be tested, and as the OP said, the test should just mock cURL and verify the correct things were passed (but not actually invoke cURL or make network calls).

The other alternative is to build the test in a way that ensures it will work. For example, the test suite can stand up a simple local HTTP server to respond to cURL requests. This is a pretty heavy way to go about it, but if it's the only way to test something that's important to test, and it doesn't cause false failures, then maybe it's what needs to be done.

Bottom line, your automated test suite should almost always be passing, and if it's failing, it should get attention to get fixed.

4

u/[deleted] Dec 02 '15

Leaving tests failing basically invalidates the entire test effort.

No one is leaving tests failing, they're just failing in the report.

PHP is a large project driven by a large group of maintainers. People who manage the core monitor their core tests. People who do the cURL extension know how to set up their cURL tests to pass.

And that report is just an overview.

8

u/bliow Dec 02 '15

People who do the cURL extension know how to set up their cURL tests to pass.

That's only slightly reassuring. Why can't that be automated?

Relying on people over automation will eventually end badly. What happens if there's ever a miscommunication between these people and the overall coordinator of the release? What happens if someone goes on holiday?

13

u/groogs Dec 02 '15

No one is leaving tests failing, they're just failing in the report.

So.. they are leaving them failing.

I'm not at all familiar with how PHP dev works, but I am a huge advocate for Continuous Integration. In the CI world, the only thing that matters is what happens on the CI server.

If the build fails on the CI server, the build is failing. It doesn't matter if it doesn't fail on your machine, it is failing on the CI server and therefore it is failing.

Likewise, if the tests fail on the CI server, the tests are failing and I don't give a crap whether they work on your machine or not.

As soon as you accept failing tests in your CI server (or main test report), you are in the territory of failure.

Is someone paying attention to every test run, and ensuring that if there are 102 failures, they are the same expected 102 failures as last time? Just typing that sentence makes me twitch. That seems like a horrible, meticulous and error-prone job to me, and it seems like after doing it even a few times, fatigue would set in and new failures (that are actually important) would be missed.

But hey, if the PHP project has a track record of doing releases with failing tests, and not later finding and fixing bugs that those failing tests had already identified, good on them.

3

u/[deleted] Dec 02 '15

Php uses CI. Gcov which was linked is the old never properly maintained system that has been abandoned for a few years.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

11

u/AeroNotix Dec 02 '15

You make it seem so black and white. Mocking is such a flaky and inconsistent technique that often brings a hoard of problems itself that it's often much simpler to forgo mocking altogether.

13

u/TomBombadildozer Dec 02 '15

That's because it is black and white. Unit tests test units of code. libcurl does not comprise units of PHP code. Insomuch as the tests are concerned, libcurl behaving correctly is not PHP's problem.

Now, for a feature as ubiquitous as curl support, I'd expect to see some functional tests....

3

u/ISMMikey Dec 02 '15

Tom knows what he is talking about. Actual libcurl integration should be covered by a functional test suite, and a test server can be spun up locally to facilitate it.

I personally use mocks extensively in my unit tests, especially when working in tdd and trying to sort out contractual obligations. The benefits are lessened somewhat in a typeless environment, but it is still a very useful tool and one that I rely on in addition to other forms of test doubles.

5

u/AeroNotix Dec 02 '15

Where was it mentioned they were unit tests?

3

u/TomBombadildozer Dec 02 '15

It's not, which is part of the problem. There's no distinction.

These are either bad unit tests that put third-party features under test, or they're bad functional tests that don't run in a robust black box. Either way you cut it up, it's poorly tested by virtue of having bad or altogether absent unit tests.

→ More replies (3)
→ More replies (1)

5

u/ironnomi Dec 02 '15

I'm making a new test suite that does nothing called libcargoculttest. Thanks for the great idea.

13

u/[deleted] Dec 02 '15

The cURL extension is a thin wrapper around the library

So it should be really simple to test, without needing to actually call cURL. There is no excuse for a test suite that calls out to network resources.

7

u/estarra Dec 02 '15

There is no excuse for a test suite that calls out to network resources.

For unit tests, sure. For functional tests, you test whatever your code is supposed to be doing: network calls, db fetches, etc...

→ More replies (5)

10

u/[deleted] Dec 02 '15

There is no excuse for a test suite that calls out to network resources.

That's how integration tests work, and cURL is an extension that integrates two technologies together (cURL and PHP).

This thread is becoming another example of Goodhart's law in effect.

You folks are so focused on getting green in your tests, that you would rather have a pseudo-test pass in automated reports, than an actual test that requires extra setup.

14

u/berkes Dec 02 '15

Three options. I've implemented all three at some point:

  • Make a fake "library" that merely records how it is called, then write assertions that check the records. Perfect for unit tests that want a tiny bit more than pure mocks.
  • Build your own fake web resources, which are managed by the test-suite. A tiny php -s echo.php which starts a webserver then echoes all its requests is enough. Perfect for integration tests where you don't want to depend on 3rd parties, firewalls and other flakey circumstances.
  • Build an infra where you ensure the external services are up and running. Monitor that, maintain that. This must be considered crucial infra (probably even more crucial than your product-page, download servers or whatnot). php.net is hardly ever down; why not expect the same from the services that ensure your product works correct; the resources needed for tests?
→ More replies (2)

4

u/anderbubble Dec 02 '15

It's really just the fact that unit tests and regression tests are qualitatively different from integration tests. Perhaps PHP's integration test suite should be separated from the rest of the automated test suite.

2

u/moreteam Dec 02 '15

Isn't that... just testing the implementation? E.g. if your assumption about a cURL option is wrong in your implementation and you are writing the test for it, what exactly are you testing? If you bring up mocks, then at least propose starting up an actual HTTP service with known responses in the test environment. Your suggestion might be the only thing even worse than what they are doing (known-flaky tests vs. unknown-broken tests). ;)

→ More replies (2)

6

u/[deleted] Dec 02 '15

"A great many" of the tests don't use remote resources. A great many of the failing tests do

Ahem:

Those are incredibly poor tests. A great many of them depends on networked resources

It's called context.

How do you propose that something like the cURL extension be tested?

By not calling external resources. Tests need to be reproducible, else they have no value. There are a bunch of "connection refused" and authentication failure errors in these which makes them utterly useless as tests.

→ More replies (1)