public IEnumerator BuddySystemTest_Action() { string requiredValue = "I AM A BUDDY PRIMARY"; BuddyHandler.SendInfoForBuddyTests("REQUIRED_VALUE", requiredValue); yield return(StartCoroutine(Q.driver.WaitRealTime(1))); }
public IEnumerator BuddySystemTest_Reaction() { //Verify that the required test data was passed from the Primary buddy to the Secondary Buddy. string expectedValue = BuddyHandler.GetValueFromBuddyPrimaryTestForSecondaryTest("REQUIRED_VALUE"); yield return(StartCoroutine(Q.assert.IsTrue(expectedValue == "I AM A BUDDY PRIMARY", "Buddy primary failed to provide required information for secondary reaction test."))); yield return(StartCoroutine(Q.driver.WaitRealTime(1))); }
/// <summary> /// Handles incoming pubsub messages. Expects JSON format. /// </summary> public IEnumerator HandleMessage(string result) { //Ignore duplicate or empty messages. Ignore messages not meant for this client. if (lastMessageReceived == result || string.IsNullOrEmpty(result.Trim())) { yield break; } lastMessageReceived = result; List <KeyValuePair <string, string> > parameters = DeserializeJsonString(result); if (!LocalRunLaunch) { //If no context or identity is provided, then this is not a valid command. If the DeviceUdid is not valid, then ignore the command. if (!parameters.FindAll(x => x.Key.ToLower() == "grid_source").Any() || !parameters.FindAll(x => x.Key.ToLower() == "grid_identity").Any()) { yield break; } string source = parameters.Find(x => x.Key == "grid_source").Value; string identity = parameters.Find(x => x.Key == "grid_identity").Value; string buddy = parameters.Find(x => x.Key == "grid_identity_buddy").Value; //If message simply contains no reference to this GridIdentity OR the identity is self, then it is chatter and can be ignored. bool isChatter = !result.Contains(GridIdentity); bool isInvalid = string.IsNullOrEmpty(TestRunId) ? !parameters.FindAll(x => x.Key == "set_test_run_id").Any() : parameters.FindAll(x => x.Key == "test_run_id").Any() && TestRunId != parameters.Find(x => x.Key == "test_run_id").Value; bool isEcho = identity == GridIdentity && source == "client"; //If message is from a client source where the identity is not that of this client, but contains this client's identity, then this it is a BuddySystem message. bool isBuddyMessage = source != "server" && parameters.FindAll(x => x.Key.StartsWith("buddy_")).Any() && buddy == GridIdentity && identity == BuddyHandler.BuddyName; //If this message is meant for a different client, or is an echo from the current client, simply ignore the message. if (!isBuddyMessage && (isChatter || isEcho || isInvalid)) { yield break; } } else if (!LocalRunLaunch && parameters.FindAll(x => x.Key.ToLower() == "grid_identity").Any() ? parameters.Find(x => x.Key == "grid_identity").Value != GridIdentity : false) { yield break; } LastMessage = DateTime.Now; if (parameters.Count > 0) { //Process each command. for (int c = 0; c < parameters.Count; c++) { string command = parameters[c].Key.ToLower(); string message = parameters[c].Value.TrimEnd(','); bool isRecognizedCommand = true; switch (command.ToLower()) { case "change_connection_strategy": AutomationMaster.ConnectionStrategy.ChangeConnectionStrategy(message); break; case "change_communications_identity": AutomationMaster.ConnectionStrategy.UpdateChannelIdentity(message); break; case "no_interval_screenshots": AutomationMaster.NoIntervalScreenshots = true; break; case "ignore_memory_tracking": AutomationMaster.IgnoreMemoryTracking = true; break; case "health_check": SendCommunication(string.Format("heartbeat_{0}", (++AutomationMaster.HeartBeatIndex).ToString(), "0")); break; case "buddy_ignore_all": AutomationMaster.IgnoreAllBuddyTests = true; AutomationMaster.LockIgnoreBuddyTestsFlag = true; //Prevents Test editor window from implicitly updating the Ignore flag. break; case "buddy_ready_for_tests": //TODO: Refactor and re-add GRIDLOCK logic. Without it, BuddySystem will not informatively report that both buddies are reporting as the same role. //if((BuddyHandler.IsPrimary && message == "primary") || (!BuddyHandler.IsPrimary && message == "secondary")) { //Gridlock. One client must be the primary, and one must be the secondary. //SendCommunication("buddy_gridlock_detected", "0"); //BuddyHandler.RoleGridLock = true; //} else { SendCommunication("buddy_ready_for_tests_acknowledged", BuddyHandler.IsPrimary ? "primary" : "secondary"); BuddyHandler.IsBuddyReadyForBuddyTests = true; //} break; case "buddy_ready_for_tests_acknowledged": BuddyHandler.HasBuddyAcknowledgedOurReadiness = true; break; case "buddy_switching_roles": BuddyHandler.BuddyHasSuccessfullySwitchRoles = true; break; case "buddy_requesting_required_details": //Send/Resend details required by Primary Buddy. BuddyHandler.SendBasicBuddyDetails(); break; case "buddy_starting_reaction": BuddyHandler.SecondaryReactionsStarted = true; break; case "buddy_tearing_down": BuddyHandler.BuddyTearingDown = true; break; case "buddy_data_update": BuddyHandler.SetCurrentBuddyRequiredDetails(message); break; case "buddy_primary_test_complete": BuddyHandler.CurrentPrimaryTest = message; BuddyHandler.ReadyForReactionTests = true; BuddyHandler.SendBuddyCommunication("buddy_xyz", string.Format("Buddy Primary Test Completion ({0}) Acknowledged ({1}) %%%%", BuddyHandler.CurrentPrimaryTest, BuddyHandler.ReadyForReactionTests)); break; case "buddy_primary_pretest_commands": AutomationMaster.BuddyHandler.PreTestCommandReceived(message); break; case "buddy_secondary_pretest_commands_complete": BuddyHandler.BuddyProcessingCommands = false; break; case "buddy_secondary_pretest_commands_failure": BuddyHandler.BuddyCommandExecutionFailure = true; BuddyHandler.BuddyProcessingCommands = false; BuddyHandler.BuddyCommandFailure = message; break; case "buddy_secondary_tests_complete": BuddyHandler.WaitingForBuddyToCompleteReactionTests = false; break; case "buddy_primary_test_failed": BuddyHandler.PrimaryFailed = true; break; case "buddy_primary_complete_action_tests": BuddyHandler.IsPrimaryFinishedWithActionTests = true; break; case "loop_tests": //This command should be sent before or at the same time as the run command. Sending it after may result in failing to have the desired effect. List <KeyValuePair <string, int> > loopTests = new List <KeyValuePair <string, int> >(); List <string> RawRequests = message.Split(AutomationMaster.DELIMITER).ToList(); for (int x = 0; x < RawRequests.Count; x++) { string testName = RawRequests[x].Split('@').First(); string count = RawRequests[x].Split('@').Last(); if (RawRequests[x].Split('@').ToList().Count != 2 || count.ToInt() == 0) { AutoConsole.PostMessage("Provided loop_tests command is invalid. The value must be a string and then integer, separated by an @ symbol."); continue; } loopTests.Add(new KeyValuePair <string, int>(testName, count.ToInt())); } AutomationMaster.LoopTests = loopTests; break; case "request_response": switch (message) { case "screenshot": AutomationMaster.AwaitingScreenshot = false; break; default: break; } break; case "request_buddy": //AutomationMaster.BuddyRequest(message, "newbuddy"); break; case "set_test_run_id": TestRunId = message; break; case "manual_set_buddy_primary": BuddyHandler.BuddyName = message; BuddyHandler.IsPrimary = true; BuddyHandler.SendBasicBuddyDetails(); BuddyIdentity = message; break; case "manual_set_buddy_secondary": BuddyHandler.BuddyName = message; BuddyHandler.IsPrimary = false; BuddyHandler.SendBasicBuddyDetails(); BuddyIdentity = message; break; case "no_test_rails_reporting": AutomationReport.IgnoreTestRailsReporting = true; break; case "server_heartbeat": AutomationMaster.ServerHeartbeatReceived(); break; case "console_command": List <string> commands = message.Trim().Split('|').ToList(); for (int co = 0; co < commands.Count; co++) { string com = string.Format("{0} {1}", commands[co].Split('$').First(), commands[co].Split('$').Last()); Q.SendConsoleCommand(com); AutoConsole.PostMessage(string.Format("Ran Command: {0}", com), MessageLevel.Abridged); } break; case "server_broker_response": Q.request.CommandResponseReceived(message); break; case "automation_command": if (AutomationMaster.Busy) { SendCommunication("Notification", "Busy completing previous test run."); break; } SendCommunication("Notification", "Beginning pre-run checks."); if (parameters.Find(x => x.Key == "grid_source").Value == "server") { AutomationMaster.IsServerListening = true; } //Incoming server-based runs will require the carrot before "rt all", for example, to run unit tests instead of automation. if (message.StartsWith("^")) { AutomationMaster.UnitTestMode = true; } yield return(StartCoroutine(Q.driver.WaitRealTime(1))); AutomationMaster.Busy = true; AutomationMaster.LockIgnoreBuddyTestsFlag = true; //Split string and discard only command prefix. Also allows for spaces in test Category names. message = message.TrimStart().TrimEnd().Replace(", ", ",").Split(new char[] { ' ' }, 2)[1].Trim().ToLower(); if (message == "all") { AutomationMaster.LaunchType = LaunchType.All; } else if (message.StartsWith("*") && message.Contains(",")) { message = message.Replace("*", string.Empty); AutomationMaster.LaunchType = LaunchType.MultipleMethodNames; } else if (message.StartsWith("*")) { message = message.Replace("*", string.Empty); AutomationMaster.LaunchType = LaunchType.MethodName; } else if (message.StartsWith("&&")) { message = message.Replace("&&", string.Empty); AutomationMaster.LaunchType = LaunchType.Mix; } else if (message.Contains(",")) { AutomationMaster.LaunchType = LaunchType.MultipleCategoryNames; } else { AutomationMaster.LaunchType = LaunchType.CategoryName; } //Wait until loading of game is complete to attempt a launch of the automation suite yield return(StartCoroutine(Q.game.WaitForGameLoadingComplete())); StartCoroutine(AutomationMaster.StaticSelfComponent.BeginTestLaunch(message)); break; case "buddy_secondary_test_complete": case "buddy_requesting_value_ready": case "buddy_setting_ready_to": //Commands that do not require any action, but should be considered valid for logging purposes (isRecognizedCommand). break; default: isRecognizedCommand = false; break; } Arbiter.LocalRunLaunch = false; if (isRecognizedCommand && !string.IsNullOrEmpty(message)) { AutoConsole.PostMessage(string.Format("SENDER [{0}] - COMMAND [{1}] - MESSAGE [{2}]", parameters.Find(x => x.Key == "grid_identity").Value, command, message), ConsoleMessageType.Pubsub); } } } }