@@ -187,6 +187,7 @@ class InvalidErrorHandler; end
187
187
stub_request ( :post , impression_log_url ) . with ( query : params )
188
188
189
189
expect ( project_instance . activate ( 'test_experiment' , 'test_user' ) ) . to eq ( 'control' )
190
+ sleep 0.1
190
191
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
191
192
expect ( project_instance . decision_service . bucketer ) . to have_received ( :bucket ) . once
192
193
end
@@ -205,6 +206,7 @@ class InvalidErrorHandler; end
205
206
stub_request ( :post , impression_log_url ) . with ( query : params )
206
207
207
208
expect ( project_instance . activate ( 'test_experiment' , 'test_user' ) ) . to eq ( 'control' )
209
+ sleep 0.1
208
210
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
209
211
end
210
212
@@ -296,6 +298,7 @@ class InvalidErrorHandler; end
296
298
# Should be included via exact match string audience with id '3468206642'
297
299
expect ( @project_typed_audience_instance . activate ( 'typed_audience_experiment' , 'test_user' , 'house' => 'Gryffindor' ) )
298
300
. to eq ( 'A' )
301
+ sleep 0.1
299
302
expect ( @project_typed_audience_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
300
303
expect ( @project_typed_audience_instance . decision_service . bucketer ) . to have_received ( :bucket ) . once
301
304
end
@@ -371,6 +374,7 @@ class InvalidErrorHandler; end
371
374
372
375
expect ( @project_typed_audience_instance . activate ( 'audience_combinations_experiment' , 'test_user' , user_attributes ) )
373
376
. to eq ( 'A' )
377
+ sleep 0.1
374
378
expect ( @project_typed_audience_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
375
379
expect ( @project_typed_audience_instance . decision_service . bucketer ) . to have_received ( :bucket ) . once
376
380
end
@@ -432,6 +436,7 @@ class InvalidErrorHandler; end
432
436
433
437
expect ( project_instance . activate ( 'test_experiment_with_audience' , 'test_user' , attributes ) )
434
438
. to eq ( 'control_with_audience' )
439
+ sleep 0.1
435
440
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
436
441
expect ( project_instance . decision_service . bucketer ) . to have_received ( :bucket ) . once
437
442
end
@@ -492,6 +497,7 @@ class InvalidErrorHandler; end
492
497
project_instance . decision_service . set_forced_variation ( project_config , 'test_experiment_with_audience' , 'test_user' , 'variation_with_audience' )
493
498
variation_to_return = project_instance . decision_service . get_forced_variation ( project_config , 'test_experiment' , 'test_user' )
494
499
allow ( project_instance . decision_service . bucketer ) . to receive ( :bucket ) . and_return ( variation_to_return )
500
+ sleep 0.1
495
501
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
496
502
497
503
expect ( project_instance . activate ( 'test_experiment_with_audience' , 'test_user' , 'browser_type' => 'firefox' ) )
@@ -595,13 +601,16 @@ def callback(_args); end
595
601
method ( :callback )
596
602
)
597
603
variation_to_return = project_config . get_variation_from_id ( 'test_experiment' , '111128' )
604
+ sleep 0.1
598
605
allow ( project_instance . decision_service . bucketer ) . to receive ( :bucket ) . and_return ( variation_to_return )
599
606
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
600
607
allow ( project_config ) . to receive ( :get_audience_ids_for_experiment )
601
608
. with ( 'test_experiment' )
602
609
. and_return ( [ ] )
603
610
experiment = project_config . get_experiment_from_key ( 'test_experiment' )
604
611
612
+ # sleep because forwarder is wrapped in a thread
613
+ sleep 0.1
605
614
# Decision listener
606
615
expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
607
616
Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] , any_args
@@ -621,6 +630,8 @@ def callback(_args); end
621
630
622
631
project_instance . activate ( 'test_experiment' , 'test_user' )
623
632
633
+ sleep 0.1
634
+
624
635
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::INFO , "Activating user 'test_user' in experiment 'test_experiment'." )
625
636
end
626
637
@@ -634,6 +645,7 @@ def callback(_args); end
634
645
allow ( project_instance . decision_service . bucketer ) . to receive ( :bucket ) . and_return ( variation_to_return )
635
646
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( any_args ) . and_raise ( RuntimeError )
636
647
project_instance . activate ( 'test_experiment' , 'test_user' )
648
+ sleep 0.1
637
649
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::ERROR , "Error dispatching event: #{ log_event } RuntimeError." )
638
650
end
639
651
@@ -661,6 +673,7 @@ def callback(_args); end
661
673
662
674
expect ( project_instance . activate ( 'test_experiment_with_audience' , 'forced_audience_user' , 'browser_type' => 'wrong_browser' ) )
663
675
. to eq ( 'variation_with_audience' )
676
+ sleep 0.1
664
677
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , impression_log_url , params , post_headers ) ) . once
665
678
expect ( Optimizely ::Audience ) . to_not have_received ( :user_in_experiment? )
666
679
end
@@ -712,6 +725,7 @@ def callback(_args); end
712
725
expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . ordered
713
726
714
727
project_instance . activate ( 'test_experiment' , 'test_user' )
728
+ sleep 0.1
715
729
end
716
730
end
717
731
@@ -720,16 +734,17 @@ def callback(_args); end
720
734
WebMock . allow_net_connect!
721
735
notification_center = Optimizely ::NotificationCenter . new ( spy_logger , error_handler )
722
736
723
- expect ( notification_center ) . to receive ( :send_notifications ) . with (
737
+ expect ( notification_center ) . to receive ( :send_notifications ) . once . with (
724
738
Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :OPTIMIZELY_CONFIG_UPDATE ]
725
739
) . ordered
726
740
727
741
expect ( notification_center ) . to receive ( :send_notifications ) . ordered
728
742
729
743
expect ( notification_center ) . to receive ( :send_notifications ) . ordered
730
744
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
745
+ logger :spy_logger ,
731
746
url : 'https://cdn.optimizely.com/datafiles/QBw9gFM8oTn7ogY9ANCC1z.json' ,
732
- notification_center : notification_center
747
+ notification_center : notification_center ,
733
748
)
734
749
735
750
project_instance = Optimizely ::Project . new (
@@ -741,18 +756,20 @@ def callback(_args); end
741
756
742
757
expect ( http_project_config_manager . config ) . not_to eq ( nil )
743
758
expect ( project_instance . activate ( 'checkout_flow_experiment' , 'test_user' ) ) . not_to eq ( nil )
759
+ sleep 0.5
744
760
end
745
761
746
762
it 'should update config, send update notification when sdk key is provided' do
747
763
WebMock . allow_net_connect!
748
764
notification_center = Optimizely ::NotificationCenter . new ( spy_logger , error_handler )
765
+ allow ( notification_center ) . to receive ( :send_notifications )
749
766
750
767
expect ( notification_center ) . to receive ( :send_notifications ) . with (
751
768
Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :OPTIMIZELY_CONFIG_UPDATE ]
752
- ) . ordered
769
+ )
753
770
754
- expect ( notification_center ) . to receive ( :send_notifications ) . ordered
755
- expect ( notification_center ) . to receive ( :send_notifications ) . ordered
771
+ expect ( notification_center ) . to receive ( :send_notifications )
772
+ expect ( notification_center ) . to receive ( :send_notifications )
756
773
757
774
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
758
775
sdk_key : 'QBw9gFM8oTn7ogY9ANCC1z' ,
@@ -768,6 +785,7 @@ def callback(_args); end
768
785
769
786
expect ( http_project_config_manager . config ) . not_to eq ( nil )
770
787
expect ( project_instance . activate ( 'checkout_flow_experiment' , 'test_user' ) ) . not_to eq ( nil )
788
+ sleep 0.5
771
789
end
772
790
end
773
791
@@ -792,6 +810,7 @@ def callback(_args); end
792
810
793
811
expect ( project_instance . is_valid ) . to be true
794
812
expect ( project_instance . activate ( 'checkout_flow_experiment' , 'test_user' ) ) . not_to eq ( nil )
813
+ sleep 0.5
795
814
end
796
815
end
797
816
end
@@ -859,13 +878,15 @@ def callback(_args); end
859
878
860
879
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
861
880
project_instance . track ( 'test_event' , 'test_user' )
881
+ sleep 0.1
862
882
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
863
883
end
864
884
865
885
it 'should properly track an event by calling dispatch_event with right params after forced variation' do
866
886
project_instance . decision_service . set_forced_variation ( project_config , 'test_experiment' , 'test_user' , 'variation' )
867
887
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
868
888
project_instance . track ( 'test_event' , 'test_user' )
889
+ sleep 0.1
869
890
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , @expected_track_event_params , post_headers ) ) . once
870
891
end
871
892
@@ -878,6 +899,7 @@ def callback(_args); end
878
899
project_instance . decision_service . set_forced_variation ( project_config , 'test_experiment' , 'test_user' , 'variation' )
879
900
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
880
901
project_instance . track ( 'test_event' , 'test_user' , nil , revenue : 42 )
902
+ sleep 0.1
881
903
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
882
904
end
883
905
@@ -889,6 +911,7 @@ def callback(_args); end
889
911
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( any_args ) . and_raise ( RuntimeError )
890
912
891
913
project_instance . track ( 'test_event' , 'test_user' )
914
+ sleep 0.1
892
915
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::ERROR , "Error dispatching event: #{ log_event } RuntimeError." )
893
916
end
894
917
@@ -917,6 +940,7 @@ def callback(_args); end
917
940
) . ordered
918
941
919
942
project_instance . track ( 'test_event' , 'test_user' , nil , 'revenue' => 42 )
943
+ sleep 0.1
920
944
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
921
945
end
922
946
@@ -933,6 +957,7 @@ def callback(_args); end
933
957
934
958
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
935
959
project_instance . track ( 'test_event_with_audience' , 'test_user' , 'browser_type' => 'firefox' )
960
+ sleep 0.1
936
961
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
937
962
end
938
963
@@ -980,6 +1005,7 @@ def callback(_args); end
980
1005
# Should be included via substring match string audience with id '3988293898'
981
1006
allow ( @project_typed_audience_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
982
1007
@project_typed_audience_instance . track ( 'item_bought' , 'test_user' , 'house' => 'Welcome to Slytherin!' )
1008
+ sleep 0.1
983
1009
expect ( @project_typed_audience_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , @expected_event_params , post_headers ) ) . once
984
1010
end
985
1011
@@ -988,6 +1014,7 @@ def callback(_args); end
988
1014
params [ :visitors ] [ 0 ] [ :attributes ] [ 0 ] [ :value ] = 'Welcome to Hufflepuff!'
989
1015
allow ( @project_typed_audience_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
990
1016
@project_typed_audience_instance . track ( 'item_bought' , 'test_user' , 'house' => 'Welcome to Hufflepuff!' )
1017
+ sleep 0.1
991
1018
expect ( @project_typed_audience_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
992
1019
end
993
1020
@@ -1018,6 +1045,7 @@ def callback(_args); end
1018
1045
params [ :visitors ] [ 0 ] [ :snapshots ] [ 0 ] [ :events ] [ 0 ] [ :key ] = 'user_signed_up'
1019
1046
allow ( @project_typed_audience_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
1020
1047
@project_typed_audience_instance . track ( 'user_signed_up' , 'test_user' , user_attributes )
1048
+ sleep 0.1
1021
1049
expect ( @project_typed_audience_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
1022
1050
end
1023
1051
end
@@ -1035,6 +1063,7 @@ def callback(_args); end
1035
1063
1036
1064
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
1037
1065
project_instance . track ( 'test_event_with_audience' , 'test_user' , 'browser_type' => 'cyberdog' )
1066
+ sleep 0.1
1038
1067
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
1039
1068
end
1040
1069
@@ -1044,6 +1073,7 @@ def callback(_args); end
1044
1073
params [ :visitors ] [ 0 ] [ :snapshots ] [ 0 ] [ :events ] [ 0 ] [ :key ] = 'test_event_not_running'
1045
1074
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
1046
1075
project_instance . track ( 'test_event_not_running' , 'test_user' )
1076
+ sleep 0.1
1047
1077
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
1048
1078
end
1049
1079
@@ -1055,6 +1085,7 @@ def callback(_args); end
1055
1085
)
1056
1086
allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
1057
1087
project_instance . track ( 'test_event' , 'test_user' , nil , 'revenue' => 42 )
1088
+ sleep 0.1
1058
1089
expect ( spy_logger ) . to have_received ( :log ) . with ( Logger ::INFO , "Tracking event 'test_event' for user 'test_user'." )
1059
1090
end
1060
1091
@@ -1066,6 +1097,7 @@ def callback(_args); end
1066
1097
it 'should return false when called with attributes in an invalid format' do
1067
1098
expect ( project_instance . error_handler ) . to receive ( :handle_error ) . with ( any_args ) . once . and_return ( nil )
1068
1099
project_instance . track ( 'test_event' , 'test_user' , 'invalid' )
1100
+ sleep 0.1
1069
1101
end
1070
1102
1071
1103
it 'should raise an exception when called with event tags in an invalid format' do
@@ -1538,6 +1570,7 @@ def callback(_args); end
1538
1570
allow ( project_instance . decision_service ) . to receive ( :get_variation_for_feature ) . and_return ( decision_to_return )
1539
1571
1540
1572
expect ( project_instance . is_feature_enabled ( 'multi_variate_feature' , 'test_user' ) ) . to be false
1573
+ sleep 0.2
1541
1574
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) ) . once
1542
1575
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::INFO , "Feature 'multi_variate_feature' is not enabled for user 'test_user'." )
1543
1576
end
@@ -1560,7 +1593,7 @@ def callback(_args); end
1560
1593
1561
1594
# Decision listener called when the user is in experiment with variation feature on.
1562
1595
expect ( variation_to_return [ 'featureEnabled' ] ) . to be true
1563
- expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . once . with (
1596
+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
1564
1597
Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
1565
1598
'feature' , 'test_user' , { } ,
1566
1599
feature_enabled : true ,
@@ -1573,6 +1606,7 @@ def callback(_args); end
1573
1606
) . ordered
1574
1607
1575
1608
project_instance . is_feature_enabled ( 'multi_variate_feature' , 'test_user' )
1609
+ sleep 0.5
1576
1610
end
1577
1611
1578
1612
it 'should call decision listener when user is bucketed into a feature experiment with featureEnabled property is false' do
@@ -1604,6 +1638,7 @@ def callback(_args); end
1604
1638
)
1605
1639
1606
1640
project_instance . is_feature_enabled ( 'multi_variate_feature' , 'test_user' , 'browser_type' => 'chrome' )
1641
+ sleep 0.5
1607
1642
end
1608
1643
1609
1644
it 'should call decision listener when user is bucketed into rollout with featureEnabled property is true' do
@@ -1628,6 +1663,7 @@ def callback(_args); end
1628
1663
)
1629
1664
1630
1665
project_instance . is_feature_enabled ( 'boolean_single_variable_feature' , 'test_user' , 'browser_type' => 'firefox' )
1666
+ sleep 0.1
1631
1667
end
1632
1668
1633
1669
it 'should call decision listener when user is bucketed into rollout with featureEnabled property is false' do
@@ -1644,6 +1680,7 @@ def callback(_args); end
1644
1680
)
1645
1681
1646
1682
project_instance . is_feature_enabled ( 'boolean_single_variable_feature' , 'test_user' )
1683
+ sleep 0.1
1647
1684
end
1648
1685
1649
1686
it 'call decision listener when the user is not bucketed into any experiment or rollout' do
@@ -2814,7 +2851,7 @@ def callback(_args); end
2814
2851
project_instance = Optimizely ::Project . new ( nil , nil , nil , nil , true , nil , nil , config_manager , nil , event_processor )
2815
2852
2816
2853
expect ( config_manager . stopped ) . to be false
2817
- expect ( event_processor . started ) . to be true
2854
+ expect ( event_processor . started ) . to be false
2818
2855
2819
2856
project_instance . close
2820
2857
0 commit comments