@@ -322,6 +322,70 @@ public function testNoChangeAfterResumeBeforeInsert()
322
322
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
323
323
}
324
324
325
+ public function testResumeTokenIsUpdatedAfterResuming ()
326
+ {
327
+ $ this ->insertDocument (['_id ' => 1 ]);
328
+
329
+ $ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
330
+ $ changeStream = $ operation ->execute ($ this ->getPrimaryServer ());
331
+
332
+ $ changeStream ->rewind ();
333
+ $ this ->assertNull ($ changeStream ->current ());
334
+
335
+ $ this ->insertDocument (['_id ' => 2 ]);
336
+
337
+ $ changeStream ->next ();
338
+ $ this ->assertTrue ($ changeStream ->valid ());
339
+
340
+ $ expectedResult = [
341
+ '_id ' => $ changeStream ->current ()->_id ,
342
+ 'operationType ' => 'insert ' ,
343
+ 'fullDocument ' => ['_id ' => 2 ],
344
+ 'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
345
+ 'documentKey ' => ['_id ' => 2 ],
346
+ ];
347
+
348
+ $ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
349
+
350
+ $ this ->killChangeStreamCursor ($ changeStream );
351
+
352
+ $ this ->insertDocument (['_id ' => 3 ]);
353
+
354
+ $ changeStream ->next ();
355
+ $ this ->assertTrue ($ changeStream ->valid ());
356
+
357
+ $ expectedResult = [
358
+ '_id ' => $ changeStream ->current ()->_id ,
359
+ 'operationType ' => 'insert ' ,
360
+ 'fullDocument ' => ['_id ' => 3 ],
361
+ 'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
362
+ 'documentKey ' => ['_id ' => 3 ],
363
+ ];
364
+
365
+ $ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
366
+
367
+ /* Triggering a consecutive failure will allow us to test whether the
368
+ * resume token was properly updated after the last resume. If the
369
+ * resume token updated, the next result will be {_id: 4}; otherwise,
370
+ * we'll see {_id: 3} returned again. */
371
+ $ this ->killChangeStreamCursor ($ changeStream );
372
+
373
+ $ this ->insertDocument (['_id ' => 4 ]);
374
+
375
+ $ changeStream ->next ();
376
+ $ this ->assertTrue ($ changeStream ->valid ());
377
+
378
+ $ expectedResult = [
379
+ '_id ' => $ changeStream ->current ()->_id ,
380
+ 'operationType ' => 'insert ' ,
381
+ 'fullDocument ' => ['_id ' => 4 ],
382
+ 'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
383
+ 'documentKey ' => ['_id ' => 4 ],
384
+ ];
385
+
386
+ $ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
387
+ }
388
+
325
389
public function testKey ()
326
390
{
327
391
$ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
0 commit comments