@@ -616,31 +616,99 @@ describe('WidgetModel', function () {
616
616
} ) ;
617
617
618
618
it ( 'respects the message throttle' , function ( ) {
619
- const send = sinon . spy ( this . widget , 'send_sync_message' ) ;
619
+ // reuse the callback, similar to .touch in views, which will
620
+ // expose an bug of calling onstatus multiple times
621
+ const callbacks = this . widget . callbacks ( ) ;
620
622
this . widget . set ( 'a' , 'sync test' ) ;
621
- this . widget . save_changes ( ) ;
623
+ expect ( this . widget . _pending_msgs ) . to . equal ( 0 ) ;
624
+ this . widget . save_changes ( callbacks ) ;
625
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
622
626
this . widget . set ( 'a' , 'another sync test' ) ;
623
627
this . widget . set ( 'b' , 'change b' ) ;
624
- this . widget . save_changes ( ) ;
628
+ this . widget . save_changes ( callbacks ) ;
625
629
this . widget . set ( 'b' , 'change b again' ) ;
626
- this . widget . save_changes ( ) ;
630
+ this . widget . save_changes ( callbacks ) ;
631
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
627
632
628
633
// check that one sync message went through
629
- expect ( send ) . to . be . calledOnce ;
630
- expect ( send ) . to . be . calledWith ( {
631
- a : 'sync test' ,
634
+ expect ( this . comm . send ) . to . be . calledOnce ;
635
+ expect ( this . comm . send ) . to . be . calledWith ( {
636
+ method : 'update' ,
637
+ state : { a : 'sync test' } ,
638
+ buffer_paths : [ ] ,
639
+ } ) ;
640
+ expect ( this . widget . _msg_buffer ) . to . deep . equal ( {
641
+ a : 'another sync test' ,
642
+ b : 'change b again' ,
632
643
} ) ;
644
+ expect ( this . widget . _msg_buffer_callbacks ) . to . not . equals ( null ) ;
633
645
// have the comm send a status idle message
634
- this . widget . _handle_status ( {
646
+ callbacks . iopub . status ( {
635
647
content : {
636
648
execution_state : 'idle' ,
637
649
} ,
638
650
} ) ;
651
+ // we directly get a new pending message
652
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
653
+ expect ( this . widget . _msg_buffer ) . to . equal ( null ) ;
654
+ expect ( this . widget . _msg_buffer_callbacks ) . to . equals ( null ) ;
655
+
639
656
// check that the other sync message went through with the updated values
640
- expect ( send . secondCall ) . to . be . calledWith ( {
641
- a : 'another sync test' ,
642
- b : 'change b again' ,
657
+ expect ( this . comm . send . secondCall ) . to . be . calledWith ( {
658
+ method : 'update' ,
659
+ state : {
660
+ a : 'another sync test' ,
661
+ b : 'change b again' ,
662
+ } ,
663
+ buffer_paths : [ ] ,
664
+ } ) ;
665
+ callbacks . iopub . status ( {
666
+ content : {
667
+ execution_state : 'idle' ,
668
+ } ,
669
+ } ) ;
670
+ expect ( this . widget . _pending_msgs ) . to . equal ( 0 ) ;
671
+
672
+ // repeat again
673
+ this . comm . send . resetHistory ( ) ;
674
+
675
+ this . widget . set ( 'a' , 'sync test - 2' ) ;
676
+ this . widget . save_changes ( callbacks ) ;
677
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
678
+ this . widget . set ( 'a' , 'another sync test - 2' ) ;
679
+ this . widget . set ( 'b' , 'change b - 2' ) ;
680
+ this . widget . save_changes ( callbacks ) ;
681
+ this . widget . set ( 'b' , 'change b again - 2' ) ;
682
+ this . widget . save_changes ( callbacks ) ;
683
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
684
+ expect ( this . comm . send ) . to . be . calledOnce ;
685
+ expect ( this . comm . send ) . to . be . calledWith ( {
686
+ method : 'update' ,
687
+ state : { a : 'sync test - 2' } ,
688
+ buffer_paths : [ ] ,
689
+ } ) ;
690
+ callbacks . iopub . status ( {
691
+ content : {
692
+ execution_state : 'idle' ,
693
+ } ,
694
+ } ) ;
695
+ // again, directly a new message
696
+ expect ( this . widget . _pending_msgs ) . to . equal ( 1 ) ;
697
+
698
+ expect ( this . comm . send . secondCall ) . to . be . calledWith ( {
699
+ method : 'update' ,
700
+ state : {
701
+ a : 'another sync test - 2' ,
702
+ b : 'change b again - 2' ,
703
+ } ,
704
+ buffer_paths : [ ] ,
705
+ } ) ;
706
+ callbacks . iopub . status ( {
707
+ content : {
708
+ execution_state : 'idle' ,
709
+ } ,
643
710
} ) ;
711
+ expect ( this . widget . _pending_msgs ) . to . equal ( 0 ) ;
644
712
} ) ;
645
713
646
714
it ( 'Initial values are *not* sent on creation' , function ( ) {
0 commit comments