Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Add feature tests #102

Merged
merged 14 commits into from Mar 2, 2021
Merged

Add feature tests #102

merged 14 commits into from Mar 2, 2021

Conversation

mmachatschek
Copy link
Collaborator

@mmachatschek mmachatschek commented Feb 14, 2021

WIP

This adds feature tests to the repo and solves #90 and #81

TODOS:

  • Add documentation how to run feature tests locally
  • Add more tests (based on https://github.com/meilisearch/meilisearch-symfony/)
  • Update the cleanup method and add a SCOUT_PREFIX config with a test key and only remove indexes with that prefix to avoid deleting documents from a local meilisearch instance

I added a matrix for the meilisearch containers to also test the library against older versions. If this should be removed, just tell me @shokme or @curquiza.

@curquiza
Copy link
Member

Hello @mmachatschek!
Thanks for this awesome PR. Feel free to remove the "Draft PR" status when you are ready for a review!

I added a matrix for the meilisearch containers to also test the library against older versions. If this should be removed, just tell me @shokme or @curquiza.

No need to test the previous version of MeiliSearch for the moment. Since MeiliSearch is not stable, it does not worth it 🙂

Thanks again!

@mmachatschek mmachatschek marked this pull request as ready for review February 17, 2021 12:49
Remove duplicate underscore
@mmachatschek
Copy link
Collaborator Author

@curquiza this is ready for review.

For the actual search queries to MeiliSearch I had to wrap it with a retry function because of a race condition, where meilisearch's index wasn't yet ready for all entries. How was this solved in symfony or other implementations?

@curquiza
Copy link
Member

curquiza commented Feb 17, 2021

Hello @mmachatschek!

For the actual search queries to MeiliSearch I had to wrap it with a retry function because of a race condition, where meilisearch's index wasn't yet ready for all entries. How was this solved in symfony or other implementations?

If I understand well you need to be sure the push of documents is ready when you want to search. We provide a function in the meilisearch-php client, which is waitForPendingUpdate.

A usage example: https://github.com/meilisearch/meilisearch-php/blob/6cb37bae30904b0364fc5dc30b71cc41fbc6cac4/tests/Endpoints/SearchTest.php#L17-L19

The implementation of the method if you are curious: https://github.com/meilisearch/meilisearch-php/blob/6cb37bae30904b0364fc5dc30b71cc41fbc6cac4/src/Endpoints/Indexes.php#L116-L137

Sorry it's not documented yet!

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

This is the first review, I have not checked the code, I'm waiting for your update with the waitForPendingUpdate method 👍

.github/workflows/tests.yml Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
@curquiza
Copy link
Member

curquiza commented Feb 18, 2021

Also @mmachatschek you seem really involved in this repo and all the MeiliSearch team wants to thank you! That's why I've just given the write access to you on the repo 🙂 No need to work on your forked repository anymore, and your reviews will be valuable (= take into account as a real reviewer by GitHub).
Hope you are ok with this! 😁

@mmachatschek
Copy link
Collaborator Author

mmachatschek commented Feb 19, 2021

If I understand well you need to be sure the push of documents is ready when you want to search. We provide a function in the meilisearch-php client, which is waitForPendingUpdate.

I looked into this. It would definitely fix the race condition in the tests. However it would require to mock the feature tests again and hook into the Indexes class as far as I can tell. Which we generally wanted to avoid in the feature tests.

Also @mmachatschek you seem really involved in this repo and all the MeiliSearch team wants to thank you! That's why I've just given the write access to you on the repo 🙂 No need to work on your forked repository anymore, and your reviews will be valuable (= take into account as a real reviewer by GitHub).
Hope you are ok with this! 😁

Thanks @curquiza for that I'll gladly contribute to this and maybe other repos of MeiliSearch 😊

@curquiza
Copy link
Member

I looked into this. It would definitely fix the race condition in the tests. However it would require to mock the feature tests again and hook into the Indexes class as far as I can tell. Which we generally wanted to avoid in the feature tests.

Hum I don't understand why we would mock this part 🤔 In all our other repositories we do tests with the waitForPendingUpdate method without any mocking test. In general, we don't have any mocking tests.

@mmachatschek
Copy link
Collaborator Author

Hum I don't understand why we would mock this part thinking In all our other repositories we do tests with the waitForPendingUpdate method without any mocking test. In general, we don't have any mocking tests.

I can't think of a possibility to get the promiseId of an update/create event returned by the meilisearch-php client. via the laravel-scout library without changing any method signature or mocking/extending anything for the test. Maybe I'm missunderstanding something here 😅

@shokme maybe you have an Idea how to use either waitForPendingUpdate or hook into laravel-scout etc.

@curquiza
Copy link
Member

curquiza commented Feb 23, 2021

Hum, I see you have a waitForIndexToUpdate which is a good start.
In this method, a way to know if all the actions are processed would be to call the route "Get all updates status" (https://docs.meilisearch.com/reference/api/updates.html#get-all-update-status). It's getAllUpdateStatus with the PHP SDK. You can gather all the status -> if there is one "enqueued", this is not over.
It's not performant, I agree, but this is for tests purpose :)

@mmachatschek
Copy link
Collaborator Author

mmachatschek commented Feb 23, 2021

@curquiza I updated the code now. Now we use your suggested method with getAllUpdateStatus. I iterate over the updateId and we will wait for all updates to finish

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

I have some questions, sorry if there are newbie questions, I have a limited experience with Laravel 🙂

phpunit.xml.dist Show resolved Hide resolved
{
collect(resolve(Client::class)->getAllIndexes())->each(function (Indexes $index) {
// Starts with prefix
if (substr($index->getUid(), 0, strlen($this->getPrefix())) === $this->getPrefix()) {
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this condition?
I think we should delete all the indexes without any condition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just wanted to make sure that there is no data lost if someone runs the tests with an existing instance. So this just removes the indexes from meilisearch that start with the prefix set in the tests.

https://github.com/meilisearch/meilisearch-laravel-scout/pull/102/files#diff-abf1fa77a19f720052b75bc802df0260157b9064d8c3c12a80794f01e9acc065R37-R38

tests/Feature/MeilisearchConsoleCommandTest.php Outdated Show resolved Hide resolved
tests/Feature/MeilisearchTest.php Show resolved Hide resolved
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

Awesome!! Thank you so much @mmachatschek!!

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 2, 2021

@bors bors bot merged commit 8652b62 into meilisearch:main Mar 2, 2021
@mmachatschek mmachatschek deleted the add_feature_tests branch March 3, 2021 07:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants