10000 [HttpFoundation] Check Mongo effective connection before starting tests by EmanueleMinotto · Pull Request #16287 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Check Mongo effective connection before starting tests #16287

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

Closed
wants to merge 1 commit into from
Closed

[HttpFoundation] Check Mongo effective connection before starting tests #16287

wants to merge 1 commit into from

Conversation

EmanueleMinotto
Copy link
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

The test suite for MongoDbSessionHandlerTest is executed even if a connection can’t be established.

@EmanueleMinotto EmanueleMinotto changed the title Check Mongo effective connection before starting tests [HttpFoundation] Check Mongo effective connection before starting tests Oct 19, 2015
@Tobion
Copy link
Contributor
Tobion commented Oct 19, 2015

Mongo is mocked in the tests. So there should not be any connection necessary at all. So this change doesn't make sense to me.

Status: Needs Work

@EmanueleMinotto
Copy link
Author

Hi @Tobion, this is my first source PR so probably hasn't the best development topics behind, sorry about it. ^^'

Anyway I'm seeing that currently this test class has the annotation @requires extension mongo and locally I had:

There were 10 errors:

1) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testConstructorShouldThrowExceptionForInvalidMongo
MongoConnectionException: Failed to connect to: localhost:27017: Connection refused

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

2) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testConstructorShouldThrowExceptionForMissingOptions
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

3) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testOpenMethodAlwaysReturnTrue
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

4) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testCloseMethodAlwaysReturnTrue
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

5) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testRead
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

6) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWrite
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

7) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWriteWhenUsingExpiresField
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

8) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testReplaceSessionData
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

9) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testDestroy
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

10) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testGc
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:37

I have the mongo extension installed but default parameters aren't accepted for the connection.

Should I open an issue about these failures instead of this PR?

@Tobion
Copy link
Contributor
Tobion commented Oct 19, 2015

I think it's because the original constructor is still called of the mock. Please adjust the code in https://github.com/EmanueleMinotto/symfony/blob/mongo-effective-connection/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php#L36 as follows and the 8000 n test again.

$this->mongo = $this->getMockBuilder($mongoClass)
    ->disableOriginalConstructor()
    ->getMock();

@EmanueleMinotto
Copy link
Author

Still failing, 6 failures now:

There were 6 errors:

1) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testRead
MongoConnectionException: Failed to connect to: localhost:27017: Connection refused

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:94

2) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWrite
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:130

3) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWriteWhenUsingExpiresField
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:171

4) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testReplaceSessionData
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:199

5) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testDestroy
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:222

6) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testGc
MongoConnectionException: Failed to connect to: localhost:27017: Previous connection attempts failed, server blacklisted

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:260
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:238

Could https://github.com/symfony/symfony/blob/2.8/.travis.yml#L26 affect results?

@EmanueleMinotto
Copy link
Author

@Tobion how should I proceed?

@xabbuh
Copy link
Member
xabbuh commented Oct 22, 2015

@EmanueleMinotto Did you change the createMongoCollectionMock() method in the test class too?

@EmanueleMinotto
Copy link
Author

@xabbuh sorry, I didn't see the notification.
The checkMongoConnection is executed before any test methods in the class and createMongoCollectionMock is private, why should I change it too?

@xabbuh
Copy link
Member
xabbuh commented Oct 28, 2015

@EmanueleMinotto Because from looking at the stack trace you posted the error is triggered in that method when creating the mock object.

@EmanueleMinotto
Copy link
Author

@xabbuh added the check in createMongoCollectionMock too

@xabbuh
Copy link
Member
xabbuh commented Oct 28, 2015

Imo having this check method is the wrong solution. Simply calling disableOriginalConstructor() on the mock builder was way cleaner.

@EmanueleMinotto
Copy link
Author

That's what I meant some comments above, even with disableOriginalConstructor() I'm having some failures ( 6 ), could be that https://github.com/symfony/symfony/blob/2.8/.travis.yml#L26 affects results?

@xabbuh
Copy link
Member
xabbuh commented Oct 28, 2015

@EmanueleMinotto Can you please push the disableOriginalConstructor() calls that you did locally here? I think you simply missed calling it in both places.

@EmanueleMinotto
Copy link
Author

@xabbuh you're right, output changes, but I'm still having 6 failures:

There were 6 errors:

1) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testRead
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:80

2) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWrite
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:116

3) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testWriteWhenUsingExpiresField
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:157

4) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testReplaceSessionData
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:185

5) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testDestroy
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:208

6) Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testGc
MongoException: The Mongo object has not been correctly initialized by its constructor

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:250
src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php:224

@xabbuh
Copy link
Member
xabbuh commented Oct 28, 2015

@EmanueleMinotto Hard to tell without knowing how your code now looks like. Please push your changes here.

@xabbuh
Copy link
Member
xabbuh commented Oct 28, 2015

@EmanueleMinotto I found some time to have a deeper look into your issue which should be solved by #16370.

@xabbuh xabbuh closed this Oct 28, 2015
@EmanueleMinotto
Copy link
Author

@xabbuh great, thanks

Tobion added a commit that referenced this pull request Oct 28, 2015
…bjects (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] don't call constructors on Mongo mock objects

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16287
| License       | MIT
| Doc PR        |

Calling the parent constructor of the mocked `Mongo` class tries to
connect to a local MongoDB server which fails in case no local server
was configured.

Similarly, when the parent constructor of the mocked `MongoCollection`
class is called it performs checks on the passed arguments which fails
again when a connection was not established successfully before.

Commits
-------

6541b8b don't call constructors on Mongo mock objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0