@@ -34,6 +34,8 @@ bool FPubnubAddChannelToGroupAndReceiveMessageTest::RunTest(const FString& Param
34
34
TSharedPtr<bool > bPublishDone = MakeShared<bool >(false );
35
35
TSharedPtr<bool > bPublishSuccess = MakeShared<bool >(false );
36
36
TSharedPtr<bool > bRemoveChannelFromGroupDone = MakeShared<bool >(false );
37
+ TSharedPtr<bool > bSubscribeToGroupDone = MakeShared<bool >(false );
38
+ TSharedPtr<bool > bUnsubscribeFromGroupDone = MakeShared<bool >(false );
37
39
38
40
if (!InitTest ())
39
41
{
@@ -79,6 +81,19 @@ bool FPubnubAddChannelToGroupAndReceiveMessageTest::RunTest(const FString& Param
79
81
}
80
82
});
81
83
84
+ FOnSubscribeOperationResponseNative SubscribeToGroupCallback;
85
+ SubscribeToGroupCallback.BindLambda ([this , bSubscribeToGroupDone](const FPubnubOperationResult& Result)
86
+ {
87
+ *bSubscribeToGroupDone = true ;
88
+ TestFalse (" SubscribeToGroup operation should not have failed" , Result.Error );
89
+ TestEqual (" SubscribeToGroup HTTP status should be 200" , Result.Status , 200 );
90
+
91
+ if (Result.Error )
92
+ {
93
+ AddError (FString::Printf (TEXT (" SubscribeToGroup failed with error: %s" ), *Result.ErrorMessage ));
94
+ }
95
+ });
96
+
82
97
FOnPublishMessageResponseNative PublishCallback;
83
98
PublishCallback.BindLambda ([this , bPublishDone, bPublishSuccess](const FPubnubOperationResult& Result, const FPubnubMessageData& PublishedMessage)
84
99
{
@@ -93,6 +108,19 @@ bool FPubnubAddChannelToGroupAndReceiveMessageTest::RunTest(const FString& Param
93
108
}
94
109
});
95
110
111
+ FOnSubscribeOperationResponseNative UnsubscribeFromGroupCallback;
112
+ UnsubscribeFromGroupCallback.BindLambda ([this , bUnsubscribeFromGroupDone](const FPubnubOperationResult& Result)
113
+ {
114
+ *bUnsubscribeFromGroupDone = true ;
115
+ TestFalse (" UnsubscribeFromGroup operation should not have failed" , Result.Error );
116
+ TestEqual (" UnsubscribeFromGroup HTTP status should be 200" , Result.Status , 200 );
117
+
118
+ if (Result.Error )
119
+ {
120
+ AddError (FString::Printf (TEXT (" UnsubscribeFromGroup failed with error: %s" ), *Result.ErrorMessage ));
121
+ }
122
+ });
123
+
96
124
FOnRemoveChannelFromGroupResponseNative RemoveChannelCallback;
97
125
RemoveChannelCallback.BindLambda ([this , bRemoveChannelFromGroupDone](const FPubnubOperationResult& Result)
98
126
{
@@ -117,11 +145,25 @@ bool FPubnubAddChannelToGroupAndReceiveMessageTest::RunTest(const FString& Param
117
145
}, 0 .1f ));
118
146
119
147
// Step 2: Subscribe to the group
120
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup]()
148
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup, SubscribeToGroupCallback, bSubscribeToGroupDone ]()
121
149
{
122
- PubnubSubsystem->SubscribeToGroup (TestGroup);
150
+ *bSubscribeToGroupDone = false ;
151
+ PubnubSubsystem->SubscribeToGroup (TestGroup, SubscribeToGroupCallback);
152
+ }, 0 .1f ));
153
+
154
+ // Wait until subscribe to group result is received
155
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bSubscribeToGroupDone]() -> bool {
156
+ return *bSubscribeToGroupDone;
157
+ }, MAX_WAIT_TIME));
158
+
159
+ // Check whether subscribe to group result was received
160
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bSubscribeToGroupDone]()
161
+ {
162
+ if (!*bSubscribeToGroupDone)
163
+ {
164
+ AddError (" SubscribeToGroup result callback was not received" );
165
+ }
123
166
}, 0 .1f ));
124
- ADD_LATENT_AUTOMATION_COMMAND (FEngineWaitLatentCommand (0 .5f )); // Allow subscription to establish
125
167
126
168
// Step 3: Publish a message to the channel (which is in the subscribed group)
127
169
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannel, TestMessage, PublishCallback, bPublishDone, bPublishSuccess]()
@@ -147,10 +189,25 @@ bool FPubnubAddChannelToGroupAndReceiveMessageTest::RunTest(const FString& Param
147
189
TestTrue (" Message should be received on channel within a group" , *TestMessageReceived);
148
190
}, 0 .1f ));
149
191
150
- // Cleanup
151
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup]()
192
+ // Cleanup: Unsubscribe from group
193
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup, UnsubscribeFromGroupCallback, bUnsubscribeFromGroupDone ]()
152
194
{
153
- PubnubSubsystem->UnsubscribeFromGroup (TestGroup);
195
+ *bUnsubscribeFromGroupDone = false ;
196
+ PubnubSubsystem->UnsubscribeFromGroup (TestGroup, UnsubscribeFromGroupCallback);
197
+ }, 0 .1f ));
198
+
199
+ // Wait until unsubscribe from group result is received
200
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bUnsubscribeFromGroupDone]() -> bool {
201
+ return *bUnsubscribeFromGroupDone;
202
+ }, MAX_WAIT_TIME));
203
+
204
+ // Check whether unsubscribe from group result was received
205
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bUnsubscribeFromGroupDone]()
206
+ {
207
+ if (!*bUnsubscribeFromGroupDone)
208
+ {
209
+ AddError (" UnsubscribeFromGroup result callback was not received" );
210
+ }
154
211
}, 0 .1f ));
155
212
156
213
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannel, TestGroup, RemoveChannelCallback, bRemoveChannelFromGroupDone]()
@@ -407,6 +464,8 @@ bool FPubnubUnsubscribeFromGroupTest::RunTest(const FString& Parameters)
407
464
TSharedPtr<bool > bPublishDone = MakeShared<bool >(false );
408
465
TSharedPtr<bool > bPublishSuccess = MakeShared<bool >(false );
409
466
TSharedPtr<bool > bRemoveChannelFromGroupDone = MakeShared<bool >(false );
467
+ TSharedPtr<bool > bSubscribeToGroupDone = MakeShared<bool >(false );
468
+ TSharedPtr<bool > bUnsubscribeFromGroupDone = MakeShared<bool >(false );
410
469
411
470
if (!InitTest ())
412
471
{
@@ -445,6 +504,32 @@ bool FPubnubUnsubscribeFromGroupTest::RunTest(const FString& Parameters)
445
504
}
446
505
});
447
506
507
+ FOnSubscribeOperationResponseNative SubscribeToGroupCallback;
508
+ SubscribeToGroupCallback.BindLambda ([this , bSubscribeToGroupDone](const FPubnubOperationResult& Result)
509
+ {
510
+ *bSubscribeToGroupDone = true ;
511
+ TestFalse (" SubscribeToGroup operation should not have failed" , Result.Error );
512
+ TestEqual (" SubscribeToGroup HTTP status should be 200" , Result.Status , 200 );
513
+
514
+ if (Result.Error )
515
+ {
516
+ AddError (FString::Printf (TEXT (" SubscribeToGroup failed with error: %s" ), *Result.ErrorMessage ));
517
+ }
518
+ });
519
+
520
+ FOnSubscribeOperationResponseNative UnsubscribeFromGroupCallback;
521
+ UnsubscribeFromGroupCallback.BindLambda ([this , bUnsubscribeFromGroupDone](const FPubnubOperationResult& Result)
522
+ {
523
+ *bUnsubscribeFromGroupDone = true ;
524
+ TestFalse (" UnsubscribeFromGroup operation should not have failed" , Result.Error );
525
+ TestEqual (" UnsubscribeFromGroup HTTP status should be 200" , Result.Status , 200 );
526
+
527
+ if (Result.Error )
528
+ {
529
+ AddError (FString::Printf (TEXT (" UnsubscribeFromGroup failed with error: %s" ), *Result.ErrorMessage ));
530
+ }
531
+ });
532
+
448
533
FOnPublishMessageResponseNative PublishCallback;
449
534
PublishCallback.BindLambda ([this , bPublishDone, bPublishSuccess](const FPubnubOperationResult& Result, const FPubnubMessageData& PublishedMessage)
450
535
{
@@ -483,18 +568,46 @@ bool FPubnubUnsubscribeFromGroupTest::RunTest(const FString& Parameters)
483
568
}, 0 .1f ));
484
569
485
570
// Step 2: Subscribe to the group
486
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup]()
571
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup, SubscribeToGroupCallback, bSubscribeToGroupDone ]()
487
572
{
488
- PubnubSubsystem->SubscribeToGroup (TestGroup);
573
+ *bSubscribeToGroupDone = false ;
574
+ PubnubSubsystem->SubscribeToGroup (TestGroup, SubscribeToGroupCallback);
575
+ }, 0 .1f ));
576
+
577
+ // Wait until subscribe to group result is received
578
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bSubscribeToGroupDone]() -> bool {
579
+ return *bSubscribeToGroupDone;
580
+ }, MAX_WAIT_TIME));
581
+
582
+ // Check whether subscribe to group result was received
583
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bSubscribeToGroupDone]()
584
+ {
585
+ if (!*bSubscribeToGroupDone)
586
+ {
587
+ AddError (" SubscribeToGroup result callback was not received" );
588
+ }
489
589
}, 0 .1f ));
490
- ADD_LATENT_AUTOMATION_COMMAND (FEngineWaitLatentCommand (0 .5f )); // Allow subscription to establish
491
590
492
591
// Step 3: Unsubscribe from the group
493
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup]()
592
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroup, UnsubscribeFromGroupCallback, bUnsubscribeFromGroupDone]()
593
+ {
594
+ *bUnsubscribeFromGroupDone = false ;
595
+ PubnubSubsystem->UnsubscribeFromGroup (TestGroup, UnsubscribeFromGroupCallback);
596
+ }, 0 .1f ));
597
+
598
+ // Wait until unsubscribe from group result is received
599
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bUnsubscribeFromGroupDone]() -> bool {
600
+ return *bUnsubscribeFromGroupDone;
601
+ }, MAX_WAIT_TIME));
602
+
603
+ // Check whether unsubscribe from group result was received
604
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bUnsubscribeFromGroupDone]()
494
605
{
495
- PubnubSubsystem->UnsubscribeFromGroup (TestGroup);
496
- }, 2 .0f ));
497
- ADD_LATENT_AUTOMATION_COMMAND (FEngineWaitLatentCommand (2 .0f )); // Allow unsubscription to process
606
+ if (!*bUnsubscribeFromGroupDone)
607
+ {
608
+ AddError (" UnsubscribeFromGroup result callback was not received" );
609
+ }
610
+ }, 0 .1f ));
498
611
499
612
// Step 4: Publish a message to the channel (that was in the group)
500
613
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannel, TestMessage, PublishCallback, bPublishDone, bPublishSuccess]()
@@ -552,6 +665,9 @@ bool FPubnubUnsubscribeFromAllTest::RunTest(const FString& Parameters)
552
665
TSharedPtr<bool > bPublish2Done = MakeShared<bool >(false );
553
666
TSharedPtr<bool > bPublish2Success = MakeShared<bool >(false );
554
667
TSharedPtr<bool > bRemoveChannelFromGroupDone = MakeShared<bool >(false );
668
+ TSharedPtr<bool > bSubscribeToChannelDone = MakeShared<bool >(false );
669
+ TSharedPtr<bool > bSubscribeToGroupDone = MakeShared<bool >(false );
670
+ TSharedPtr<bool > bUnsubscribeFromAllDone = MakeShared<bool >(false );
555
671
556
672
557
673
if (!InitTest ())
@@ -596,6 +712,45 @@ bool FPubnubUnsubscribeFromAllTest::RunTest(const FString& Parameters)
596
712
}
597
713
});
598
714
715
+ FOnSubscribeOperationResponseNative SubscribeToChannelCallback;
716
+ SubscribeToChannelCallback.BindLambda ([this , bSubscribeToChannelDone](const FPubnubOperationResult& Result)
717
+ {
718
+ *bSubscribeToChannelDone = true ;
719
+ TestFalse (" SubscribeToChannel operation should not have failed" , Result.Error );
720
+ TestEqual (" SubscribeToChannel HTTP status should be 200" , Result.Status , 200 );
721
+
722
+ if (Result.Error )
723
+ {
724
+ AddError (FString::Printf (TEXT (" SubscribeToChannel failed with error: %s" ), *Result.ErrorMessage ));
725
+ }
726
+ });
727
+
728
+ FOnSubscribeOperationResponseNative SubscribeToGroupCallback;
729
+ SubscribeToGroupCallback.BindLambda ([this , bSubscribeToGroupDone](const FPubnubOperationResult& Result)
730
+ {
731
+ *bSubscribeToGroupDone = true ;
732
+ TestFalse (" SubscribeToGroup operation should not have failed" , Result.Error );
733
+ TestEqual (" SubscribeToGroup HTTP status should be 200" , Result.Status , 200 );
734
+
735
+ if (Result.Error )
736
+ {
737
+ AddError (FString::Printf (TEXT (" SubscribeToGroup failed with error: %s" ), *Result.ErrorMessage ));
738
+ }
739
+ });
740
+
741
+ FOnSubscribeOperationResponseNative UnsubscribeFromAllCallback;
742
+ UnsubscribeFromAllCallback.BindLambda ([this , bUnsubscribeFromAllDone](const FPubnubOperationResult& Result)
743
+ {
744
+ *bUnsubscribeFromAllDone = true ;
745
+ TestFalse (" UnsubscribeFromAll operation should not have failed" , Result.Error );
746
+ TestEqual (" UnsubscribeFromAll HTTP status should be 200" , Result.Status , 200 );
747
+
748
+ if (Result.Error )
749
+ {
750
+ AddError (FString::Printf (TEXT (" UnsubscribeFromAll failed with error: %s" ), *Result.ErrorMessage ));
751
+ }
752
+ });
753
+
599
754
FOnPublishMessageResponseNative PublishCallback1;
600
755
PublishCallback1.BindLambda ([this , bPublish1Done, bPublish1Success](const FPubnubOperationResult& Result, const FPubnubMessageData& PublishedMessage)
601
756
{
@@ -648,35 +803,80 @@ bool FPubnubUnsubscribeFromAllTest::RunTest(const FString& Parameters)
648
803
}, 0 .1f ));
649
804
650
805
// Step 2: Subscribe to the channel
651
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannelForAll]()
806
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannelForAll, SubscribeToChannelCallback, bSubscribeToChannelDone ]()
652
807
{
653
- PubnubSubsystem->SubscribeToChannel (TestChannelForAll);
654
- }, 2 .2f ));
808
+ *bSubscribeToChannelDone = false ;
809
+ PubnubSubsystem->SubscribeToChannel (TestChannelForAll, SubscribeToChannelCallback);
810
+ }, 0 .1f ));
811
+
812
+ // Wait until subscribe to channel result is received
813
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bSubscribeToChannelDone]() -> bool {
814
+ return *bSubscribeToChannelDone;
815
+ }, MAX_WAIT_TIME));
816
+
817
+ // Check whether subscribe to channel result was received
818
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bSubscribeToChannelDone]()
819
+ {
820
+ if (!*bSubscribeToChannelDone)
821
+ {
822
+ AddError (" SubscribeToChannel result callback was not received" );
823
+ }
824
+ }, 0 .1f ));
655
825
656
826
// Step 3: Subscribe to the group
657
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroupForAll]()
827
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestGroupForAll, SubscribeToGroupCallback, bSubscribeToGroupDone ]()
658
828
{
659
- PubnubSubsystem->SubscribeToGroup (TestGroupForAll);
660
- }, 0 .5f ));
829
+ *bSubscribeToGroupDone = false ;
830
+ PubnubSubsystem->SubscribeToGroup (TestGroupForAll, SubscribeToGroupCallback);
831
+ }, 0 .1f ));
832
+
833
+ // Wait until subscribe to group result is received
834
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bSubscribeToGroupDone]() -> bool {
835
+ return *bSubscribeToGroupDone;
836
+ }, MAX_WAIT_TIME));
837
+
838
+ // Check whether subscribe to group result was received
839
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bSubscribeToGroupDone]()
840
+ {
841
+ if (!*bSubscribeToGroupDone)
842
+ {
843
+ AddError (" SubscribeToGroup result callback was not received" );
844
+ }
845
+ }, 0 .1f ));
661
846
662
847
// Step 4: Unsubscribe from all
663
- ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this ]()
848
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , UnsubscribeFromAllCallback, bUnsubscribeFromAllDone ]()
664
849
{
665
- PubnubSubsystem->UnsubscribeFromAll ();
666
- }, 1 .0f ));
850
+ *bUnsubscribeFromAllDone = false ;
851
+ PubnubSubsystem->UnsubscribeFromAll (UnsubscribeFromAllCallback);
852
+ }, 0 .1f ));
853
+
854
+ // Wait until unsubscribe from all result is received
855
+ ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bUnsubscribeFromAllDone]() -> bool {
856
+ return *bUnsubscribeFromAllDone;
857
+ }, MAX_WAIT_TIME));
858
+
859
+ // Check whether unsubscribe from all result was received
860
+ ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bUnsubscribeFromAllDone]()
861
+ {
862
+ if (!*bUnsubscribeFromAllDone)
863
+ {
864
+ AddError (" UnsubscribeFromAll result callback was not received" );
865
+ }
866
+ }, 0 .1f ));
667
867
668
868
// Step 5: Publish a message to the direct channel
669
869
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannelForAll, TestMessageForChannel, PublishCallback1, bPublish1Done, bPublish1Success]()
670
870
{
671
871
*bPublish1Done = false ;
672
872
*bPublish1Success = false ;
673
873
PubnubSubsystem->PublishMessage (TestChannelForAll, TestMessageForChannel, PublishCallback1);
674
- }, 0 .3f ));
874
+ }, 0 .1f ));
675
875
ADD_LATENT_AUTOMATION_COMMAND (FWaitUntilLatentCommand ([bPublish1Done]() { return *bPublish1Done; }, MAX_WAIT_TIME));
676
876
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , bPublish1Success]()
677
877
{
678
878
TestTrue (" PublishMessage 1 should succeed" , *bPublish1Success);
679
- }, 0 .3f ));
879
+ }, 0 .1f ));
680
880
681
881
// Step 6: Publish a message to the channel that was in the group
682
882
ADD_LATENT_AUTOMATION_COMMAND (FDelayedFunctionLatentCommand ([this , TestChannelInGroupForAll, TestMessageForGroupChannel, PublishCallback2, bPublish2Done, bPublish2Success]()
0 commit comments