Esempio n. 1
0
        public IEnumerator SecondaryBuddyTestRun()
        {
            do
            {
                int timeout = 300;
                int time    = 0;
                while (!ReadyForReactionTests && time <= timeout)
                {
                    if (ReadyForReactionTests || IsPrimaryFinishedWithActionTests || PrimaryFailed || BuddyTearingDown)
                    {
                        break;
                    }

                    //Every 50 seconds, report still waiting.
                    if (time % 50 == 0)
                    {
                        AutoConsole.PostMessage(string.Format("Secondary waiting for Primary ({0}) seconds", time.ToString()), MessageLevel.Abridged);
                    }

                    yield return(StartCoroutine(Q.driver.WaitRealTime(5f)));

                    time += 5;
                }

                //If there is no primary test, then we are complete the secondary run.
                if (string.IsNullOrEmpty(CurrentPrimaryTest) || BuddyTearingDown)
                {
                    break;
                }

                SendBuddyCommunication("buddy_starting_reaction", "0");

                List <KeyValuePair <string, MethodInfo> > reactionTests = _buddies.FindAll(x => x.Key.Value.Name == CurrentPrimaryTest).First().Value.FindAll(x => {
                    BuddySystem bs = (BuddySystem)Attribute.GetCustomAttribute(x.Value, typeof(BuddySystem));
                    return(bs.buddy == Buddy.Reaction);
                });

                for (int r = 0; r < reactionTests.Count; r++)
                {
                    if (_primaryFailed)
                    {
                        //Add each test and "start" them with auto fail.
                        if (!AutomationMaster.Methods.KeyValListContainsKey(reactionTests[r].Key))
                        {
                            AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(reactionTests[r].Key, reactionTests[r].Value));
                        }
                        string errorMessage = string.Format("This BuddySystem Reaction test was skipped because its primary Action \"{0}\" failed.", CurrentPrimaryTest);
                        yield return(StartCoroutine(Master.LaunchSingleTest(reactionTests[r], AutomationMaster.Methods.Count - 1, TestStatus.Fail, errorMessage)));
                    }
                    else
                    {
                        if (HandledBuddyTests.Contains(reactionTests[r].Key))
                        {
                            continue;
                        }
                        HandledBuddyTests.Add(reactionTests[r].Key);
                        if (!AutomationMaster.Methods.KeyValListContainsKey(reactionTests[r].Key))
                        {
                            AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(reactionTests[r].Key, reactionTests[r].Value));
                        }
                        yield return(StartCoroutine(Master.LaunchSingleTest(reactionTests[r], AutomationMaster.Methods.Count - 1)));

                        SendBuddyCommunication("buddy_secondary_test_complete", reactionTests[r].Key);
                    }
                }

                ReadyForReactionTests = false;
                CurrentPrimaryTest    = string.Empty;

                //Alert buddy that reaction tests are complete.
                SendBuddyCommunication("buddy_secondary_tests_complete", "0");
                ResendAllInfoForBuddyTests();
            } while(!_isPrimaryFinishedWithActionTests);


            yield return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// While this client is in the Primary Buddy role, run Action tests, and await completion of Secondary Buddy's Reaction tests.
        /// </summary>
        /// <returns>The buddy test run.</returns>
        public IEnumerator PrimaryBuddyTestRun()
        {
            for (int b = 0; b < _buddies.Count; b++)
            {
                //Skip this method if it has already been handled.
                if (HandledBuddyTests.Contains(Buddies[b].Key.Key))
                {
                    continue;
                }

                SecondaryReactionsStarted = false; //Reset for next reaction.

                timeout = 180;
                time    = 0;

                //Retrieve any BuddyCommands for this Action test, and send them to Buddy for execution.
                BuddyCommand command = _buddies[b].Key.Value.GetCustomAttributes(typeof(BuddyCommand), false).ToList().First() as BuddyCommand;
                if (command != null)
                {
                    SendBuddyCommunication("buddy_primary_pretest_commands", string.Join("|", command.Commands.ToArray()));
                    BuddyProcessingCommands = true;
                    while (BuddyProcessingCommands && time <= timeout)
                    {
                        if (BuddyCommandExecutionFailure)
                        {
                            break;
                        }
                        //Every 50 seconds, report still waiting.
                        if (time % 50 == 0)
                        {
                            AutoConsole.PostMessage(string.Format("Primary waiting for Secondary to complete pretest commands ({0}) seconds", time.ToString()), MessageLevel.Abridged);
                        }

                        yield return(StartCoroutine(Q.driver.WaitRealTime(5)));

                        time += 5;
                    }
                }

                string errorMessage = string.Empty;
                HandledBuddyTests.Add(_buddies[b].Key.Key);
                if (!AutomationMaster.Methods.KeyValListContainsKey(Buddies[b].Key.Key))
                {
                    AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(Buddies[b].Key.Key, Buddies[b].Key.Value));
                }

                if (!BuddyCommandExecutionFailure && time <= timeout)
                {
                    //Launch Action test.
                    yield return(StartCoroutine(Master.LaunchSingleTest(Buddies[b].Key, AutomationMaster.Methods.Count - 1)));
                }
                else
                {
                    AutomationMaster.CurrentTestContext.TestInitialize(_buddies[b].Key.Value);
                    if (BuddyCommandExecutionFailure)
                    {
                        errorMessage = string.Format("The Secondary Buddy of this client failed to successfully handle the command(s) {0} required by this Action test. Commands: {1}.", BuddyCommandFailure, string.Join("|", command.Commands.ToArray()));
                    }
                    else
                    {
                        errorMessage = "Timout occurred waiting for primary buddy to complete its pretest commands.";
                    }
                    yield return(StartCoroutine(Q.assert.Fail(errorMessage, FailureContext.TestMethod)));

                    AutomationReport.AddToReport(false, 0, true); //Save results to test run's XML file.
                    Master.ReportOnTest();
                }
                ResendAllInfoForBuddyTests();
                yield return(StartCoroutine(Q.driver.WaitRealTime(2f)));

                bool actionSuccessful = AutomationMaster.CurrentTestContext.IsSuccess;
                if (actionSuccessful)
                {
                    SendBuddyCommunication("buddy_primary_test_complete", _buddies[b].Key.Value.Name);
                }
                else
                {
                    SendBuddyCommunication("buddy_primary_test_failed", _buddies[b].Key.Value.Name);
                }

                //When the buddy has completed all reaction tests, we can then move on to the next.
                timeout = 300;
                time    = 0;
                _waitingForBuddyToCompleteReactionTests = true;
                int resendCount = 4;
                while (_waitingForBuddyToCompleteReactionTests && time <= timeout)
                {
                    //Check if buddy has declared that it is running its secondary tests. If not, resend the command once.
                    if (resendCount > 0 && time > 10 && !SecondaryReactionsStarted)
                    {
                        resendCount--;
                        if (actionSuccessful)
                        {
                            SendBuddyCommunication("buddy_primary_test_complete", _buddies[b].Key.Value.Name);
                        }
                        else
                        {
                            SendBuddyCommunication("buddy_primary_test_failed", _buddies[b].Key.Value.Name);
                        }
                    }

                    //Every 50 seconds, report still waiting.
                    if (time % 50 == 0)
                    {
                        AutoConsole.PostMessage(string.Format("Primary waiting for Secondary ({0}) seconds", time.ToString()), MessageLevel.Abridged);
                    }

                    yield return(StartCoroutine(Q.driver.WaitRealTime(5f)));

                    time += 5;
                }

                //If we time out, stop the run and break out of execution.
                _isBuddySystemFailure = time >= timeout;
                if (_isBuddySystemFailure)
                {
                    _failureReason = errorMessage;
                    AutoConsole.PostMessage(_failureReason, MessageLevel.Abridged);
                    break;
                }

                //Run all CounterReaction tests for this Action.
                List <KeyValuePair <string, MethodInfo> > counterReactions = _buddies.FindAll(x => x.Key.Value.Name == _buddies[b].Key.Value.Name).First().Value.FindAll(x => {
                    BuddySystem bs = (BuddySystem)Attribute.GetCustomAttribute(x.Value, typeof(BuddySystem));
                    return(bs.buddy == Buddy.CounterReaction);
                });

                for (int c = 0; c < counterReactions.Count; c++)
                {
                    HandledBuddyTests.Add(counterReactions[c].Key);
                    if (!AutomationMaster.Methods.KeyValListContainsKey(counterReactions[c].Key))
                    {
                        AutomationMaster.Methods.Add(new KeyValuePair <string, MethodInfo>(counterReactions[c].Key, counterReactions[c].Value));
                    }
                    yield return(StartCoroutine(Master.LaunchSingleTest(counterReactions[c], AutomationMaster.Methods.Count - 1, actionSuccessful ? TestStatus.Pass : TestStatus.Fail)));
                }
            }

            SendBuddyCommunication("buddy_primary_complete_action_tests", "0");

            yield return(null);
        }