Example #1
0
        /// <summary>
        /// Creates a build request.
        /// </summary>
        private BuildRequest CreateBuildRequest(int nodeRequestId, int configId, string[] targets, NodeAffinity nodeAffinity, BuildRequest parentRequest)
        {
            HostServices hostServices = null;

            if (nodeAffinity != NodeAffinity.Any)
            {
                hostServices = new HostServices();
                hostServices.SetNodeAffinity(String.Empty, nodeAffinity);
            }

            BuildRequest request = new BuildRequest(1 /* submissionId */, nodeRequestId, configId, targets, hostServices, BuildEventContext.Invalid, parentRequest);
            return request;
        }
Example #2
0
        public void TestUnregisteringNonConflictingHostObjectRestoresOriginalAffinity()
        {
            HostServices hostServices = new HostServices();
            TestHostObject hostObject = new TestHostObject();
            hostServices.SetNodeAffinity(String.Empty, NodeAffinity.OutOfProc);
            hostServices.SetNodeAffinity("project", NodeAffinity.Any);
            Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project2"));
            Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));

            hostServices.RegisterHostObject("project", "target", "task", hostObject);
            Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project"));
            hostServices.RegisterHostObject("project", "target", "task", null);
            Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));
            Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project2"));
        }
Example #3
0
        public void TestProjectInstanceWithNonConflictingHostServices()
        {
            HostServices hostServices = new HostServices();
            ProjectInstance project = CreateDummyProject("foo.proj");

            BuildRequestData data = new BuildRequestData(project, new string[] { }, hostServices);

            hostServices.SetNodeAffinity(project.FullPath, NodeAffinity.InProc);
            BuildRequestData data2 = new BuildRequestData(project, new string[] { }, hostServices);
        }
Example #4
0
 public void TestNonContraditcoryHostObjectAllowed_InProc()
 {
     HostServices hostServices = new HostServices();
     TestHostObject hostObject = new TestHostObject();
     hostServices.SetNodeAffinity("project", NodeAffinity.InProc);
     hostServices.RegisterHostObject("project", "target", "task", hostObject);
 }
Example #5
0
 public void TestAffinityChangeAfterClearingHostObject()
 {
     HostServices hostServices = new HostServices();
     TestHostObject hostObject = new TestHostObject();
     hostServices.RegisterHostObject("project", "target", "task", hostObject);
     Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project"));
     hostServices.RegisterHostObject("project", "target", "task", null);
     Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));
     hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
     Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project"));
 }
Example #6
0
 public void TestContraditcoryHostObjectCausesException_OutOfProc()
 {
     HostServices hostServices = new HostServices();
     TestHostObject hostObject = new TestHostObject();
     hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
     hostServices.RegisterHostObject("project", "target", "task", hostObject);
 }
Example #7
0
 public void TestNonContraditcoryHostObjectAllowed_Any()
 {
     HostServices hostServices = new HostServices();
     TestHostObject hostObject = new TestHostObject();
     hostServices.SetNodeAffinity("project", NodeAffinity.Any);
     hostServices.RegisterHostObject("project", "target", "task", hostObject);
     Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project"));
 }
Example #8
0
        public void TestClearingAffinities()
        {
            HostServices hostServices = new HostServices();

            hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
            Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project"));
            hostServices.SetNodeAffinity(null, NodeAffinity.OutOfProc);
            Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));

            hostServices.SetNodeAffinity(String.Empty, NodeAffinity.OutOfProc);
            Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project"));
            hostServices.SetNodeAffinity(null, NodeAffinity.OutOfProc);
            Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));
        }
Example #9
0
 public void TestContradictoryAffinityCausesException_Any()
 {
     HostServices hostServices = new HostServices();
     TestHostObject hostObject = new TestHostObject();
     hostServices.RegisterHostObject("project", "target", "task", hostObject);
     Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project"));
     hostServices.SetNodeAffinity("project", NodeAffinity.Any);
 }
Example #10
0
        public void TestOverrideGeneralAffinityRegistration()
        {
            HostServices hostServices = new HostServices();

            hostServices.SetNodeAffinity(String.Empty, NodeAffinity.InProc);
            hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
            Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project"));
            Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project2"));
        }
Example #11
0
 public void TestDefaultAffinityWhenProjectNotRegistered()
 {
     HostServices hostServices = new HostServices();
     hostServices.SetNodeAffinity("project1", NodeAffinity.InProc);
     Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project2"));
 }
Example #12
0
 public void TestSpecificAffinityRegistration()
 {
     HostServices hostServices = new HostServices();
     hostServices.SetNodeAffinity("project", NodeAffinity.InProc);
     Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project"));
     hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
     Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project"));
     hostServices.SetNodeAffinity("project", NodeAffinity.Any);
     Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project"));
 }
Example #13
0
        public void Regress265010()
        {
            string contents = ObjectModelHelpers.CleanupFileContents(@"
<Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
 <PropertyGroup>
   <Prop>BaseValue</Prop>
 </PropertyGroup>
<ItemGroup>
  <Item Include='BaseItem'/>
</ItemGroup>
 <Target Name='BaseTest'>   
   <Message Text='[$(Prop)]'/>
   <Message Text='[@(Item)]'/>
    <PropertyGroup>
        <Prop>NewValue</Prop>
    </PropertyGroup>
    <ItemGroup>
        <Item Include='NewItem'/>
    </ItemGroup>
 </Target>

 <Target Name='MovedTest'>   
   <Message Text='[$(Prop)]'/>
   <Message Text='[@(Item)]'/>
 </Target>

</Project>
");

            string fileName = Path.GetTempFileName();
            File.WriteAllText(fileName, contents);
            _buildManager.BeginBuild(_parameters);
            try
            {
                HostServices services = new HostServices();
                services.SetNodeAffinity(fileName, NodeAffinity.OutOfProc);
                BuildRequestData data = new BuildRequestData(fileName, new Dictionary<string, string>(), ObjectModelHelpers.MSBuildDefaultToolsVersion, new[] { "BaseTest" }, services);
                _buildManager.PendBuildRequest(data).Execute();
                _logger.AssertLogContains("[BaseValue]");
                _logger.AssertLogContains("[BaseItem]");
                _logger.ClearLog();

                _parameters.ResetCaches = false;
                services.SetNodeAffinity(fileName, NodeAffinity.InProc);
                data = new BuildRequestData(fileName, new Dictionary<string, string>(), ObjectModelHelpers.MSBuildDefaultToolsVersion, new[] { "MovedTest" }, services);
                _buildManager.PendBuildRequest(data).Execute();
                _logger.AssertLogContains("[NewValue]");
                _logger.AssertLogContains("[BaseItem;NewItem]");
                _logger.AssertLogDoesntContain("[BaseValue]");
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                _buildManager.EndBuild();
            }
        }
Example #14
0
 public void TestContraditcoryHostObjectCausesException_OutOfProc()
 {
     Assert.Throws<InvalidOperationException>(() =>
     {
         HostServices hostServices = new HostServices();
         TestHostObject hostObject = new TestHostObject();
         hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc);
         hostServices.RegisterHostObject("project", "target", "task", hostObject);
     }
    );
 }