public void TestConstructorNullSendDataDelegate() { Assert.Throws<InternalErrorException>(() => { BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(null); } ); }
public void TestConsumeNullBuildEvent() { Assert.Throws<InternalErrorException>(() => { BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(PacketProcessor); transportSink.Consume(null, 0); } ); }
public void PropertyTests() { BuildEventArgTransportSink sink = new BuildEventArgTransportSink(PacketProcessor); Assert.Null(sink.Name); string name = "Test Name"; sink.Name = name; Assert.Equal(0, string.Compare(sink.Name, name, StringComparison.OrdinalIgnoreCase)); }
public void TestConsumeMessageBuildEvent() { bool wentInHandler = false; BuildMessageEventArgs messageEvent = new BuildMessageEventArgs("My message", "Help me keyword", "Sender", MessageImportance.High); SendDataDelegate transportDelegate = delegate (INodePacket packet) { wentInHandler = true; LogMessagePacket loggingPacket = packet as LogMessagePacket; Assert.NotNull(loggingPacket); BuildMessageEventArgs messageEventFromPacket = loggingPacket.NodeBuildEvent.Value.Value as BuildMessageEventArgs; Assert.Equal(messageEventFromPacket, messageEvent); }; BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.Consume(messageEvent, 0); Assert.True(wentInHandler); // "Expected to go into transport delegate" }
public void TestConsumeBuildStartedEvent() { bool wentInHandler = false; BuildStartedEventArgs buildStarted = new BuildStartedEventArgs("Start", "Help"); SendDataDelegate transportDelegate = delegate (INodePacket packet) { wentInHandler = true; }; BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.Consume(buildStarted, 0); Assert.True(transportSink.HaveLoggedBuildStartedEvent); Assert.False(transportSink.HaveLoggedBuildFinishedEvent); Assert.False(wentInHandler); // "Expected not to go into transport delegate" }
public void TestShutDown() { SendDataDelegate transportDelegate = PacketProcessor; WeakReference weakTransportDelegateReference = new WeakReference(transportDelegate); BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate); transportSink.ShutDown(); Assert.NotNull(weakTransportDelegateReference.Target); transportDelegate = null; GC.Collect(); GC.WaitForPendingFinalizers(); // Expected shutdown to null out the sendData delegate, the two garbage collections // should have collected the sendDataDelegate causing the weak reference to die. Assert.Null(weakTransportDelegateReference.Target); // " Expected delegate to be dead" }
/// <summary> /// Handles the NodeConfiguration packet. /// </summary> private void HandleNodeConfiguration(NodeConfiguration configuration) { // Grab the system parameters. _buildParameters = configuration.BuildParameters; _buildParameters.ProjectRootElementCache = s_projectRootElementCache; // Snapshot the current environment _savedEnvironment = CommunicationsUtilities.GetEnvironmentVariables(); // Change to the startup directory try { NativeMethodsShared.SetCurrentDirectory(BuildParameters.StartupDirectory); } catch (DirectoryNotFoundException) { // Somehow the startup directory vanished. This can happen if build was started from a USB Key and it was removed. NativeMethodsShared.SetCurrentDirectory(Environment.SystemDirectory); } // Replicate the environment. First, unset any environment variables set by the previous configuration. if (_currentConfiguration != null) { foreach (string key in _currentConfiguration.BuildParameters.BuildProcessEnvironment.Keys) { Environment.SetEnvironmentVariable(key, null); } } // Now set the new environment foreach (KeyValuePair<string, string> environmentPair in _buildParameters.BuildProcessEnvironment) { Environment.SetEnvironmentVariable(environmentPair.Key, environmentPair.Value); } // We want to make sure the global project collection has the toolsets which were defined on the parent // so that any custom toolsets defined can be picked up by tasks who may use the global project collection but are // executed on the child node. ICollection<Toolset> parentToolSets = _buildParameters.ToolsetProvider.Toolsets; if (parentToolSets != null) { ProjectCollection.GlobalProjectCollection.RemoveAllToolsets(); foreach (Toolset toolSet in parentToolSets) { ProjectCollection.GlobalProjectCollection.AddToolset(toolSet); } } // Set the culture. Thread.CurrentThread.CurrentCulture = _buildParameters.Culture; Thread.CurrentThread.CurrentUICulture = _buildParameters.UICulture; // Get the node ID. _buildParameters.NodeId = configuration.NodeId; _buildParameters.IsOutOfProc = true; // And the AppDomainSetup _buildParameters.AppDomainSetup = configuration.AppDomainSetup; // Set up the logging service. LoggingServiceFactory loggingServiceFactory = new LoggingServiceFactory(LoggerMode.Asynchronous, configuration.NodeId); _componentFactories.ReplaceFactory(BuildComponentType.LoggingService, loggingServiceFactory.CreateInstance); _loggingService = _componentFactories.GetComponent(BuildComponentType.LoggingService) as ILoggingService; BuildEventArgTransportSink sink = new BuildEventArgTransportSink(SendLoggingPacket); _shutdownException = null; try { // If there are no node loggers to initialize dont do anything if (configuration.LoggerDescriptions != null && configuration.LoggerDescriptions.Length > 0) { _loggingService.InitializeNodeLoggers(configuration.LoggerDescriptions, sink, configuration.NodeId); } } catch (Exception ex) { if (ExceptionHandling.IsCriticalException(ex)) { throw; } OnEngineException(ex); } _loggingService.OnLoggingThreadException += new LoggingExceptionDelegate(OnLoggingThreadException); string forwardPropertiesFromChild = Environment.GetEnvironmentVariable("MSBUILDFORWARDPROPERTIESFROMCHILD"); string[] propertyListToSerialize = null; // Get a list of properties which should be serialized if (!String.IsNullOrEmpty(forwardPropertiesFromChild)) { propertyListToSerialize = forwardPropertiesFromChild.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } _loggingService.PropertiesToSerialize = propertyListToSerialize; _loggingService.RunningOnRemoteNode = true; string forwardAllProperties = Environment.GetEnvironmentVariable("MSBUILDFORWARDALLPROPERTIESFROMCHILD"); if (String.Equals(forwardAllProperties, "1", StringComparison.OrdinalIgnoreCase) || _buildParameters.LogInitialPropertiesAndItems) { _loggingService.SerializeAllProperties = true; } else { _loggingService.SerializeAllProperties = false; } // Now prep the buildRequestEngine for the build. _loggingContext = new NodeLoggingContext(_loggingService, configuration.NodeId, false /* inProcNode */); if (_shutdownException != null) { Exception exception; HandleShutdown(out exception); throw exception; } _buildRequestEngine.InitializeForBuild(_loggingContext); // Finally store off this configuration packet. _currentConfiguration = configuration; }
public void TestConsumeNullBuildEvent() { BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(PacketProcessor); transportSink.Consume(null, 0); }
public void TestConstructorNullSendDataDelegate() { BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(null); }