public void Lync_FabricExitedHandlerShouldNotCrash() { using (var deployment = LyncScenarioTestHelper.CreateDeployment("Lync_FabricExitedCrashTest")) { using (var hostInfo = new LyncScenarioTestHelper.LyncHostInfo(deployment.Nodes.First(), Enumerable.Empty <Type>(), true)) { // let the host come up LogHelper.Log("Starting processes"); hostInfo.StartProcess(deployment.TestOutputPath, "exitnotification_crash"); // kill the fabric node LogHelper.Log("Killing fabric.exe"); deployment.Nodes.First().Dispose(); // assert that the host received the notification Assert.IsTrue(MiscUtility.WaitUntil(() => hostInfo.QueryHasFabricExited(), TimeSpan.FromSeconds(5), 200)); // wait for a little while Thread.Sleep(2000); // assert that the host is still up and has not crashed Assert.IsFalse(hostInfo.Process.HasExited); LogHelper.Log("Stopping Host"); hostInfo.StopProcess(); } } }
public void Lync_FabricExitedNotification() { const int hostCount = 10; bool hasFabricExited = false; using (var deployment = LyncScenarioTestHelper.CreateDeployment("Lync_FabricExitedNotification")) { var lyncHostList = new List <LyncScenarioTestHelper.LyncHostInfo>(); for (int i = 0; i < hostCount; i++) { lyncHostList.Add(new LyncScenarioTestHelper.LyncHostInfo(deployment.Nodes.First(), Enumerable.Empty <Type>(), false)); } // let the host come up LogHelper.Log("Starting processes"); for (int i = 0; i < hostCount; i++) { lyncHostList[i].StartProcess(deployment.TestOutputPath, "exitnotification_" + i.ToString()); } // kill the fabric node LogHelper.Log("Killing fabric.exe"); deployment.Nodes.First().Dispose(); // assert that the host received the notification MiscUtility.WaitUntil(() => { LogHelper.Log("Querying host"); hasFabricExited = Enumerable.All(lyncHostList, e => e.QueryHasFabricExited()); return(hasFabricExited); }, TimeSpan.FromSeconds(5), 200); LogHelper.Log("Stopping Host"); lyncHostList.ForEach(e => e.StopProcess()); LogHelper.Log("Dispose"); lyncHostList.ForEach(e => e.Dispose()); } Assert.IsTrue(hasFabricExited); }
private void TestHelper(Type serviceImplementationType, Func <ServiceDescription> serviceDescriptionFactory) { // create a fabric deployment (happens in the class Init/CLeanup) // define a folder where the service will write data // start the host exe // create the service and pass folder via init data (the service in its OnOpen will write "open" to a text file in the folder and "close" in OnClose) // wait till the output folder contains some data (i.e. service starts up) // delete the service // wait till output folder contains the close line // tell the host to unregister and stop // validate that no error occurred and host terminated gracefully // this is the path where the service will write its code string serviceOutputPath = Path.Combine(Lync_ActivationDeactivationTest.deployment.TestOutputPath, serviceImplementationType.Name); FileUtility.CreateDirectoryIfNotExists(serviceOutputPath); // start the host // we know that the cluster has one node so just put the host on the first node LogHelper.Log("Starting host"); using (var lyncHost = new LyncScenarioTestHelper.LyncHostInfo(deployment.Nodes.First(), new Type[] { serviceImplementationType }, false)) { lyncHost.StartProcess(Lync_ActivationDeactivationTest.deployment.TestOutputPath, serviceImplementationType.Name + "_host.txt"); // create the service FabricClient client = new FabricClient(deployment.ClientConnectionAddresses.Select(e => e.ToString()).ToArray()); var sd = serviceDescriptionFactory(); sd.InitializationData = Encoding.UTF8.GetBytes(serviceOutputPath); sd.ServiceName = new Uri(string.Format("fabric:/my_app/{0}", serviceImplementationType.Name)); sd.ServiceTypeName = serviceImplementationType.Name; sd.PartitionSchemeDescription = new SingletonPartitionSchemeDescription(); LogHelper.Log("Creating service"); deployment.CreateService(sd); // wait for the service to come up // when the service comes up it just writes some content to a text file LogHelper.Log("Waiting for service to start"); Assert.IsTrue(MiscUtility.WaitUntil(() => Directory.GetFiles(serviceOutputPath).Length > 0, TimeSpan.FromSeconds(120))); // delete the service deployment.DeleteService(sd.ServiceName); // wait for the service to get deleted // when closeAsync is called it writes some text to a text file string[] contents = null; Assert.IsTrue( MiscUtility.WaitUntil( () => { return(FileUtility.TryReadAllLines(Directory.GetFiles(serviceOutputPath)[0], out contents) && contents.Length == 2); }, TimeSpan.FromSeconds(120), 250, true)); // the activation context should not be available Assert.IsFalse(lyncHost.QueryIsActivationContextAvailable()); // kill the host lyncHost.StopProcess(); // validate that the correct data was written to the file Assert.AreEqual(ServiceImplementationHelper.OpenMarker, contents[0]); Assert.AreEqual(ServiceImplementationHelper.CloseMarker, contents[1]); } }