@@ -157,11 +157,11 @@ func (s MongoClickhouseSuite) Test_Simple_Flow_Partitioned() {
157157 RequireEnvCanceled (t , env )
158158}
159159
160- func (s MongoClickhouseSuite ) Test_Snapshot_Partition_Capped_To_Timestamp_Range () {
160+ func (s MongoClickhouseSuite ) Test_Snapshot_Empty_Collection () {
161161 t := s .T ()
162162 srcDatabase := GetTestDatabase (s .Suffix ())
163- srcTable := "test_partition_cap "
164- dstTable := "test_partition_cap_dst "
163+ srcTable := "test_empty_collection "
164+ dstTable := "test_empty_collection_dst "
165165
166166 connectionGen := FlowConnectionGenerationConfig {
167167 FlowJobName : AddSuffix (s , srcTable ),
@@ -170,49 +170,33 @@ func (s MongoClickhouseSuite) Test_Snapshot_Partition_Capped_To_Timestamp_Range(
170170 }
171171 flowConnConfig := s .generateFlowConnectionConfigsDefaultEnv (connectionGen )
172172 flowConnConfig .DoInitialSnapshot = true
173- // 1 row per partition would normally request 100 partitions for 100 docs,
174- // but the 5-second timestamp range should cap it to 5 partitions.
175173 flowConnConfig .SnapshotNumRowsPerPartition = 1
176174 flowConnConfig .Env ["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING" ] = "true"
177175
178176 adminClient := s .Source ().(* MongoSource ).AdminClient ()
179- collection := adminClient .Database (srcDatabase ).Collection (srcTable )
180-
181- baseTime := time .Date (2026 , 3 , 1 , 0 , 0 , 0 , 0 , time .UTC )
182- docs := make ([]any , 100 )
183- for i := range 100 {
184- // insert 100 docs spread across 5 seconds (20 docs per second)
185- oid := bson .NewObjectIDFromTimestamp (baseTime .Add (time .Duration (i / 20 ) * time .Second ))
186- docs [i ] = bson.D {
187- {Key : "_id" , Value : oid },
188- {Key : "key" , Value : fmt .Sprintf ("value_%d" , i )},
189- }
190- }
191- _ , err := collection .InsertMany (t .Context (), docs )
177+ err := adminClient .Database (srcDatabase ).CreateCollection (t .Context (), srcTable )
192178 require .NoError (t , err )
193179
194180 tc := NewTemporalClient (t )
195181 env := ExecutePeerflow (t , tc , flowConnConfig )
182+ SetupCDCFlowStatusQuery (t , env , flowConnConfig )
196183
197- EnvWaitForEqualTablesWithNames ( env , s , "initial load to match" , srcTable , dstTable , "_id,doc" )
198-
199- catalogPool , err := internal . GetCatalogConnectionPoolFromEnv (t .Context ())
184+ // insert after snapshot to verify CDC still works
185+ collection := adminClient . Database ( srcDatabase ). Collection ( srcTable )
186+ insertRes , err := collection . InsertOne (t .Context (), bson. D {bson. E { Key : "key" , Value : "val" }}, options . InsertOne ())
200187 require .NoError (t , err )
201- var partitionCount int
202- require .NoError (t , catalogPool .QueryRow (t .Context (),
203- `SELECT COUNT(*) FROM peerdb_stats.qrep_partitions WHERE parent_mirror_name = $1` ,
204- flowConnConfig .FlowJobName ).Scan (& partitionCount ))
205- require .Equal (t , 5 , partitionCount )
188+ require .True (t , insertRes .Acknowledged )
189+ EnvWaitForEqualTablesWithNames (env , s , "cdc after empty snapshot" , srcTable , dstTable , "_id,doc" )
206190
207191 env .Cancel (t .Context ())
208192 RequireEnvCanceled (t , env )
209193}
210194
211- func (s MongoClickhouseSuite ) Test_Snapshot_Empty_Collection () {
195+ func (s MongoClickhouseSuite ) Test_Snapshot_Collection_With_Single_Document () {
212196 t := s .T ()
213197 srcDatabase := GetTestDatabase (s .Suffix ())
214- srcTable := "test_empty_collection "
215- dstTable := "test_empty_collection_dst "
198+ srcTable := "test_single_doc_snapshot "
199+ dstTable := "test_single_doc_snapshot_dst "
216200
217201 connectionGen := FlowConnectionGenerationConfig {
218202 FlowJobName : AddSuffix (s , srcTable ),
@@ -225,19 +209,31 @@ func (s MongoClickhouseSuite) Test_Snapshot_Empty_Collection() {
225209 flowConnConfig .Env ["PEERDB_MONGODB_PARALLEL_SNAPSHOTTING" ] = "true"
226210
227211 adminClient := s .Source ().(* MongoSource ).AdminClient ()
228- err := adminClient .Database (srcDatabase ).CreateCollection (t .Context (), srcTable )
212+ collection := adminClient .Database (srcDatabase ).Collection (srcTable )
213+
214+ _ , err := collection .InsertOne (t .Context (), bson.D {{Key : "key" , Value : "value" }})
229215 require .NoError (t , err )
230216
231217 tc := NewTemporalClient (t )
232218 env := ExecutePeerflow (t , tc , flowConnConfig )
219+
220+ EnvWaitForEqualTablesWithNames (env , s , "initial load" , srcTable , dstTable , "_id,doc" )
221+
222+ catalogPool , err := internal .GetCatalogConnectionPoolFromEnv (t .Context ())
223+ require .NoError (t , err )
224+ var partitionCount int
225+ require .NoError (t , catalogPool .QueryRow (t .Context (),
226+ `SELECT COUNT(*) FROM peerdb_stats.qrep_partitions WHERE parent_mirror_name = $1` ,
227+ flowConnConfig .FlowJobName ).Scan (& partitionCount ))
228+ require .Equal (t , 1 , partitionCount )
229+
233230 SetupCDCFlowStatusQuery (t , env , flowConnConfig )
234231
235232 // insert after snapshot to verify CDC still works
236- collection := adminClient .Database (srcDatabase ).Collection (srcTable )
237- insertRes , err := collection .InsertOne (t .Context (), bson.D {bson.E {Key : "key" , Value : "val" }}, options .InsertOne ())
233+ insertRes , err := collection .InsertOne (t .Context (), bson.D {{Key : "cdc_key" , Value : "cdc_value" }})
238234 require .NoError (t , err )
239235 require .True (t , insertRes .Acknowledged )
240- EnvWaitForEqualTablesWithNames (env , s , "cdc after empty snapshot" , srcTable , dstTable , "_id,doc" )
236+ EnvWaitForEqualTablesWithNames (env , s , "cdc after single doc snapshot" , srcTable , dstTable , "_id,doc" )
241237
242238 env .Cancel (t .Context ())
243239 RequireEnvCanceled (t , env )
0 commit comments