Skip to content

Commit 1c76fd3

Browse files
authored
Switch to a more generic method to get a server timestamp for mobile tests. (#1528)
* Add a method to get a server timestamp on mobile. * Change tests to use new server time method. * Add desktop source file missing from some tests. * Fix 64-bit integers on Windows. * Add offset to Windows time calculation. * Add missing source file for tvOS Auth tests.
1 parent 56dc7fb commit 1c76fd3

File tree

17 files changed

+99
-58
lines changed

17 files changed

+99
-58
lines changed

analytics/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

app/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

app_check/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

auth/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

auth/integration_test/integration_test.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
D62CCBC022F367140099BE9F /* gmock-all.cc in Sources */ = {isa = PBXBuildFile; fileRef = D62CCBBF22F367140099BE9F /* gmock-all.cc */; };
2929
D66B16871CE46E8900E5638A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D66B16861CE46E8900E5638A /* LaunchScreen.storyboard */; };
3030
D67D355822BABD2200292C1D /* gtest-all.cc in Sources */ = {isa = PBXBuildFile; fileRef = D67D355622BABD2100292C1D /* gtest-all.cc */; };
31+
D6A908EC2B786EDF00EF5160 /* ios_firebase_test_framework.mm in Sources */ = {isa = PBXBuildFile; fileRef = D6C179E822CB322900C2651A /* ios_firebase_test_framework.mm */; };
3132
D6C179E922CB322900C2651A /* ios_app_framework.mm in Sources */ = {isa = PBXBuildFile; fileRef = D6C179E722CB322900C2651A /* ios_app_framework.mm */; };
3233
D6C179EA22CB322900C2651A /* ios_firebase_test_framework.mm in Sources */ = {isa = PBXBuildFile; fileRef = D6C179E822CB322900C2651A /* ios_firebase_test_framework.mm */; };
3334
D6C179EE22CB323300C2651A /* firebase_test_framework.cc in Sources */ = {isa = PBXBuildFile; fileRef = D6C179EC22CB323300C2651A /* firebase_test_framework.cc */; };
@@ -368,6 +369,7 @@
368369
9F3A09032669792100E1D69F /* app_framework.cc in Sources */,
369370
9F3A09022669791E00E1D69F /* gtest-all.cc in Sources */,
370371
9F3A09042669792400E1D69F /* firebase_test_framework.cc in Sources */,
372+
D6A908EC2B786EDF00EF5160 /* ios_firebase_test_framework.mm in Sources */,
371373
9F5DD0AC266A7AD30058C144 /* integration_test.cc in Sources */,
372374
9F5DD0AB266A7ACE0058C144 /* ios_app_framework.mm in Sources */,
373375
);

database/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

database/integration_test/src/integration_test.cc

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ class FirebaseDatabaseTest : public FirebaseTest {
147147
// Shut down Firebase Database.
148148
void TerminateDatabase();
149149

150-
int64_t GetRemoteTimeInMilliseconds();
151-
152150
firebase::database::DatabaseReference CreateWorkingPath(
153151
bool suppress_cleanup = false);
154152

@@ -368,30 +366,6 @@ firebase::database::DatabaseReference FirebaseDatabaseTest::CreateWorkingPath(
368366
return ref;
369367
}
370368

371-
int64_t FirebaseDatabaseTest::GetRemoteTimeInMilliseconds() {
372-
firebase::database::DatabaseReference ref =
373-
CreateWorkingPath().Child("timestamp");
374-
WaitForCompletionAnyResult(
375-
ref.SetValue(firebase::database::ServerTimestamp()),
376-
"GetRemoteTime_SetValue");
377-
firebase::Future<firebase::database::DataSnapshot> future = ref.GetValue();
378-
WaitForCompletionAnyResult(future, "GetRemoteTime_GetValue");
379-
int64_t timestamp = 0;
380-
if (future.error() == 0 && future.result() &&
381-
future.result()->value().is_int64()) {
382-
timestamp = future.result()->value().int64_value();
383-
}
384-
if (timestamp > 0) {
385-
LogDebug("Got server timestamp: %lld", timestamp);
386-
LogDebug(" Local timestamp: %lld",
387-
app_framework::GetCurrentTimeInMicroseconds() / 1000L);
388-
return timestamp;
389-
} else {
390-
LogWarning("Couldn't get remote timestamp, using local time");
391-
return app_framework::GetCurrentTimeInMicroseconds() / 1000L;
392-
}
393-
}
394-
395369
// Test cases below.
396370
TEST_F(FirebaseDatabaseTest, TestInitializeAndTerminate) {
397371
// Already tested via SetUp() and TearDown().
@@ -487,7 +461,11 @@ TEST_F(FirebaseDatabaseTest, TestSetAndGetSimpleValues) {
487461
WaitForCompletion(f7, "GetLongDouble");
488462

489463
// Get the current time to compare to the Timestamp.
490-
int64_t current_time_milliseconds = GetRemoteTimeInMilliseconds();
464+
int64_t current_time_milliseconds =
465+
GetCurrentTimeInSecondsSinceEpoch() * 1000LL;
466+
LogDebug("Comparing current time %" PRId64 " with timestamp %" PRId64,
467+
current_time_milliseconds,
468+
f5.result()->value().AsInt64().int64_value());
491469

492470
EXPECT_EQ(f1.result()->value().AsString(), kSimpleString);
493471
EXPECT_EQ(f2.result()->value().AsInt64(), kSimpleInt);
@@ -698,8 +676,12 @@ TEST_F(FirebaseDatabaseTest, TestUpdateChildren) {
698676
WaitForCompletion(update_future, "UpdateChildren");
699677
read_future = ref.Child(test_name).GetValue();
700678
WaitForCompletion(read_future, "GetValue 2");
701-
int64_t current_time_milliseconds = GetRemoteTimeInMilliseconds();
702-
679+
int64_t current_time_milliseconds =
680+
GetCurrentTimeInSecondsSinceEpoch() * 1000L;
681+
LogDebug(
682+
"Comparing current time %" PRId64 " with timestamp %" PRId64,
683+
current_time_milliseconds,
684+
read_future.result()->value().map()["timestamp"].AsInt64().int64_value());
703685
EXPECT_THAT(
704686
read_future.result()->value().map(),
705687
UnorderedElementsAre(

firestore/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

firestore/integration_test_internal/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ else()
345345
# Platform abstraction layer for the desktop integration test.
346346
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
347347
src/desktop/desktop_app_framework.cc
348+
src/desktop/desktop_firebase_test_framework.cc
348349
)
349350

350351
set(integration_test_target_name "integration_test")

functions/integration_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ else()
189189
# Platform abstraction layer for the desktop integration test.
190190
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
191191
src/desktop/desktop_app_framework.cc
192+
src/desktop/desktop_firebase_test_framework.cc
192193
)
193194

194195
set(integration_test_target_name "integration_test")

0 commit comments

Comments
 (0)