Skip to content

Firestore: write_batch_test.cc: clean up assertion checks #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions firestore/integration_test_internal/src/write_batch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "firebase/firestore.h"
#include "firestore_integration_test.h"
#include "util/event_accumulator.h"
#include "util/future_test_util.h"
#if defined(__ANDROID__)
#include "firestore/src/android/write_batch_android.h"
#include "firestore/src/common/wrapper_assertions.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ TEST_F(WriteBatchTest, TestBatchesCommitAtomicallyRaisingCorrectEvents) {
EventAccumulator<QuerySnapshot> accumulator;
accumulator.listener()->AttachTo(&collection, MetadataChanges::kInclude);
QuerySnapshot initial_snapshot = accumulator.Await();
EXPECT_TRUE(0 == initial_snapshot.size());
EXPECT_EQ(initial_snapshot.size(), 0);

// Atomically write two documents.
Await(TestFirestore()
Expand Down Expand Up @@ -176,7 +177,7 @@ TEST_F(WriteBatchTest, TestBatchesFailAtomicallyRaisingCorrectEvents) {
EventAccumulator<QuerySnapshot> accumulator;
accumulator.listener()->AttachTo(&collection, MetadataChanges::kInclude);
QuerySnapshot initial_snapshot = accumulator.Await();
EXPECT_TRUE(0 == initial_snapshot.size());
EXPECT_EQ(initial_snapshot.size(), 0);

// Atomically write 1 document and update a nonexistent document.
Future<void> future =
Expand All @@ -186,8 +187,10 @@ TEST_F(WriteBatchTest, TestBatchesFailAtomicallyRaisingCorrectEvents) {
.Update(doc_b, MapFieldValue{{"b", FieldValue::Integer(2)}})
.Commit();
Await(future);
EXPECT_TRUE(FutureStatus::kFutureStatusComplete == future.status());
EXPECT_TRUE(Error::kErrorNotFound == future.error());
EXPECT_EQ(future.status(), FutureStatus::kFutureStatusComplete)
<< ToEnumeratorName(future.status());
EXPECT_EQ(future.error(), Error::kErrorNotFound)
<< ToFirestoreErrorCodeName(future.error());

// Local event with the set document.
QuerySnapshot local_snapshot = accumulator.Await();
Expand All @@ -199,7 +202,7 @@ TEST_F(WriteBatchTest, TestBatchesFailAtomicallyRaisingCorrectEvents) {
// Server event with the set reverted
QuerySnapshot server_snapshot = accumulator.Await();
EXPECT_FALSE(server_snapshot.metadata().has_pending_writes());
EXPECT_TRUE(0 == server_snapshot.size());
EXPECT_EQ(server_snapshot.size(), 0);
}

TEST_F(WriteBatchTest, TestWriteTheSameServerTimestampAcrossWrites) {
Expand All @@ -209,7 +212,7 @@ TEST_F(WriteBatchTest, TestWriteTheSameServerTimestampAcrossWrites) {
EventAccumulator<QuerySnapshot> accumulator;
accumulator.listener()->AttachTo(&collection, MetadataChanges::kInclude);
QuerySnapshot initial_snapshot = accumulator.Await();
EXPECT_TRUE(0 == initial_snapshot.size());
EXPECT_EQ(initial_snapshot.size(), 0);

// Atomically write two documents with server timestamps.
Await(TestFirestore()
Expand All @@ -227,9 +230,9 @@ TEST_F(WriteBatchTest, TestWriteTheSameServerTimestampAcrossWrites) {

QuerySnapshot server_snapshot = accumulator.AwaitRemoteEvent();
EXPECT_FALSE(server_snapshot.metadata().has_pending_writes());
EXPECT_TRUE(2 == server_snapshot.size());
ASSERT_EQ(server_snapshot.size(), 2);
const FieldValue when = server_snapshot.documents()[0].Get("when");
EXPECT_TRUE(FieldValue::Type::kTimestamp == when.type());
EXPECT_EQ(when.type(), FieldValue::Type::kTimestamp);
EXPECT_THAT(QuerySnapshotToValues(server_snapshot),
testing::ElementsAre(MapFieldValue{{"when", when}},
MapFieldValue{{"when", when}}));
Expand Down Expand Up @@ -261,7 +264,7 @@ TEST_F(WriteBatchTest, TestCanWriteTheSameDocumentMultipleTimes) {
DocumentSnapshot server_snapshot = accumulator.Await();
EXPECT_FALSE(server_snapshot.metadata().has_pending_writes());
const FieldValue when = server_snapshot.Get("when");
EXPECT_TRUE(FieldValue::Type::kTimestamp == when.type());
EXPECT_EQ(when.type(), FieldValue::Type::kTimestamp);
EXPECT_THAT(server_snapshot.GetData(),
testing::ContainerEq(MapFieldValue{{"a", FieldValue::Integer(1)},
{"b", FieldValue::Integer(2)},
Expand Down