Skip to content

Commit c3ac780

Browse files
authored
Fix error in default RC Fetch timeout, and add test for Fetch(0). (#851)
* Add test for Fetch(0) to TestFetchInterval. * Change Fetch() to use correct default 12 hours, instead of 1200 hours. * Add release note for fix.
1 parent a64bec8 commit c3ac780

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ code.
571571
- Changes
572572
- General (iOS): Fixed additional issues on iOS 15 caused by early
573573
initialization of Firebase iOS SDK.
574+
- Remote Config: Fixed default `Fetch()` timeout being 1000 times too
575+
high.
574576

575577
### 8.9.0
576578
- Changes

remote_config/integration_test/src/integration_test.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,44 @@ TEST_F(FirebaseRemoteConfigTest, TestFetchInterval) {
366366
EXPECT_NE(current_fetch_time, rc_->GetInfo().fetch_time);
367367
}
368368

369+
TEST_F(FirebaseRemoteConfigTest, TestFetchSecondsParameter) {
370+
ASSERT_NE(rc_, nullptr);
371+
372+
EXPECT_TRUE(
373+
WaitForCompletion(RunWithRetry([&]() { return rc_->FetchAndActivate(); }),
374+
"FetchAndActivate"));
375+
uint64_t current_fetch_time = rc_->GetInfo().fetch_time;
376+
// Making sure the config settings's fetch interval is 12 hours
377+
EXPECT_TRUE(WaitForCompletion(SetDefaultConfigSettings(rc_),
378+
"SetDefaultConfigSettings"));
379+
// Test Fetch() without specifying an interval; it should not fetch.
380+
EXPECT_TRUE(WaitForCompletion(RunWithRetry([&]() { return rc_->Fetch(); }),
381+
"Fetch() [should not fetch]"));
382+
EXPECT_EQ(current_fetch_time, rc_->GetInfo().fetch_time);
383+
384+
FLAKY_TEST_SECTION_BEGIN();
385+
386+
// Call Fetch(0), forcing a fetch.
387+
EXPECT_TRUE(WaitForCompletion(RunWithRetry([&]() { return rc_->Fetch(0); }),
388+
"Fetch(0) [should fetch]"));
389+
EXPECT_NE(current_fetch_time, rc_->GetInfo().fetch_time);
390+
391+
current_fetch_time = rc_->GetInfo().fetch_time;
392+
// Call Fetch(30), which shouldn't fetch yet.
393+
EXPECT_TRUE(WaitForCompletion(RunWithRetry([&]() { return rc_->Fetch(30); }),
394+
"Fetch(30) [should not fetch]"));
395+
EXPECT_EQ(current_fetch_time, rc_->GetInfo().fetch_time);
396+
397+
LogDebug("Pausing 45 seconds before re-running Fetch");
398+
for (int i = 0; i < 45; i++) {
399+
ProcessEvents(1000);
400+
}
401+
// After waiting 45 seconds, Fetch(30) should now fetch.
402+
EXPECT_TRUE(WaitForCompletion(RunWithRetry([&]() { return rc_->Fetch(30); }),
403+
"Fetch(30) [should fetch]"));
404+
EXPECT_NE(current_fetch_time, rc_->GetInfo().fetch_time);
405+
406+
FLAKY_TEST_SECTION_END();
407+
}
408+
369409
} // namespace firebase_testapp_automated

remote_config/src/remote_config.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "app/src/cleanup_notifier.h"
2020
#include "app/src/include/firebase/internal/mutex.h"
2121
#include "app/src/semaphore.h"
22+
#include "app/src/time.h"
2223
#include "include/firebase/remote_config.h"
2324
#include "remote_config/src/common.h"
2425

@@ -132,7 +133,8 @@ Future<bool> RemoteConfig::FetchAndActivateLastResult() {
132133
}
133134

134135
Future<void> RemoteConfig::Fetch() {
135-
return Fetch(GetConfigSettings().minimum_fetch_interval_in_milliseconds);
136+
return Fetch(GetConfigSettings().minimum_fetch_interval_in_milliseconds /
137+
firebase::internal::kMillisecondsPerSecond);
136138
}
137139

138140
Future<void> RemoteConfig::Fetch(uint64_t cache_expiration_in_seconds) {

0 commit comments

Comments
 (0)