Skip to content

Commit 0fd263a

Browse files
committed
chore: keep last error in case of failure waiting for search indexes
1 parent c736af7 commit 0fd263a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/integration/tools/mongodb/search/listSearchIndexes.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,22 @@ describeWithMongoDB(
106106
const SEARCH_RETRIES = 10_000;
107107
async function waitUntilSearchIsReady(provider: NodeDriverServiceProvider, abortSignal: AbortSignal): Promise<void> {
108108
let success = true;
109+
let lastError: unknown = false;
110+
109111
for (let i = 0; i < SEARCH_RETRIES && !abortSignal.aborted; i++) {
110112
try {
111113
await provider.insertOne("tmp", "test", { field1: "yay" });
112114
await provider.createSearchIndexes("tmp", "test", [{ definition: { mappings: { dynamic: true } } }]);
113115
success = true;
114116
break;
115117
} catch (err) {
116-
void err;
118+
lastError = err;
117119
await sleep(100);
118120
}
119121
}
120122

121123
if (!success) {
122-
throw new Error("Search Management Index is not ready.");
124+
throw new Error(`Search Management Index is not ready.\nlastError: ${lastError}`);
123125
}
124126
}
125127

@@ -131,20 +133,27 @@ async function waitUntilIndexIsQueryable(
131133
abortSignal: AbortSignal
132134
): Promise<void> {
133135
let success = false;
136+
let lastIndexStatus: unknown = false;
137+
let lastError: unknown = false;
138+
134139
for (let i = 0; i < SEARCH_RETRIES && !abortSignal.aborted; i++) {
135140
try {
136141
const [indexStatus] = await provider.getSearchIndexes(database, collection, indexName);
142+
lastIndexStatus = indexStatus;
143+
137144
if (indexStatus?.queryable === true) {
138145
success = true;
139146
break;
140147
}
141148
} catch (err) {
142-
void err;
149+
lastError = err;
143150
await sleep(100);
144151
}
145152
}
146153

147154
if (!success) {
148-
throw new Error(`Index ${indexName} in ${database}.${collection} is not ready.`);
155+
throw new Error(
156+
`Index ${indexName} in ${database}.${collection} is not ready: \nlastIndexStatus: ${lastIndexStatus}\nlastError: ${lastError}`
157+
);
149158
}
150159
}

0 commit comments

Comments
 (0)