Closed cameron1729 closed 1 year ago
Following on from my comment here - I think the reason this guzzle_exception
thing was added is to handle the case where the Elasticsearch service URL is invalid on the configuration page. Without additional handling, the stack trace and everything will appear there, when really we just want a status code.
Instead of handling the situation where the server can't be accessed directly http_action
, I've updated get_server_status_code
to use a try/catch. http_action
is supposed to return a response, so it doesn't feel right that it should try to handle the case where the server is unreachable (hence there cannot be a response) - it feels appropriate to throw an exception and leave it to calling code to either surface the exception or gracefully handle it.
Thanks for the fix @cameron1729 Any chance you can add automated tests to cover this change?
Also pinging @marxjohnson here in case he has a spare minute to have a look.
@dmitriim looks like the plugin has some decent coverage already so hopefully won't be too difficult to update for this change.
well, no tests exploded after the code change.
@dmitriim just pushed a commit adding some new tests. I wanted to see if it would be possible to modify existing ones - but they are all using Guzzle mock stuff, and in those cases exceptions don't trigger the same way they do when trying to make a real curl request (even though some people claim it should be possible I couldn't get it to work).
I just added two new tests which try to really call unreachable URIs.
@cameron1729 Your explanation and solution both look good to me!
NB: As we are testing situations in which Elasticsearch is unreachable, it is not necessary to have an Elasticsearch service running locally to complete testing.
Prerequisites
is_server_ready
function to make the indexing scheduled task run)Testing
is_server_ready
in classes/engine.php so that it immediately returns true:php admin/cli/scheduled_task.php --execute="\\core\\task\\search_index_task"
Bonus
Set up an Elasticsearch server and verify that the plugin works correctly when properly configured
!fixes #117