Skip to content

Commit 1e0d08a

Browse files
committed
Support testing with remotes
1 parent 91794ec commit 1e0d08a

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
3434

3535
You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).
3636

37+
#### With Docker <!-- omit in toc -->
3738
Example of running all the checks with docker:
3839
```bash
3940
docker-compose run --rm package bash -c "bundle install && bundle exec rspec && bundle exec rubocop"
4041
```
42+
<!-- need to run multiple instances of meilisearch for proxy tests -->
43+
44+
#### Locally <!-- omit in toc -->
4145

4246
To install dependencies:
4347
```bash
@@ -51,7 +55,12 @@ Each PR should pass the tests to be accepted.
5155
```bash
5256
# Tests
5357
curl -L https://install.meilisearch.com | sh # download Meilisearch
54-
./meilisearch --master-key=masterKey --no-analytics # run Meilisearch
58+
59+
# run Meilisearch
60+
./meilisearch --master-key=masterKey --no-analytics
61+
# run a second instance of Meilisearch to act as proxy
62+
./meilisearch --master-key=masterKey --no-analytics --http-addr localhost:7701
63+
5564
bundle exec rspec
5665
```
5766

docker-compose.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ services:
1010
environment:
1111
- MEILISEARCH_URL=meilisearch
1212
- MEILISEARCH_PORT=7700
13+
- MEILISEARCH_REMOTE_URL=meilisearch_remote
14+
- MEILISEARCH_REMOTE_PORT=7701
1315
- BUNDLE_PATH=/vendor/bundle
1416
depends_on:
1517
- meilisearch
16-
links:
17-
- meilisearch
18+
- meilisearch_remote
1819
volumes:
1920
- ./:/home/package
2021
- bundle:/vendor/bundle
2122

2223
meilisearch:
23-
image: getmeili/meilisearch:latest
24+
image: getmeili/meilisearch:nightly
2425
ports:
2526
- "7700"
2627
environment:
2728
- MEILI_MASTER_KEY=masterKey
2829
- MEILI_NO_ANALYTICS=true
30+
31+
meilisearch_remote:
32+
image: getmeili/meilisearch:nightly
33+
ports:
34+
- "7701"
35+
environment:
36+
- MEILI_MASTER_KEY=masterKey
37+
- MEILI_NO_ANALYTICS=true
38+
command: ["meilisearch", "--http-addr", "0.0.0.0:7701"]

spec/meilisearch/client/multi_search_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,61 @@
7575
expect(hits.size).to be 3
7676
expect(hits.first).to have_key('_federation')
7777
end
78+
79+
describe 'searching multiple remotes' do
80+
it 'federated search searches multiple remotes' do
81+
client.update_experimental_features(network: true)
82+
proxy_client.update_experimental_features(network: true)
83+
84+
client.update_network(
85+
self: 'ms0',
86+
remotes: {
87+
ms2: {
88+
url: PROXY_URL,
89+
search_api_key: MASTER_KEY
90+
}
91+
}
92+
)
93+
94+
three_body_problem = { id: 1, title: 'The Three Body Problem' }
95+
the_dark_forest = { id: 2, title: 'The Dark Forest' }
96+
proxy_client.index('books').add_documents([three_body_problem, the_dark_forest]).await
97+
98+
sherwood_forest = { id: 50, name: 'Sherwood Forest' }
99+
forbidden_forest = { id: 200, name: 'Forbidden Forest' }
100+
client.index('parks').add_documents([sherwood_forest, forbidden_forest]).await
101+
102+
response = client.multi_search(
103+
federation: {},
104+
queries: [
105+
{
106+
q: 'Forest',
107+
index_uid: 'parks',
108+
federation_options: {
109+
remote: 'ms0'
110+
}
111+
},
112+
{
113+
q: 'Body',
114+
index_uid: 'books',
115+
federation_options: {
116+
remote: 'ms2'
117+
}
118+
}
119+
]
120+
)
121+
122+
resp = response['hits'].map { |hit| hit.slice('id', 'name', 'title').transform_keys(&:to_sym) }
123+
124+
expect(resp).to include(three_body_problem, sherwood_forest, forbidden_forest)
125+
expect(resp).not_to include(the_dark_forest)
126+
rescue Meilisearch::CommunicationError
127+
pending('Please launch a second instance of Meilisearch to test network search, see spec_helper for addr config.')
128+
raise
129+
ensure
130+
client.update_network(self: nil, remotes: nil)
131+
client.delete_index('parks')
132+
proxy_client.delete_index('books')
133+
end
134+
end
78135
end

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
# Globals for all tests
4343
URL = format('http://%<host>s:%<port>s',
4444
host: ENV.fetch('MEILISEARCH_URL', 'localhost'), port: ENV.fetch('MEILISEARCH_PORT', '7700'))
45+
46+
PROXY_URL = format('http://%<host>s:%<port>s',
47+
host: ENV.fetch('MEILISEARCH_REMOTE_URL', 'localhost'),
48+
port: ENV.fetch('MEILISEARCH_REMOTE_PROXY', '7701'))
49+
4550
MASTER_KEY = 'masterKey'
4651
DEFAULT_SEARCH_RESPONSE_KEYS = [
4752
'hits',

spec/support/default_shared_context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
RSpec.shared_context 'test defaults' do
44
let(:client) { Meilisearch::Client.new(URL, MASTER_KEY, { timeout: 2, max_retries: 1 }) }
5+
let(:proxy_client) { Meilisearch::Client.new(PROXY_URL, MASTER_KEY, { timeout: 2, max_retries: 1 }) }
56

67
before do
78
clear_all_indexes(client)

0 commit comments

Comments
 (0)