Skip to content

Commit 073c067

Browse files
Adding queryWithMicrosecondPrecision test
1 parent b7cee60 commit 073c067

File tree

1 file changed

+18
-1
lines changed
  • google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it

1 file changed

+18
-1
lines changed

google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void serverTimestamp() throws Exception {
201201
}
202202

203203
@Test
204-
public void updateMicrosecondTimestamp() throws Exception {
204+
public void timestamptDoesntGetTruncatedDuringUpdate() throws Exception {
205205
DocumentReference documentReference = addDocument("time", Timestamp.ofTimeSecondsAndNanos(0, 123000));
206206
DocumentSnapshot documentSnapshot = documentReference.get().get();
207207

@@ -265,6 +265,23 @@ public void noResults() throws Exception {
265265
assertNotNull(querySnapshot.getReadTime());
266266
}
267267

268+
@Test
269+
public void queryWithMicrosecondPrecision() throws Exception {
270+
Timestamp microsecondTimestamp = Timestamp.ofTimeSecondsAndNanos(0, 123000);
271+
272+
DocumentReference documentReference = addDocument("time", microsecondTimestamp);
273+
DocumentSnapshot documentSnapshot = documentReference.get().get();
274+
275+
Query query = randomColl.whereEqualTo("time", microsecondTimestamp);
276+
QuerySnapshot querySnapshot = query.get().get();
277+
assertEquals(1, querySnapshot.size());
278+
279+
// Using `.toDate()` truncates to millseconds, and hence the query doesn't match.
280+
query = randomColl.whereEqualTo("time", microsecondTimestamp.toDate());
281+
querySnapshot = query.get().get();
282+
assertEquals(0, querySnapshot.size());
283+
}
284+
268285
@Test
269286
public void nestedQuery() throws Exception {
270287
randomColl = randomColl.document("foo").collection("bar");

0 commit comments

Comments
 (0)