@@ -355,6 +355,77 @@ test_replay(void **state)
355
355
close (fd );
356
356
}
357
357
358
+ /* TEST */
359
+ static void
360
+ test_replay_start_time (void * * state )
361
+ {
362
+ struct state * st = (struct state * )* state ;
363
+ struct lyd_node * notif ;
364
+ int ret , fd ;
365
+ char * str , * exp ;
366
+ uint32_t sub_id ;
367
+ struct timespec ts , replay_start_time ;
368
+
369
+ /* store a notification not supposed to be replayed */
370
+ assert_int_equal (SR_ERR_OK , sr_set_module_replay_support (st -> conn , "ops" , 1 ));
371
+ assert_int_equal (SR_ERR_OK , sr_notif_send (st -> sess , "/ops:notif4" , NULL , 0 , 0 , 0 ));
372
+
373
+ /* remember realtime after the notification */
374
+ clock_gettime (CLOCK_REALTIME , & ts );
375
+
376
+ /* store a notification for replay */
377
+ assert_int_equal (SR_ERR_OK , sr_set_module_replay_support (st -> conn , "test" , 1 ));
378
+ assert_int_equal (SR_ERR_OK , sr_notif_send (st -> sess , "/test:notif1" , NULL , 0 , 0 , 0 ));
379
+
380
+ /* subscribe to notifs with start-time */
381
+ assert_int_equal (SR_ERR_OK , srsn_subscribe (st -> sess , "NETCONF" , NULL , NULL , & ts , 0 , NULL , & replay_start_time , & fd , & sub_id ));
382
+
383
+ /* there are notifs from time earlier than the start time */
384
+ assert_int_equal (replay_start_time .tv_sec , 0 );
385
+
386
+ /* read replayed notification */
387
+ assert_int_equal (SR_ERR_OK , srsn_poll (fd , 1000 ));
388
+ assert_int_equal (SR_ERR_OK , srsn_read_notif (fd , st -> ly_ctx , & ts , & notif ));
389
+ lyd_print_mem (& str , notif , LYD_XML , 0 );
390
+ assert_string_equal (str , "<notif1 xmlns=\"urn:test\"/>\n" );
391
+ free (str );
392
+ lyd_free_tree (notif );
393
+
394
+ /* replay completed */
395
+ assert_int_equal (SR_ERR_OK , srsn_poll (fd , 1000 ));
396
+ assert_int_equal (SR_ERR_OK , srsn_read_notif (fd , st -> ly_ctx , & ts , & notif ));
397
+ lyd_print_mem (& str , notif , LYD_XML , 0 );
398
+ ret = asprintf (& exp ,
399
+ "<replay-completed xmlns=\"urn:ietf:params:xml:ns:yang:ietf-subscribed-notifications\">\n"
400
+ " <id>%" PRIu32 "</id>\n"
401
+ "</replay-completed>\n" , sub_id );
402
+ assert_int_not_equal (ret , -1 );
403
+ assert_string_equal (str , exp );
404
+ free (str );
405
+ free (exp );
406
+ lyd_free_tree (notif );
407
+
408
+ /* stop the subscription */
409
+ assert_int_equal (SR_ERR_OK , srsn_terminate (sub_id , "ietf-subscribed-notifications:no-such-subscription" ));
410
+
411
+ /* read (no poll, pipe closed) and check the notif */
412
+ assert_int_equal (SR_ERR_OK , srsn_read_notif (fd , st -> ly_ctx , & ts , & notif ));
413
+ lyd_print_mem (& str , notif , LYD_XML , 0 );
414
+ ret = asprintf (& exp ,
415
+ "<subscription-terminated xmlns=\"urn:ietf:params:xml:ns:yang:ietf-subscribed-notifications\">\n"
416
+ " <id>%" PRIu32 "</id>\n"
417
+ " <reason>no-such-subscription</reason>\n"
418
+ "</subscription-terminated>\n" , sub_id );
419
+ assert_int_not_equal (ret , -1 );
420
+ assert_string_equal (str , exp );
421
+ free (str );
422
+ free (exp );
423
+ lyd_free_tree (notif );
424
+
425
+ /* cleanup */
426
+ close (fd );
427
+ }
428
+
358
429
/* TEST */
359
430
static void
360
431
test_suspend (void * * state )
@@ -889,6 +960,7 @@ main(void)
889
960
cmocka_unit_test (test_sub_delete ),
890
961
cmocka_unit_test (test_stop_time ),
891
962
cmocka_unit_test (test_replay ),
963
+ cmocka_unit_test (test_replay_start_time ),
892
964
cmocka_unit_test (test_suspend ),
893
965
cmocka_unit_test (test_yp_periodic ),
894
966
cmocka_unit_test (test_yp_on_change ),
0 commit comments