Skip to content

Commit fd5bb03

Browse files
committed
chore: simplify wait methods (pr comments)
1 parent a1c2b82 commit fd5bb03

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,20 @@ describeWithMongoDB(
118118
);
119119

120120
async function waitUntilSearchIsReady(provider: NodeDriverServiceProvider, abortSignal: AbortSignal): Promise<void> {
121-
let success = false;
122121
let lastError: unknown = null;
123122

124123
for (let i = 0; i < SEARCH_RETRIES && !abortSignal.aborted; i++) {
125124
try {
126125
await provider.insertOne("tmp", "test", { field1: "yay" });
127126
await provider.createSearchIndexes("tmp", "test", [{ definition: { mappings: { dynamic: true } } }]);
128-
success = true;
129-
break;
127+
return;
130128
} catch (err) {
131129
lastError = err;
132130
await sleep(100);
133131
}
134132
}
135133

136-
if (!success) {
137-
throw new Error(`Search Management Index is not ready.\nlastError: ${JSON.stringify(lastError)}`);
138-
}
134+
throw new Error(`Search Management Index is not ready.\nlastError: ${JSON.stringify(lastError)}`);
139135
}
140136

141137
async function waitUntilIndexIsQueryable(
@@ -145,7 +141,6 @@ async function waitUntilIndexIsQueryable(
145141
indexName: string,
146142
abortSignal: AbortSignal
147143
): Promise<void> {
148-
let success = false;
149144
let lastIndexStatus: unknown = null;
150145
let lastError: unknown = null;
151146

@@ -155,20 +150,17 @@ async function waitUntilIndexIsQueryable(
155150
lastIndexStatus = indexStatus;
156151

157152
if (indexStatus?.queryable === true) {
158-
success = true;
159-
break;
153+
return;
160154
}
161155
} catch (err) {
162156
lastError = err;
163157
await sleep(100);
164158
}
165159
}
166160

167-
if (!success) {
168-
throw new Error(
169-
`Index ${indexName} in ${database}.${collection} is not ready:
161+
throw new Error(
162+
`Index ${indexName} in ${database}.${collection} is not ready:
170163
lastIndexStatus: ${JSON.stringify(lastIndexStatus)}
171164
lastError: ${JSON.stringify(lastError)}`
172-
);
173-
}
165+
);
174166
}

0 commit comments

Comments
 (0)