Skip to content

Commit 98ad95d

Browse files
committed
add tests
1 parent f7a77de commit 98ad95d

File tree

5 files changed

+228
-65
lines changed

5 files changed

+228
-65
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@
748748
61D35E0DE04E70D3BC243A65 /* FIRGeoPointTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E048202154AA00B64F25 /* FIRGeoPointTests.mm */; };
749749
61ECC7CE18700CBD73D0D810 /* leveldb_migrations_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = EF83ACD5E1E9F25845A9ACED /* leveldb_migrations_test.cc */; };
750750
61F72C5620BC48FD001A68CB /* serializer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 61F72C5520BC48FD001A68CB /* serializer_test.cc */; };
751+
62180C272DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62180C262DF20F4B00B370CD /* SnapshotStreamListenerSourceTests.swift */; };
752+
62180C282DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62180C262DF20F4B00B370CD /* SnapshotStreamListenerSourceTests.swift */; };
753+
62180C292DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62180C262DF20F4B00B370CD /* SnapshotStreamListenerSourceTests.swift */; };
751754
621D620A28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621D620928F9CE7400D2FA26 /* QueryIntegrationTests.swift */; };
752755
621D620B28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621D620928F9CE7400D2FA26 /* QueryIntegrationTests.swift */; };
753756
621D620C28F9CE7400D2FA26 /* QueryIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621D620928F9CE7400D2FA26 /* QueryIntegrationTests.swift */; };
@@ -1777,7 +1780,7 @@
17771780
4334F87873015E3763954578 /* status_testing.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = status_testing.h; sourceTree = "<group>"; };
17781781
4375BDCDBCA9938C7F086730 /* Validation_BloomFilterTest_MD5_5000_1_bloom_filter_proto.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_5000_1_bloom_filter_proto.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_5000_1_bloom_filter_proto.json; sourceTree = "<group>"; };
17791782
444B7AB3F5A2929070CB1363 /* hard_assert_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = hard_assert_test.cc; sourceTree = "<group>"; };
1780-
4564AD9C55EC39C080EB9476 /* globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = globals_cache_test.cc; sourceTree = "<group>"; };
1783+
4564AD9C55EC39C080EB9476 /* globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = globals_cache_test.cc; sourceTree = "<group>"; };
17811784
478DC75A0DCA6249A616DD30 /* Validation_BloomFilterTest_MD5_500_0001_membership_test_result.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_500_0001_membership_test_result.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_500_0001_membership_test_result.json; sourceTree = "<group>"; };
17821785
48D0915834C3D234E5A875A9 /* grpc_stream_tester.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = grpc_stream_tester.h; sourceTree = "<group>"; };
17831786
4B3E4A77493524333133C5DC /* Validation_BloomFilterTest_MD5_50000_1_bloom_filter_proto.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_50000_1_bloom_filter_proto.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_50000_1_bloom_filter_proto.json; sourceTree = "<group>"; };
@@ -1895,7 +1898,7 @@
18951898
5B5414D28802BC76FDADABD6 /* stream_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = stream_test.cc; sourceTree = "<group>"; };
18961899
5B96CC29E9946508F022859C /* Validation_BloomFilterTest_MD5_50000_0001_membership_test_result.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_50000_0001_membership_test_result.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_50000_0001_membership_test_result.json; sourceTree = "<group>"; };
18971900
5C68EE4CB94C0DD6E333F546 /* Validation_BloomFilterTest_MD5_1_01_membership_test_result.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_1_01_membership_test_result.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_1_01_membership_test_result.json; sourceTree = "<group>"; };
1898-
5C6DEA63FBDE19D841291723 /* memory_globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = memory_globals_cache_test.cc; sourceTree = "<group>"; };
1901+
5C6DEA63FBDE19D841291723 /* memory_globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = memory_globals_cache_test.cc; sourceTree = "<group>"; };
18991902
5C7942B6244F4C416B11B86C /* leveldb_mutation_queue_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_mutation_queue_test.cc; sourceTree = "<group>"; };
19001903
5CAE131920FFFED600BE9A4A /* Firestore_Benchmarks_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_Benchmarks_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
19011904
5CAE131D20FFFED600BE9A4A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -1935,6 +1938,7 @@
19351938
618BBE9A20B89AAC00B5BCE7 /* status.pb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = status.pb.h; sourceTree = "<group>"; };
19361939
61F72C5520BC48FD001A68CB /* serializer_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = serializer_test.cc; sourceTree = "<group>"; };
19371940
620C1427763BA5D3CCFB5A1F /* BridgingHeader.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = "<group>"; };
1941+
62180C262DF20F4B00B370CD /* SnapshotStreamListenerSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotStreamListenerSourceTests.swift; sourceTree = "<group>"; };
19381942
621D620928F9CE7400D2FA26 /* QueryIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryIntegrationTests.swift; sourceTree = "<group>"; };
19391943
62E103B28B48A81D682A0DE9 /* Pods_Firestore_Example_tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example_tvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
19401944
62E54B832A9E910A003347C8 /* IndexingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexingTests.swift; sourceTree = "<group>"; };
@@ -1945,7 +1949,7 @@
19451949
69E6C311558EC77729A16CF1 /* Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
19461950
6A7A30A2DB3367E08939E789 /* bloom_filter.pb.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = bloom_filter.pb.h; sourceTree = "<group>"; };
19471951
6AE927CDFC7A72BF825BE4CB /* Pods-Firestore_Tests_tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests_tvOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests_tvOS/Pods-Firestore_Tests_tvOS.release.xcconfig"; sourceTree = "<group>"; };
1948-
6E42FA109D363EA7F3387AAE /* thread_safe_memoizer_testing.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = thread_safe_memoizer_testing.cc; sourceTree = "<group>"; };
1952+
6E42FA109D363EA7F3387AAE /* thread_safe_memoizer_testing.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = thread_safe_memoizer_testing.cc; sourceTree = "<group>"; };
19491953
6E8302DE210222ED003E1EA3 /* FSTFuzzTestFieldPath.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTFuzzTestFieldPath.h; sourceTree = "<group>"; };
19501954
6E8302DF21022309003E1EA3 /* FSTFuzzTestFieldPath.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTFuzzTestFieldPath.mm; sourceTree = "<group>"; };
19511955
6EA39FDD20FE820E008D461F /* FSTFuzzTestSerializer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTFuzzTestSerializer.mm; sourceTree = "<group>"; };
@@ -2123,7 +2127,7 @@
21232127
E42355285B9EF55ABD785792 /* Pods_Firestore_Example_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
21242128
E592181BFD7C53C305123739 /* Pods-Firestore_Tests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests_iOS/Pods-Firestore_Tests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
21252129
E76F0CDF28E5FA62D21DE648 /* leveldb_target_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_target_cache_test.cc; sourceTree = "<group>"; };
2126-
EA10515F99A42D71DA2D2841 /* thread_safe_memoizer_testing_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = thread_safe_memoizer_testing_test.cc; sourceTree = "<group>"; };
2130+
EA10515F99A42D71DA2D2841 /* thread_safe_memoizer_testing_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = thread_safe_memoizer_testing_test.cc; sourceTree = "<group>"; };
21272131
ECEBABC7E7B693BE808A1052 /* Pods_Firestore_IntegrationTests_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
21282132
EF3A65472C66B9560041EE69 /* FIRVectorValueTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRVectorValueTests.mm; sourceTree = "<group>"; };
21292133
EF6C285029E462A200A7D4F1 /* FIRAggregateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRAggregateTests.mm; sourceTree = "<group>"; };
@@ -2141,7 +2145,7 @@
21412145
F848C41C03A25C42AD5A4BC2 /* target_cache_test.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = target_cache_test.h; sourceTree = "<group>"; };
21422146
F869D85E900E5AF6CD02E2FC /* firebase_auth_credentials_provider_test.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; name = firebase_auth_credentials_provider_test.mm; path = credentials/firebase_auth_credentials_provider_test.mm; sourceTree = "<group>"; };
21432147
FA2E9952BA2B299C1156C43C /* Pods-Firestore_Benchmarks_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Benchmarks_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Benchmarks_iOS/Pods-Firestore_Benchmarks_iOS.debug.xcconfig"; sourceTree = "<group>"; };
2144-
FC44D934D4A52C790659C8D6 /* leveldb_globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = leveldb_globals_cache_test.cc; sourceTree = "<group>"; };
2148+
FC44D934D4A52C790659C8D6 /* leveldb_globals_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_globals_cache_test.cc; sourceTree = "<group>"; };
21452149
FC738525340E594EBFAB121E /* Pods-Firestore_Example_tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_tvOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_tvOS/Pods-Firestore_Example_tvOS.release.xcconfig"; sourceTree = "<group>"; };
21462150
FF73B39D04D1760190E6B84A /* FIRQueryUnitTests.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRQueryUnitTests.mm; sourceTree = "<group>"; };
21472151
FFCA39825D9678A03D1845D0 /* document_overlay_cache_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = document_overlay_cache_test.cc; sourceTree = "<group>"; };
@@ -2267,6 +2271,7 @@
22672271
124C932A22C1635300CA8C2D /* Integration */ = {
22682272
isa = PBXGroup;
22692273
children = (
2274+
62180C262DF20F4B00B370CD /* SnapshotStreamListenerSourceTests.swift */,
22702275
EF6C286C29E6D22200A7D4F1 /* AggregationIntegrationTests.swift */,
22712276
062072B62773A055001655D7 /* AsyncAwaitIntegrationTests.swift */,
22722277
124C932B22C1642C00CA8C2D /* CodableIntegrationTests.swift */,
@@ -4655,6 +4660,7 @@
46554660
4D42E5C756229C08560DD731 /* XCTestCase+Await.mm in Sources */,
46564661
09BE8C01EC33D1FD82262D5D /* aggregate_query_test.cc in Sources */,
46574662
0EC3921AE220410F7394729B /* aggregation_result.pb.cc in Sources */,
4663+
62180C272DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */,
46584664
276A563D546698B6AAC20164 /* annotations.pb.cc in Sources */,
46594665
7B8D7BAC1A075DB773230505 /* app_testing.mm in Sources */,
46604666
DC1C711290E12F8EF3601151 /* array_sorted_map_test.cc in Sources */,
@@ -4902,6 +4908,7 @@
49024908
736C4E82689F1CA1859C4A3F /* XCTestCase+Await.mm in Sources */,
49034909
412BE974741729A6683C386F /* aggregate_query_test.cc in Sources */,
49044910
DF983A9C1FBF758AF3AF110D /* aggregation_result.pb.cc in Sources */,
4911+
62180C292DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */,
49054912
EA46611779C3EEF12822508C /* annotations.pb.cc in Sources */,
49064913
8F4F40E9BC7ED588F67734D5 /* app_testing.mm in Sources */,
49074914
A6E236CE8B3A47BE32254436 /* array_sorted_map_test.cc in Sources */,
@@ -5401,6 +5408,7 @@
54015408
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */,
54025409
B04E4FE20930384DF3A402F9 /* aggregate_query_test.cc in Sources */,
54035410
1A3D8028303B45FCBB21CAD3 /* aggregation_result.pb.cc in Sources */,
5411+
62180C282DF20F6500B370CD /* SnapshotStreamListenerSourceTests.swift in Sources */,
54045412
02EB33CC2590E1484D462912 /* annotations.pb.cc in Sources */,
54055413
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */,
54065414
FCA48FB54FC50BFDFDA672CD /* array_sorted_map_test.cc in Sources */,

Firestore/Swift/Source/AsyncAwait/Query+AsyncAwait.swift renamed to Firestore/Swift/Source/AsyncAwait/Query+AsyncThrowingStream.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,8 @@ import Foundation
2323

2424
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
2525
public extension Query {
26-
func asyncThrowingStream() -> AsyncThrowingStream<QuerySnapshot, Error> {
27-
AsyncThrowingStream { continuation in
28-
let listener = self.addSnapshotListener { snapshot, error in
29-
if let snapshot = snapshot {
30-
continuation.yield(snapshot)
31-
} else if let error = error {
32-
continuation.finish(throwing: error)
33-
}
34-
}
35-
36-
continuation.onTermination = { _ in
37-
listener.remove()
38-
}
39-
}
40-
}
41-
42-
func asyncThrowingStream(options: SnapshotListenOptions) -> AsyncThrowingStream<QuerySnapshot, Error> {
26+
func snapshotStream(options: SnapshotListenOptions = SnapshotListenOptions())
27+
-> AsyncThrowingStream<QuerySnapshot, Error> {
4328
AsyncThrowingStream { continuation in
4429
let listener = self.addSnapshotListener(options: options) { snapshot, error in
4530
if let snapshot = snapshot {

Firestore/Swift/Tests/Integration/AsyncAwaitIntegrationTests.swift

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -155,48 +155,5 @@ let emptyBundle = """
155155
}
156156
XCTAssertThrowsError(try deleteAllIndexes(), "The client has already been terminated.")
157157
}
158-
159-
func testCanListenToDefaultSourceFirstAndThenCacheAsyncStream() async throws {
160-
let collRef = collectionRef(withDocuments: [
161-
"a": ["k": "a", "sort": 0],
162-
"b": ["k": "b", "sort": 1],
163-
])
164-
165-
let query = collRef.whereField("sort", isGreaterThanOrEqualTo: 1).order(by: "sort")
166-
167-
// 1. Create a signal stream. The test will wait on this stream.
168-
// The Task will write to it after receiving the first snapshot.
169-
let (signalStream, signalContinuation) = AsyncStream.makeStream(of: Void.self)
170-
171-
let stream = query.asyncThrowingStream()
172-
var iterator = stream.makeAsyncIterator()
173-
174-
let task = Task {
175-
// This task will now run and eventually signal its progress.
176-
let firstSnapshot = try await iterator.next()
177-
178-
// Assertions for the first snapshot
179-
XCTAssertNotNil(firstSnapshot, "Expected an initial snapshot.")
180-
try assertQuerySnapshotDataEquals(firstSnapshot!, [["k": "b", "sort": 1]])
181-
XCTAssertEqual(firstSnapshot!.metadata.isFromCache, false)
182-
183-
// 2. Send the signal to the test function now that we have the first snapshot.
184-
signalContinuation.yield(())
185-
signalContinuation.finish() // We only need to signal once.
186-
187-
// This next await will be suspended until it's cancelled.
188-
let second = try await iterator.next()
189-
190-
// After cancellation, the iterator should terminate and return nil.
191-
XCTAssertNil(second, "iterator.next() should have returned nil after cancellation.")
192-
}
193-
194-
// 3. Instead of sleeping, await the signal from the Task.
195-
// This line will pause execution until `signalContinuation.yield()` is called.
196-
await signalStream.first { _ in true }
197-
198-
// 4. As soon as we receive the signal, we know it's safe to cancel.
199-
task.cancel()
200-
}
201158
}
202159
#endif

Firestore/Swift/Tests/Integration/SnapshotListenerSourceTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class SnapshotListenerSourceTests: FSTIntegrationTestCase {
2222
func assertQuerySnapshotDataEquals(_ snapshot: Any,
2323
_ expectedData: [[String: Any]]) throws {
2424
let extractedData = FIRQuerySnapshotGetData(snapshot as! QuerySnapshot)
25+
print("extractedData.count: \(extractedData.count) ")
26+
print("expectedData.count: \(expectedData.count) ")
2527
guard extractedData.count == expectedData.count else {
2628
XCTFail(
2729
"Result count mismatch: Expected \(expectedData.count), got \(extractedData.count)"

0 commit comments

Comments
 (0)