コード例 #1
0
        public override void Render()
        {
            _newBuddyName = AutomationReport.GetMostRecentBuddy();             //Display last-used Buddy by default.

            //Tell test runner to not/ignore BuddySystem tests in the current test run.
            if (Application.isPlaying)
            {
                if (_ignoreBuddyTests != AutomationMaster.IgnoreAllBuddyTests)
                {
                    if (!AutomationMaster.LockIgnoreBuddyTestsFlag)
                    {
                        AutomationMaster.IgnoreAllBuddyTests = _ignoreBuddyTests;
                    }
                }
            }


            GUIStyle buddyWindowLabel = new GUIStyle(GUI.skin.label);

            buddyWindowLabel.fontStyle = FontStyle.Bold;
            buddyWindowLabel.padding   = Nexus.BaseRectOffset;
            GUIStyle sl = new GUIStyle(GUI.skin.label);

            sl.padding = new RectOffset(15, 0, 0, 0);

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("- Set Buddy Info -", buddyWindowLabel);
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            sl.normal.textColor = Swat.WindowDefaultTextColor;

            if (_isBuddySet && !string.IsNullOrEmpty(BuddyHandler.BuddyName))
            {
                EditorGUILayout.LabelField(string.Format("Current Buddy is {0}", BuddyHandler.BuddyName), sl);
                EditorGUILayout.Space();
            }

            sl.fixedWidth = 125;

            if (!_buddyHistory.Any() && DateTime.Now.Subtract(_lastBuddyRetrieval).TotalSeconds > _redrawRateSeconds)
            {
                _buddyHistory       = AutomationReport.GetBuddyHistory();
                _lastBuddyRetrieval = DateTime.Now;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Ignore Buddy Tests? ", sl);
            _ignoreBuddyTests = EditorGUILayout.Toggle(_ignoreBuddyTests);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (_buddyHistory.Any())
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Use Known Buddy? ", sl);
                _chooseBuddyFromHistory = EditorGUILayout.Toggle(_chooseBuddyFromHistory);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Is Primary? ", sl);
            _isPrimaryBuddy = EditorGUILayout.Toggle(_isPrimaryBuddy);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (!_chooseBuddyFromHistory || !_buddyHistory.Any())
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Buddy Name: ", sl);
                _newBuddyName = EditorGUILayout.TextField(_newBuddyName);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            GUIStyle buddies = new GUIStyle(EditorStyles.popup);

            buddies.margin = new RectOffset(15, 0, 0, 0);

            if (_chooseBuddyFromHistory)
            {
                if (_buddyHistory.Any())
                {
                    buddies.fixedHeight = 15;
                    _buddySelection     = EditorGUILayout.Popup(_buddySelection, _buddyHistory.ToArray(), buddies, new GUILayoutOption[] { GUILayout.Height(50), GUILayout.MaxWidth(250) });
                }
            }

            buddies             = new GUIStyle(GUI.skin.button);
            buddies.margin      = new RectOffset(15, 0, 0, 0);
            buddies.fixedHeight = 25;

            if (GUILayout.Button("Set Buddy", buddies, new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(25) }))
            {
                _isBuddySet = true;
                AutomationMaster.Arbiter.SendCommunication(string.Format("{{\"manual_set_buddy_{0}\":\"{1}\"}}", _isPrimaryBuddy ? "primary" : "secondary", _chooseBuddyFromHistory && _buddyHistory.Any() ? _buddyHistory[_buddySelection] : _newBuddyName));
            }

            EditorGUILayout.Space();
        }
コード例 #2
0
        public IEnumerator RunBuddySystemTests()
        {
            //If a relationship has not yet been established, then cancel BuddySystem execution. This is not used if IgnoreAllBuddyTests flag set.
            BuddySystemHandlingStarted = true;
            _isBuddySystemFailure      = string.IsNullOrEmpty(BuddyName);

            if (!AutomationMaster.IgnoreAllBuddyTests)
            {
                //If allowed, and Buddy is not yet set, then set Buddy to last-used Buddy.
            #if UNITY_EDITOR
                if (AutomationMaster.ConfigReader.GetBool("EDITOR_DEFAULT_BUDDY_TO_LAST"))
                {
                    string mostRecentBuddy = AutomationReport.GetMostRecentBuddy();
                    if (!string.IsNullOrEmpty(mostRecentBuddy))
                    {
                        BuddyName = mostRecentBuddy;
                    }
                }
            #endif

                if (_isBuddySystemFailure)
                {
                    _failureReason = "Buddy was not set before BuddySystem test execution started.";
                }

                if (!_isBuddySystemFailure)
                {
                    AutoConsole.PostMessage("Establishing Connection With Buddy", MessageLevel.Abridged);
                    do
                    {
                        if (RoleGridLock)
                        {
                            _isBuddySystemFailure = true;
                            _failureReason        = "This client and the associated Buddy client share the same role (primary/secondary). One must be a primary Buddy, and the other a secondary Buddy.";
                            break;
                        }

                        SendBuddyCommunication("buddy_ready_for_tests", IsPrimary ? "primary" : "secondary");
                        yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                        time += 5;
                    } while((!_isBuddyReadyForBuddyTests || !HasBuddyAcknowledgedOurReadiness) && time <= timeout);
                    AutoConsole.PostMessage(time > timeout ? "Buddy Connection Failure": "Buddy Connection Established", MessageLevel.Abridged);

                    if (IsPrimary && !BuddyTestRequiredDetails.Any())
                    {
                        //If this client is the Primary, and has not yet recieved its required information from the Secondary, request it.
                        for (int limit = 30; limit >= 0; limit--)
                        {
                            if (!BuddyTestRequiredDetails.Any())
                            {
                                break;
                            }

                            SendBuddyCommunication("buddy_requesting_required_details", "0");
                            yield return(StartCoroutine(Q.driver.WaitRealTime(1)));
                        }
                    }

                    if (time >= timeout || (IsPrimary && !BuddyTestRequiredDetails.Any()))
                    {
                        _isBuddySystemFailure = true;
                        _failureReason        = "Timed out waiting for Buddy to be ready for multi-client testing.";
                    }

                    if (!_isBuddySystemFailure)
                    {
                        SendBasicBuddyDetails();

                        if (_isPrimary)
                        {
                            yield return(StartCoroutine(PrimaryBuddyTestRun()));

                            if (!_isBuddySystemFailure)
                            {
                                ResetBuddySystemValues();
                                yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                                SendBuddyCommunication("buddy_switching_roles", "0");

                                timeout = 300;
                                time    = 0;
                                while (!BuddyHasSuccessfullySwitchRoles && time <= timeout)
                                {
                                    yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                                    SendBuddyCommunication("buddy_primary_complete_action_tests", "0");
                                    time += 5;
                                }
                                if (time > timeout)
                                {
                                    _isBuddySystemFailure = true;
                                    _failureReason        = "Timed out waiting for Buddy to switch roles from Secondary to Primary.";
                                }
                                else
                                {
                                    AutoConsole.PostMessage("Switching Roles With Buddy", MessageLevel.Abridged);
                                    yield return(StartCoroutine(SecondaryBuddyTestRun()));
                                }
                            }
                        }
                        else
                        {
                            yield return(StartCoroutine(SecondaryBuddyTestRun()));

                            if (!_isBuddySystemFailure)
                            {
                                ResetBuddySystemValues();
                                yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                                SendBuddyCommunication("buddy_switching_roles", "0");

                                timeout = 300;
                                time    = 0;
                                while (!BuddyHasSuccessfullySwitchRoles && time <= timeout)
                                {
                                    yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                                    SendBuddyCommunication("buddy_secondary_tests_complete", "0");
                                    time += 5;
                                }
                                if (time > timeout)
                                {
                                    _isBuddySystemFailure = true;
                                    _failureReason        = "Timed out waiting for Buddy to switch roles from Primary to Secondary.";
                                }
                                else
                                {
                                    AutoConsole.PostMessage("Switching Roles With Buddy", MessageLevel.Abridged);
                                    yield return(StartCoroutine(PrimaryBuddyTestRun()));
                                }
                            }
                        }

                        SendBuddyCommunication("buddy_tearing_down", "0");
                        yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                        SendBuddyCommunication("buddy_tearing_down", "0");
                    }
                }
            }

            if (_isBuddySystemFailure || AutomationMaster.IgnoreAllBuddyTests)
            {
                //Fail all remaining tests.
                string errorMessage = string.Format("BuddySystem failure. Reason: {0} Skipping BuddySystem tests.", _failureReason);
                AutoConsole.PostMessage(errorMessage, MessageLevel.Abridged);
                for (int f = 0; f < _buddies.Count; f++)
                {
                    if (!HandledBuddyTests.Contains(_buddies[f].Key.Key))
                    {
                        AutomationMaster.CurrentTestContext = new TestContext();
                        if (!AutomationMaster.Methods.KeyValListContainsKey(_buddies[f].Key.Key))
                        {
                            AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(_buddies[f].Key.Key, Buddies[f].Key.Value));
                        }
                    }

                    yield return(StartCoroutine(Master.LaunchSingleTest(_buddies[f].Key, AutomationMaster.Methods.Count - 1, AutomationMaster.IgnoreAllBuddyTests ? TestStatus.Ignore : TestStatus.Fail, errorMessage)));

                    for (int fr = 0; fr < _buddies[f].Value.Count; fr++)
                    {
                        if (HandledBuddyTests.Contains(Buddies[f].Value[fr].Value.Name))
                        {
                            continue;
                        }
                        AutomationMaster.CurrentTestContext = new TestContext();
                        if (!AutomationMaster.Methods.KeyValListContainsKey(_buddies[f].Value[fr].Key))
                        {
                            AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(_buddies[f].Value[fr].Key, Buddies[f].Value[fr].Value));
                        }
                        yield return(StartCoroutine(Master.LaunchSingleTest(_buddies[f].Value[fr], AutomationMaster.Methods.Count - 1, AutomationMaster.IgnoreAllBuddyTests ? TestStatus.Ignore : TestStatus.Fail, errorMessage)));
                    }
                }
            }

            HandledBuddyTests = new List <string>();
            ResetBuddySystemValues();

            yield return(null);
        }