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