Skip to content

Commit c1eaa68

Browse files
authored
Simplify Messaging iOS tests on CI (#748)
* Fix for Messaging tests on iOS * Use a response file * Update UIHandlerAutomated.cs * Move comments
1 parent af5b749 commit c1eaa68

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

messaging/testapp/Assets/Firebase/Sample/Messaging/UIHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ protected virtual void Start() {
7777
void InitializeFirebase() {
7878
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
7979
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
80-
Firebase.Messaging.FirebaseMessaging.SubscribeAsync(topic).ContinueWithOnMainThread(task => {
81-
LogTaskCompletion(task, "SubscribeAsync");
82-
});
8380
DebugLog("Firebase Messaging Initialized");
8481

8582
// This will display the prompt to request permission to receive
@@ -89,6 +86,10 @@ void InitializeFirebase() {
8986
Firebase.Messaging.FirebaseMessaging.RequestPermissionAsync().ContinueWithOnMainThread(
9087
task => {
9188
LogTaskCompletion(task, "RequestPermissionAsync");
89+
90+
Firebase.Messaging.FirebaseMessaging.SubscribeAsync(topic).ContinueWithOnMainThread(task => {
91+
LogTaskCompletion(task, "SubscribeAsync");
92+
});
9293
}
9394
);
9495
isFirebaseInitialized = true;

messaging/testapp/Assets/Firebase/Sample/Messaging/UIHandlerAutomated.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class UIHandlerAutomated : UIHandler {
1313

1414
private const string TestTopic = "TestTopic";
1515
private const string ServerKey = "REPLACE_WITH_YOUR_SERVER_KEY";
16-
private const string FirebaseBackendUrl = "REPLACE_WITH_YOUR_BACKEND_URL";
16+
private const string FirebaseBackendUrl = "https://fcm.googleapis.com/fcm/send";
1717

1818
private const string MessageFoo = "This is a test message";
1919
private const string MessageBar = "It contains some data";
@@ -35,6 +35,26 @@ public class UIHandlerAutomated : UIHandler {
3535
private FirebaseMessage lastReceivedMessage;
3636

3737
protected override void Start() {
38+
#if FIREBASE_RUNNING_FROM_CI && (UNITY_IOS || UNITY_TVOS)
39+
// Messaging on iOS requires user interaction to give permissions
40+
// So if running on CI, just run a dummy test instead.
41+
Func<Task>[] tests = {
42+
MakeTest(TestDummy)
43+
};
44+
string[] customTests = {
45+
"TestDummy"
46+
};
47+
testRunner = AutomatedTestRunner.CreateTestRunner(
48+
testsToRun: tests,
49+
logFunc: DebugLog,
50+
testNames: customTests
51+
);
52+
// Don't use base.Start(), since that will trigger the permission request.
53+
DebugLog("Skipping usual Messaging tests on CI + iOS");
54+
isFirebaseInitialized = true;
55+
56+
#else // FIREBASE_RUNNING_FROM_CI && (UNITY_IOS || UNITY_TVOS)
57+
3858
Func<Task>[] tests = {
3959
// Disable these tests on desktop, as desktop never receives a token, and so WaitForToken
4060
// (called by all of these tests) stalls forever.
@@ -82,6 +102,7 @@ protected override void Start() {
82102
);
83103

84104
base.Start();
105+
#endif // FIREBASE_RUNNING_FROM_CI
85106
}
86107

87108
protected override void Update() {

scripts/gha/build_testapps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ def setup_unity_project(dir_helper, setup_options):
426426
_copy_unity_assets(dir_helper, setup_options.testapp_file_filters)
427427
_add_menu_scene(dir_helper)
428428
_add_automated_test_runner(dir_helper)
429+
# If running on CI, copy over the file that defines that custom scripting symbol
430+
# For more info, see: https://docs.unity3d.com/Manual/CustomScriptingSymbols.html
431+
if FLAGS.ci:
432+
shutil.copy(
433+
os.path.join(dir_helper.builder_dir, "csc.rsp"),
434+
dir_helper.unity_project_assets_dir)
429435
# This is the editor script that performs builds.
430436
app_builder = dir_helper.copy_editor_script("AppBuilderHelper.cs")
431437
if not setup_options.enable_firebase:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-define:FIREBASE_RUNNING_FROM_CI

0 commit comments

Comments
 (0)