Skip to content

Commit 89d23ac

Browse files
test: fix remote config logic
1 parent 165bf39 commit 89d23ac

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tests/globals.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,20 @@ global.FirebaseHelpers = {
187187
let retries = 0;
188188
let maxRetries = 5;
189189
// We handle 429 errors in a retry loop
190-
while ((doc === undefined || doc.status === 429) && retries < maxRetries) {
191-
doc = await fetch(
192-
`https://us-central1-${getE2eTestProject()}.cloudfunctions.net/${functioNName}`,
193-
{
194-
method: 'POST',
195-
body: JSON.stringify({ data: postData }),
196-
headers: { 'Content-Type': 'application/json' },
197-
},
198-
);
199-
if (doc.status === 429) {
190+
while ((doc === undefined || (doc && doc.status === 429)) && retries < maxRetries) {
191+
try {
192+
doc = await fetch(
193+
`https://us-central1-${getE2eTestProject()}.cloudfunctions.net/${functioNName}`,
194+
{
195+
method: 'POST',
196+
body: JSON.stringify({ data: postData }),
197+
headers: { 'Content-Type': 'application/json' },
198+
},
199+
);
200+
} catch (_error) {
201+
doc = undefined;
202+
}
203+
if (doc && doc.status === 429) {
200204
// We have been delayed by concurrency limits or rate limits
201205
// We'll sleep for a little bit then try again.
202206
const delayRequired = 10;
@@ -206,7 +210,7 @@ global.FirebaseHelpers = {
206210
}
207211

208212
// did we eventually have success? If not, error.
209-
if (retries === maxRetries && doc.status !== 200) {
213+
if (!doc || doc.status !== 200) {
210214
throw new Error('Unable to execute cloud remote config helper function');
211215
}
212216
const result = await doc.json();

0 commit comments

Comments
 (0)