-
Notifications
You must be signed in to change notification settings - Fork 28
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
Return 500 when DB is not connected (fix for issue 570) #574
Return 500 when DB is not connected (fix for issue 570) #574
Conversation
@AlvaroVega , Please review the PR. Thanks :) |
I'm afraid this PR cannot be merged in its current form. Test are not passing. In addition, an entry about the fixes in this PR should be added to CHANGES_NEXT_RELEASE file. |
@Gauravp-NEC could you please add any kind of tests which uses this PR? This way we can check and understand better what case is not covered by mongo driver reconnect mechanism. |
We have been seeing similar fails in other Node-based repositories (see thread: telefonicaid/iotagent-node-lib#1119 (comment)). Let's wait to see if it somekind of overall Github Actions issue... |
@fgalan , If the test case failure is overall GitHub action issue, this means that test case failure is not because of this PR. Please merge the PR. I have also tested this PR in my development environment and it is working fine. |
@AlvaroVega , Done in commit 1e3615c |
Note that although tests get working in your local environment, we also need to ensure that they pass at Github Actions. Github Actions testing is a "common ground" to run regression, so we can avoid any potential "byassing" in local environments. In this case, the issue was solved in master branch, your PR synched with master and now the tests are passing. This is the way to go :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Gauravp-NEC I just copied your code to a new branch and modify the test in this PR #577 The test implemented queries the API (GET /STH/v2/entities/entityId/attrs/attrName?type=entityType&lastN=1) with the server started and the DB connection previously closed. The test implemented is the following: describe('When the database is not connected', function() {
before(function(done) {
sth.sthServer.startServer(sthConfig.STH_HOST, sthConfig.STH_PORT, function(err, server) {
sthDatabase.closeConnection(function() {
done();
});
});
});
it('should return 500', function(done) {
let url_sth =
'http://' +
sthConfig.STH_HOST +
':' +
sthConfig.STH_PORT +
'/STH/v2/entities/entityId/attrs/attrName?type=entityType&lastN=1';
request(
{
uri: url_sth,
method: 'GET',
headers: {
'Fiware-Service': sthConfig.DEFAULT_SERVICE,
'Fiware-ServicePath': sthConfig.DEFAULT_SERVICE_PATH
}
},
function(err, response, body) {
expect(response.statusCode).to.equal(500);
done();
}
);
});
after(function(done) {
sth.exitGracefully(null, done);
});
});
}); The following error is given when requesting the API without the database connected:
This seems the purpose of the PR is not satisfied since there is no an answer when requesting without the DB connected |
@mapedraza @fgalan , In this PR currently only the test case part is might not satisfying.I would have fixed the test case after the review comment. Rest the code and logic is successful in fixing the issue #570. Also AlvaroVega, has already approved this PR and left the comment |
No, I'm afraid we cannot merge a code which unit tests are nor properly implemented. Please, have a look to the unit test implemented by @mapedraza in his PR #577. The script of that test looks really nice although it is not currently working (in PR #577 you would see a green mark in GitActions report, but if you run locally the tests in branch task/validate_PR_574, you should see it failing). We are not sure right now if the fail is in the test script or in the STH implementation logic. Thus, I'd suggest to replace your test in this PR by the test @mapedraza has developed in your PR and continue from that point (i.e. investigating the problem either in the test or in the STH implemented logic). |
@fgalan @mapedraza , We have taken two approach to perform UT test case.
Step 1 and 2 are executed successfully but in step 3 , the
If we can implement mocking in UT test case we can achieve the complete code coverage, but we have observed that mocking is currently not used in STH-Comet. Please let us know your opinion. |
@fgalan @mapedraza @AlvaroVega
We request you to provide your input as how can we stop mongoDB database in running UT so that when we push code then CI tool will also execute the UT successfully? |
@fgalan @mapedraza @AlvaroVega , We have resolved the UT failure and added new test case to cover error code 500 in commit 921574a. Now all the test cases have been passed successfully. |
At the current version the PR is almost ready but two things are pending:
We are going to merge this PR in an intermediate branch :Fix-for-issue-570-prelanding so @mapedraza could do the final fixes before merging. Thanks for your contribution! |
Continues in PR #583 |
This PR fixes the issue : #570
If database is not connected and any API will be requested then it will return "500 internal server error" and in logs it will display "database is not connected"