From e8a0e48d3bdd662a8c9bd147816ad4ed6b0b051e Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent Date: Mon, 20 Nov 2017 11:23:53 -0800 Subject: [PATCH] Added blocking with Firebase sample to prevent race conditions during tests. --- .../com/example/firestore/snippets/ManageDataSnippets.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firestore/src/main/java/com/example/firestore/snippets/ManageDataSnippets.java b/firestore/src/main/java/com/example/firestore/snippets/ManageDataSnippets.java index 30427e705c9..a2493d7352a 100644 --- a/firestore/src/main/java/com/example/firestore/snippets/ManageDataSnippets.java +++ b/firestore/src/main/java/com/example/firestore/snippets/ManageDataSnippets.java @@ -345,7 +345,8 @@ public Void updateCallback(Transaction transaction) throws Exception { String returnInfoFromTransaction(long population) throws Exception { Map map = new HashMap<>(); map.put("population", population); - db.collection("cities").document("SF").set(map); + // Block until transaction is complete is using transaction.get() + db.collection("cities").document("SF").set(map).get(); // [START fs_return_info_transaction] final DocumentReference docRef = db.collection("cities").document("SF"); ApiFuture transaction =