Skip to content

Commit 6b10411

Browse files
salman1993gems
andauthored
chore(devex): streamline local OpenSearch and Postgres test workflows (#10034)
## Summary Follow-up to #9838 to make the local dev and test workflow for OpenSearch (and PostgreSQL-backed tests) smooth out of the box while keeping OpenSearch opt-in by default for `just relay` / `just dev` / `just setup`. ### What changed - **Fix Docker Compose `--profile '*'` handling (`Justfile`, `scripts/dev-reset.sh`):** - `just down`, `just ps`, and `just logs` now pass `--profile '*'` so `buzz-opensearch` is actually stopped, listed, and tailable. - `scripts/dev-reset.sh` passes `--profile '*'` to `docker compose down -v --remove-orphans` so `buzz-opensearch-data` is wiped alongside Postgres instead of leaving stale indexed docs behind. - **One-command local OpenSearch dev flow (`Justfile`, `scripts/dev-setup.sh`):** - Added `search := ""` toggle (`just search=1 relay`, `just search=1 relay-release`, `just search=1 relay-web`, `just search=1 dev`, `just search=1 setup`) that auto-starts `buzz-opensearch`, waits for health (dumping container logs on timeout), and defaults `BUZZ_OPENSEARCH_URL=http://localhost:9200` + `BUZZ_OPENSEARCH_PREVIEW=true`. - `_ensure-services` also auto-starts `buzz-opensearch` when `BUZZ_OPENSEARCH_URL` (from env or `.env`) points to `http://localhost:9200` or `http://127.0.0.1:9200`. - Preserved caller-supplied `BUZZ_OPENSEARCH_URL` / `BUZZ_OPENSEARCH_PREVIEW` overrides across `source .env`. - **One-command search & Postgres test runners (`Justfile`, `scripts/postgres-test-*.sh`, `crates/buzz-search/tests/`):** - Added `just test-postgres [*ARGS]` (auto-starts Docker services including local OpenSearch when `BUZZ_TEST_OPENSEARCH_URL` targets `localhost:9200` / `127.0.0.1:9200`, matching the CI PostgreSQL lane, and sets local DB/OpenSearch env defaults), `just test-search [*ARGS]` (delegates to `just test-postgres -p buzz-search --tests`), and routed `just test-media-access` through `test-postgres`. - Added Homebrew keg-only `libpq` / `postgresql@17` lookup in `scripts/postgres-test-{run,setup,wrapper}.sh` and clearer errors when `BUZZ_POSTGRES_ADMIN_URL` or `cargo-nextest` is missing. - Improved OpenSearch test panic messages in `buzz-search` to include the target URL and `just test-search` hint. - **Docs (`docs/opensearch-search-deployment.md`, `CONTRIBUTING.md`, `TESTING.md`, `AGENTS.md`):** - Documented `just search=1 relay`/`dev`, `just test-search`, and `just test-postgres`. ## Testing ### Live Docker runs (macOS, head `cf91cb1653`) - `just ps`: listed `buzz-opensearch` (`Up ... (healthy) 127.0.0.1:9200->9200/tcp`) alongside Postgres, Redis, MinIO, Adminer, Keycloak, Prometheus. - `just logs --tail 3 opensearch`: tailed `buzz-opensearch` logs. - `just down`: stopped and removed `buzz-opensearch` along with all other services (`docker ps --filter name=buzz-opensearch` returned empty). - `just search=1 _ensure-services`: brought up the default services, waited for Postgres/Redis healthy, then created/started `buzz-opensearch` and waited until healthy (`Waiting for OpenSearch.... ready`). - `docker compose --profile '*' config --volumes`: confirmed `opensearch-data` is included for `scripts/dev-reset.sh`'s `down -v`. - `just test-search -E 'binary(postgres_opensearch_search) & test(search_finds_event_in_same_community)'`: passed (`1 passed, 38 skipped` in `1.509s`) with zero manual env vars. - `just test-postgres -p buzz-relay --lib -E 'test(the_flag_picks_the_backend_for_the_whole_relay_while_it_runs)'`: passed (`1 passed, 2604 skipped` in `1.891s`) with zero manual env vars. - `just search=1 relay` (against a disposable DB on non-colliding ports): booted cleanly, `/health` returned `ok`, relay logged `search outbox enabled`, `Search service ready (opensearch: true)`, and `search indexer started`, and `http://localhost:9200/_alias/buzz-messages` resolved to `buzz-messages-v2`. ### Static & unit checks - `bash -n` on all modified shell scripts - `scripts/test-postgres-test-wrapper.sh` and `scripts/test-postgres-test-discovery.sh` - `cargo fmt -p buzz-search -- --check`, `cargo test -p buzz-search --lib`, `cargo check -p buzz-search --tests`, and `cargo clippy -p buzz-search --tests -- -D warnings` - `just file-size-check` and `scripts/check-branch-skew.sh` --------- Signed-off-by: Salman Mohammed <smohammed@squareup.com> Co-authored-by: gems <fd3f5b81c5a75b0b7b88ab01493114227182cc60e16422921001d458d2a64236@buzz.block.builderlab.xyz>
1 parent b5f8b38 commit 6b10411

12 files changed

Lines changed: 257 additions & 51 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ crates/
112112
buzz-db # Postgres event store and data access layer
113113
buzz-auth # Authentication and authorization
114114
buzz-pubsub # Redis pub/sub fan-out, presence, typing indicators
115-
buzz-search # Postgres FTS full-text search
115+
buzz-search # Postgres FTS and OpenSearch message search + indexer
116116
buzz-audit # Hash-chain audit log
117117
buzz-media # Blossom/S3 media storage
118118
# Agent surface

‎CONTRIBUTING.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ We review as capacity allows — focused PRs that follow this guide move fastest
8585
| pnpm | 10+ | Required for desktop app commands and `just ci` |
8686
| Flutter | 3.47.9+ | Required for mobile app — install via [flutter.dev](https://docs.flutter.dev/get-started/install) |
8787
| Xcode | 27.1 recommended; 26 supported | Required for iOS builds; see [iOS toolchain setup](mobile/README.md#ios-toolchain) |
88-
| Docker | 24+ | For Postgres, Redis, MinIO |
88+
| Docker | 24+ | For Postgres, Redis, MinIO (and opt-in OpenSearch) |
8989
| `just` | latest | Task runner — `cargo install just` |
90+
| `cargo-nextest` | 0.9.136+ | Faster unit tests; required for `just test-postgres` and `just test-search` |
9091
| `lefthook` | 2.1.3 (Hermit-pinned) | Auto-installed by `just hooks` — no manual install needed |
9192
| `sqlx` migrations | workspace crate | `just migrate` applies embedded migrations from `migrations/` |
9293

@@ -179,6 +180,13 @@ just relay # terminal 1 — relay on ws://localhost:3000
179180
just desktop-dev # terminal 2 — Vite dev server only (no Tauri shell)
180181
```
181182

183+
To also run the opt-in local OpenSearch message index (auto-starts the
184+
`buzz-opensearch` container on `:9200`):
185+
186+
```bash
187+
just search=1 relay # or `just search=1 dev`
188+
```
189+
182190
### Stopping / Resetting
183191

184192
```bash
@@ -264,11 +272,20 @@ Set `BUZZ_POSTGRES_ADMIN_URL` to that role's maintenance database, and set
264272
schema bootstrap. PostgreSQL client tools are resolved from `PATH` unless
265273
`PG_BIN_DIR` is set. Tests that use Redis read `REDIS_URL`.
266274

267-
With native PostgreSQL and Redis running, the complete lane is below. The
268-
runner bounds compilation to the packages discovered from the current source
269-
tree and removes the run-scoped desired-state source database on exit.
270-
Per-test and source-database cleanup retries transient PostgreSQL disconnect
271-
races and emits a warning if all five attempts fail.
275+
Against the local Docker Compose stack, the `just` recipes auto-start the
276+
needed containers and set the local Postgres/OpenSearch environment variables
277+
for you (requires `cargo-nextest` and PostgreSQL client tools such as `psql` /
278+
`createdb` / `dropdb`):
279+
280+
```bash
281+
just test-search # Postgres FTS + OpenSearch tests
282+
just test-postgres # full PostgreSQL-backed lane
283+
just test-postgres -p buzz-db --lib # a single package or filter
284+
```
285+
286+
Against native PostgreSQL and Redis (or CI), run the script directly after
287+
setting `BUZZ_POSTGRES_ADMIN_URL`, `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`,
288+
and `REDIS_URL`:
272289

273290
```bash
274291
./scripts/postgres-test-run.sh

‎Justfile‎

Lines changed: 126 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ web_dir := "web"
1212
# `just mesh=1 staging` / `just mesh=1 production`.
1313
mesh := ""
1414

15+
# Opt-in OpenSearch message index. Off by default so Postgres-only work skips
16+
# the extra JVM container. Turn on with `just search=1 relay` / `just search=1 dev`
17+
# / `just search=1 setup`, or by uncommenting BUZZ_OPENSEARCH_URL in .env.
18+
search := ""
19+
1520
# Reset only the current standalone desktop instance before launch.
1621
# Usage: `just fresh=1 desktop-standalone`.
1722
fresh := ""
@@ -47,7 +52,7 @@ bootstrap:
4752
4853
# Start Docker services, run migrations, install desktop deps
4954
setup: bootstrap
50-
./scripts/dev-setup.sh
55+
BUZZ_DEV_SEARCH="{{search}}" ./scripts/dev-setup.sh
5156

5257
# Install git hooks via lefthook (dispatches from the shared .git/hooks dir so all
5358
# linked worktrees inherit the same hooks without a worktree-relative .hooks path)
@@ -72,15 +77,15 @@ reset:
7277

7378
# Stop all dev services (keep data)
7479
down:
75-
docker compose down
80+
docker compose --profile '*' down
7681

7782
# Show dev service status
7883
ps:
79-
docker compose ps
84+
docker compose --profile '*' ps
8085

8186
# Tail all service logs
8287
logs *ARGS:
83-
docker compose logs -f {{ARGS}}
88+
docker compose --profile '*' logs -f {{ARGS}}
8489

8590
# ─── Build & Check ───────────────────────────────────────────────────────────
8691

@@ -183,32 +188,76 @@ _ensure-sidecar-stubs:
183188
[[ -e "$stub" ]] || : > "$stub"
184189
done
185190
186-
# Ensure Docker dev services (Postgres, Redis, etc.) are running and healthy
187-
_ensure-services:
191+
# Ensure the opt-in OpenSearch dev container is running and healthy
192+
_ensure-opensearch:
188193
#!/usr/bin/env bash
189194
set -euo pipefail
190-
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-postgres 2>/dev/null || echo "not_found")
191-
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-redis 2>/dev/null || echo "not_found")
192-
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
193-
echo "Services already healthy"
195+
os=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-opensearch 2>/dev/null || echo "not_found")
196+
if [[ "$os" == "healthy" ]]; then
197+
echo "OpenSearch already healthy"
194198
exit 0
195199
fi
196-
echo "Starting services..."
197-
docker compose up -d || true
198-
echo -n "Waiting for services"
199-
for i in $(seq 1 40); do
200-
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-postgres 2>/dev/null || echo "not_found")
201-
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-redis 2>/dev/null || echo "not_found")
202-
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
200+
echo "Starting OpenSearch..."
201+
docker compose --profile search up -d opensearch
202+
echo -n "Waiting for OpenSearch"
203+
for i in $(seq 1 60); do
204+
os=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-opensearch 2>/dev/null || echo "not_found")
205+
if [[ "$os" == "healthy" ]]; then
203206
echo " ready"
204207
exit 0
205208
fi
206209
echo -n "."
207-
sleep 3
210+
sleep 2
208211
done
209212
echo " timed out"
213+
docker logs buzz-opensearch 2>&1 | tail -30 >&2 || true
210214
exit 1
211215
216+
# Ensure Docker dev services (Postgres, Redis, etc.) are running and healthy
217+
_ensure-services:
218+
#!/usr/bin/env bash
219+
set -euo pipefail
220+
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-postgres 2>/dev/null || echo "not_found")
221+
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-redis 2>/dev/null || echo "not_found")
222+
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
223+
echo "Services already healthy"
224+
else
225+
echo "Starting services..."
226+
docker compose up -d || true
227+
echo -n "Waiting for services"
228+
ready=false
229+
for i in $(seq 1 40); do
230+
pg=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-postgres 2>/dev/null || echo "not_found")
231+
redis=$(docker inspect --format '{{"{{"}}.State.Health.Status{{"}}"}}' buzz-redis 2>/dev/null || echo "not_found")
232+
if [[ "$pg" == "healthy" && "$redis" == "healthy" ]]; then
233+
echo " ready"
234+
ready=true
235+
break
236+
fi
237+
echo -n "."
238+
sleep 3
239+
done
240+
if [[ "$ready" != true ]]; then
241+
echo " timed out"
242+
exit 1
243+
fi
244+
fi
245+
want_opensearch=false
246+
if [[ -n "{{search}}" ]]; then
247+
want_opensearch=true
248+
else
249+
os_url="${BUZZ_OPENSEARCH_URL:-}"
250+
if [[ -z "$os_url" && -f .env ]]; then
251+
os_url="$(bash -c 'set -a; source .env >/dev/null 2>&1; printf "%s" "${BUZZ_OPENSEARCH_URL:-}"')"
252+
fi
253+
case "${os_url%/}" in
254+
http://localhost:9200|http://127.0.0.1:9200) want_opensearch=true ;;
255+
esac
256+
fi
257+
if [[ "$want_opensearch" == true ]]; then
258+
"{{justfile_directory()}}/bin/just" _ensure-opensearch
259+
fi
260+
212261
# Apply database migrations and seed the local dev community if the dev database is running
213262
_ensure-migrations: _ensure-services
214263
cargo run -p buzz-admin -- migrate
@@ -692,10 +741,36 @@ test-unit:
692741
test-integration:
693742
./scripts/run-tests.sh integration
694743

744+
# Run PostgreSQL-backed tests (auto-starts Docker services, including OpenSearch,
745+
# matching the CI PostgreSQL lane)
746+
[positional-arguments]
747+
test-postgres *ARGS: _ensure-services
748+
#!/usr/bin/env bash
749+
set -euo pipefail
750+
export PATH="{{justfile_directory()}}/bin:$PATH"
751+
export PGHOST="${PGHOST:-localhost}"
752+
export PGPORT="${PGPORT:-5432}"
753+
export PGUSER="${PGUSER:-buzz}"
754+
export PGPASSWORD="${PGPASSWORD:-buzz_dev}"
755+
export REDIS_URL="${REDIS_URL:-redis://localhost:6379}"
756+
export BUZZ_POSTGRES_ADMIN_URL="${BUZZ_POSTGRES_ADMIN_URL:-postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/postgres}"
757+
export BUZZ_TEST_OPENSEARCH_URL="${BUZZ_TEST_OPENSEARCH_URL:-http://localhost:9200}"
758+
case "${BUZZ_TEST_OPENSEARCH_URL%/}" in
759+
http://localhost:9200|http://127.0.0.1:9200)
760+
"{{justfile_directory()}}/bin/just" _ensure-opensearch
761+
;;
762+
esac
763+
./scripts/postgres-test-run.sh "$@"
764+
765+
# Run search integration tests (Postgres FTS + OpenSearch; auto-starts Postgres and OpenSearch)
766+
[positional-arguments]
767+
test-search *ARGS:
768+
"{{justfile_directory()}}/bin/just" test-postgres -p buzz-search --tests "$@"
769+
695770
# Enforce-mode upload/publication/read journey (requires PostgreSQL and Redis).
696771
# Uses the isolated PostgreSQL runner, including CLI edits and the target index.
697772
test-media-access:
698-
./scripts/postgres-test-run.sh -p buzz-relay -p buzz-db --lib -E 'test(/^api::media_access_postgres_tests::/) | test(effective_edit_uses_target_index) | test(historical_edit_preflight)'
773+
"{{justfile_directory()}}/bin/just" test-postgres -p buzz-relay -p buzz-db --lib -E 'test(/^api::media_access_postgres_tests::/) | test(effective_edit_uses_target_index) | test(historical_edit_preflight)'
699774

700775
# Regenerate the model-capability normative corpus from the production Rust
701776
# resolver. The corpus is a golden snapshot, never hand-edited: this runs the
@@ -772,9 +847,17 @@ relay: bootstrap _ensure-migrations
772847
#!/usr/bin/env bash
773848
set -euo pipefail
774849
export PATH="{{justfile_directory()}}/bin:$PATH"
850+
_caller_os_url="${BUZZ_OPENSEARCH_URL-}"
851+
_caller_os_preview="${BUZZ_OPENSEARCH_PREVIEW-}"
775852
set -o allexport
776853
source .env
777854
set +o allexport
855+
[[ -n "$_caller_os_url" ]] && export BUZZ_OPENSEARCH_URL="$_caller_os_url"
856+
[[ -n "$_caller_os_preview" ]] && export BUZZ_OPENSEARCH_PREVIEW="$_caller_os_preview"
857+
if [[ -n "{{search}}" ]]; then
858+
export BUZZ_OPENSEARCH_URL="${BUZZ_OPENSEARCH_URL:-http://localhost:9200}"
859+
export BUZZ_OPENSEARCH_PREVIEW="${BUZZ_OPENSEARCH_PREVIEW:-true}"
860+
fi
778861
cargo run -p buzz-relay
779862
780863
# Post one root + N replies (and a few reactions) to the local dev relay, for eyeballing long threads
@@ -786,9 +869,17 @@ relay-web: bootstrap _ensure-migrations
786869
#!/usr/bin/env bash
787870
set -euo pipefail
788871
export PATH="{{justfile_directory()}}/bin:$PATH"
872+
_caller_os_url="${BUZZ_OPENSEARCH_URL-}"
873+
_caller_os_preview="${BUZZ_OPENSEARCH_PREVIEW-}"
789874
set -o allexport
790875
source .env
791876
set +o allexport
877+
[[ -n "$_caller_os_url" ]] && export BUZZ_OPENSEARCH_URL="$_caller_os_url"
878+
[[ -n "$_caller_os_preview" ]] && export BUZZ_OPENSEARCH_PREVIEW="$_caller_os_preview"
879+
if [[ -n "{{search}}" ]]; then
880+
export BUZZ_OPENSEARCH_URL="${BUZZ_OPENSEARCH_URL:-http://localhost:9200}"
881+
export BUZZ_OPENSEARCH_PREVIEW="${BUZZ_OPENSEARCH_PREVIEW:-true}"
882+
fi
792883
[[ -d node_modules ]] || pnpm install
793884
pnpm -C web build
794885
BUZZ_WEB_DIR=./web/dist cargo run -p buzz-relay
@@ -841,9 +932,17 @@ admin-check: fmt-check
841932
relay-release: bootstrap _ensure-migrations
842933
#!/usr/bin/env bash
843934
set -euo pipefail
935+
_caller_os_url="${BUZZ_OPENSEARCH_URL-}"
936+
_caller_os_preview="${BUZZ_OPENSEARCH_PREVIEW-}"
844937
set -o allexport
845938
source .env
846939
set +o allexport
940+
[[ -n "$_caller_os_url" ]] && export BUZZ_OPENSEARCH_URL="$_caller_os_url"
941+
[[ -n "$_caller_os_preview" ]] && export BUZZ_OPENSEARCH_PREVIEW="$_caller_os_preview"
942+
if [[ -n "{{search}}" ]]; then
943+
export BUZZ_OPENSEARCH_URL="${BUZZ_OPENSEARCH_URL:-http://localhost:9200}"
944+
export BUZZ_OPENSEARCH_PREVIEW="${BUZZ_OPENSEARCH_PREVIEW:-true}"
945+
fi
847946
cargo run -p buzz-relay --release
848947
849948
@@ -852,9 +951,17 @@ dev *ARGS: bootstrap _ensure-sidecar-stubs _ensure-migrations
852951
#!/usr/bin/env bash
853952
set -euo pipefail
854953
export PATH="{{justfile_directory()}}/bin:$PATH"
954+
_caller_os_url="${BUZZ_OPENSEARCH_URL-}"
955+
_caller_os_preview="${BUZZ_OPENSEARCH_PREVIEW-}"
855956
set -o allexport
856957
source .env
857958
set +o allexport
959+
[[ -n "$_caller_os_url" ]] && export BUZZ_OPENSEARCH_URL="$_caller_os_url"
960+
[[ -n "$_caller_os_preview" ]] && export BUZZ_OPENSEARCH_PREVIEW="$_caller_os_preview"
961+
if [[ -n "{{search}}" ]]; then
962+
export BUZZ_OPENSEARCH_URL="${BUZZ_OPENSEARCH_URL:-http://localhost:9200}"
963+
export BUZZ_OPENSEARCH_PREVIEW="${BUZZ_OPENSEARCH_PREVIEW:-true}"
964+
fi
858965
bind_addr="${BUZZ_BIND_ADDR:-0.0.0.0:3000}"
859966
relay_port="${bind_addr##*:}"; [[ -n "$relay_port" ]] || relay_port=3000
860967
health_port="${BUZZ_HEALTH_PORT:-8080}"

‎TESTING.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
```bash
66
just test-unit # unit tests — no infrastructure needed
77
just test # unit + integration (starts Docker if needed)
8+
just test-search # Postgres FTS + OpenSearch tests (auto-starts Postgres & OpenSearch)
9+
just test-postgres # full PostgreSQL-backed lane (auto-starts Docker services)
810
```
911

1012
`just test` runs unit tests plus integration tests against Postgres and Redis
11-
(started automatically if not already running). Neither task runs the E2E suites in
12-
`buzz-test-client` — those are marked `#[ignore]` and require a running relay:
13+
(started automatically if not already running). `just test-search` and
14+
`just test-postgres` run the isolated per-test-database PostgreSQL lane
15+
(requiring `cargo-nextest` and `psql`/`createdb`/`dropdb`; on macOS,
16+
`brew install libpq` is detected automatically). Neither `just test-unit` nor
17+
`just test` runs the E2E suites in `buzz-test-client` — those are marked
18+
`#[ignore]` and require a running relay:
1319

1420
```bash
1521
# Start a relay first (see below), then:

‎crates/buzz-search/tests/postgres_opensearch_search.rs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//!
33
//! The shared [`search_suite`] cases run against OpenSearch, then sync tests
44
//! write through the database layer's normal paths and wait for the indexer.
5-
//! Needs Postgres (run through `scripts/postgres-test-run.sh -p buzz-search
6-
//! --tests`) and an OpenSearch cluster at `BUZZ_TEST_OPENSEARCH_URL`
7-
//! (default `http://localhost:9200`; `docker compose up -d opensearch`).
5+
//! Run locally with `just test-search`, or through `scripts/postgres-test-run.sh
6+
//! -p buzz-search --tests` with OpenSearch at `BUZZ_TEST_OPENSEARCH_URL`
7+
//! (default `http://localhost:9200`; `docker compose --profile search up -d opensearch`).
88
99
mod search_suite;
1010

@@ -91,15 +91,22 @@ async fn unsynced_db() -> Db {
9191

9292
/// A new index of the test's own, and its index-name prefix.
9393
async fn sync_index() -> (SearchIndex, String) {
94+
let url = opensearch_url();
9495
let prefix = format!("test-{}-", Uuid::new_v4().simple());
9596
let index = SearchIndex::new(&OpenSearchConfig {
96-
url: opensearch_url(),
97+
url: url.clone(),
9798
basic_auth: None,
9899
aws_sigv4: None,
99100
index_prefix: prefix.clone(),
100101
})
101102
.expect("OpenSearch client");
102-
index.ensure().await.expect("create index");
103+
index.ensure().await.unwrap_or_else(|err| {
104+
panic!(
105+
"create index on OpenSearch at {url}: {err}. \
106+
Is OpenSearch running? Run `just test-search` or \
107+
`docker compose --profile search up -d opensearch`."
108+
)
109+
});
103110
(index, prefix)
104111
}
105112

‎crates/buzz-search/tests/search_suite/mod.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,22 @@ impl Searcher<'_> {
144144

145145
/// A new, empty message index of the calling test's own on the test cluster.
146146
pub async fn test_index() -> SearchIndex {
147+
let url = std::env::var("BUZZ_TEST_OPENSEARCH_URL")
148+
.unwrap_or_else(|_| "http://localhost:9200".to_string());
147149
let index = SearchIndex::new(&OpenSearchConfig {
148-
url: std::env::var("BUZZ_TEST_OPENSEARCH_URL")
149-
.unwrap_or_else(|_| "http://localhost:9200".to_string()),
150+
url: url.clone(),
150151
basic_auth: None,
151152
aws_sigv4: None,
152153
index_prefix: format!("test-{}-", Uuid::new_v4().simple()),
153154
})
154155
.expect("OpenSearch client");
155-
index.ensure().await.expect("create test index");
156+
index.ensure().await.unwrap_or_else(|err| {
157+
panic!(
158+
"create test index on OpenSearch at {url}: {err}. \
159+
Is OpenSearch running? Run `just test-search` or \
160+
`docker compose --profile search up -d opensearch`."
161+
)
162+
});
156163
index
157164
}
158165

0 commit comments

Comments
 (0)