Example #1
0
        public async Task ProcessSingleBuildThatFails()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));
            var stdout = new Subject<string>();
            var allLines = stdout.CreateCollection();

            var fixture = new BuildQueue(client, cache);
            var result = default(int);
            bool shouldDie = true;

            try {
                // NB: This build fails because NuGet package restore wasn't set 
                // up properly, so MSBuild is missing a ton of assemblies
                result = await fixture.ProcessSingleBuild(new BuildQueueItem() {
                    BuildId = 1,
                    BuildScriptUrl = TestBuild.BuildScriptUrl,
                    RepoUrl = TestBuild.RepoUrl,
                    SHA1 = TestBuild.FailingBecauseOfMsbuildSHA1,
                }, stdout);
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                shouldDie = false;
            }

            var output = allLines.Aggregate(new StringBuilder(), (acc, x) => { acc.AppendLine(x); return acc; }).ToString();
            Console.WriteLine(output);

            Assert.False(shouldDie);
        }
        public void EmptyBuildQueueShouldDeserialize()
        {
            var original = new BuildQueue();

            var restored = SerializeAndDeserialize(original);

            restored.Should().BeEquivalentTo(original);
        }
Example #3
0
 public void ConstructorDoesNotAllowNullClient()
 {
     try
     {
         var queue = new BuildQueue(null, null, null);
         Assert.Fail("ArgumentNullException was expected");
     }
     catch (ArgumentNullException) { }
 }
Example #4
0
        public void ServerReturnsUnderlyingServer()
        {
            var client = mocks.Create <CruiseServerClientBase>().Object;
            var server = InitialiseServer();
            var status = new QueueSnapshot();
            var queue  = new BuildQueue(client, server, status);

            Assert.AreSame(server, queue.Server);
        }
        public void ServerReturnsUnderlyingServer()
        {
            var client = mocks.DynamicMock <CruiseServerClientBase>();
            var server = InitialiseServer();
            var status = new QueueSnapshot();
            var queue  = new BuildQueue(client, server, status);

            mocks.ReplayAll();
            Assert.AreSame(server, queue.Server);
        }
Example #6
0
        public async Task FullBuildIntegrationTest()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache);
            using (fixture.Start()) {
                var result = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);
            }
        }
Example #7
0
        public void ConstructorDoesNotAllowNullServer()
        {
            var client = mocks.Create <CruiseServerClientBase>().Object;

            try
            {
                var queue = new BuildQueue(client, null, null);
                Assert.Fail("ArgumentNullException was expected");
            }
            catch (ArgumentNullException) { }
        }
Example #8
0
        public void NameReturnsQueueNameFromSnapshot()
        {
            var client = mocks.Create <CruiseServerClientBase>().Object;
            var server = InitialiseServer();
            var status = new QueueSnapshot {
                QueueName = "Test BuildQueue"
            };
            var queue = new BuildQueue(client, server, status);

            Assert.AreEqual(status.QueueName, queue.Name);
        }
        public void ConstructorSetsBuildQueue()
        {
            var mocks   = new MockRepository(MockBehavior.Default);
            var client  = mocks.Create <CruiseServerClientBase>().Object;
            var watcher = mocks.Create <IServerWatcher>().Object;
            var monitor = new Server(client, watcher);
            var queue   = new BuildQueue(client, monitor, new QueueSnapshot());
            var args    = new BuildQueueChangedArgs(queue);

            Assert.AreSame(queue, args.BuildQueue);
        }
Example #10
0
        public void ConstructorSetsBuildQueue()
        {
            var mocks   = new MockRepository();
            var client  = mocks.DynamicMock <CruiseServerClientBase>();
            var watcher = mocks.Stub <IServerWatcher>();
            var monitor = new Server(client, watcher);
            var queue   = new BuildQueue(client, monitor, new QueueSnapshot());
            var args    = new BuildQueueChangedArgs(queue);

            Assert.AreSame(queue, args.BuildQueue);
        }
        public void ConstructorDoesNotAllowNullServer()
        {
            var client = mocks.DynamicMock <CruiseServerClientBase>();

            mocks.ReplayAll();
            try
            {
                var queue = new BuildQueue(client, null, null);
                Assert.Fail("ArgumentNullException was expected");
            }
            catch (ArgumentNullException) { }
        }
        public void PopulatedBuildQueueShouldDeserialize()
        {
            var original = new BuildQueue();

            original.Items.Add(new BuildQueueItem(BuildMenuItem.ColonyShip)
            {
                Invested = 10
            });
            original.Items.Add(new BuildQueueItem(BuildMenuItem.ScoutShip));

            var restored = SerializeAndDeserialize(original);

            restored.Should().BeEquivalentTo(original);
        }
Example #13
0
        public BuildServer(Options options)
        {
            Options      = options;
            Projects     = new List <Project>();
            BuildAgents  = new List <RemoteBuildAgent>();
            BuildQueue   = new BuildQueue();
            GithubPoller = new GithubPoller(Projects, Options.Username,
                                            Options.Token);
            GithubPoller.RepositoryChanged += OnRepositoryChange;

            Database = new Database(options.Database);
            Database.LoadProjects(Projects);
            Database.LoadBuilds();
        }
Example #14
0
 public void RequestsReturnsRequestsFromStatus()
 {
     var client = mocks.Create <CruiseServerClientBase>().Object;
     var server = InitialiseServer();
     var status = new QueueSnapshot
     {
         Requests =
         {
             new QueuedRequestSnapshot {
                 ProjectName = "Project 1"
             }
         }
     };
     var queue = new BuildQueue(client, server, status);
 }
Example #15
0
        public void UpdateValidatesArguments()
        {
            var client = mocks.Create <CruiseServerClientBase>().Object;
            var server = InitialiseServer();
            var status = new QueueSnapshot {
                QueueName = "Testing"
            };
            var queue = new BuildQueue(client, server, status);

            try
            {
                queue.Update(null);
                Assert.Fail("ArgumentNullException was expected");
            }
            catch (ArgumentNullException) { }
        }
Example #16
0
        public void Setup()
        {
            if (Log == null)
            {
                Log = new ConsoleLog();
            }

            if (Options.OutputDir == null)
            {
                Options.OutputDir = Directory.GetCurrentDirectory();
            }

            Queue               = new BuildQueue();
            Queue.BuildAdded   += BuildAdded;
            Queue.BuildRemoved += BuildRemoved;
        }
Example #17
0
    public override IEnumerator Perform()
    {
        ObjectDefinition buildDefinition = GameObject.GetComponent <ObjectDefinition>();

        ResourceResolver resources = Owner.GetComponent <ResourceResolver>();

        BuildQueue queue = Owner.GetComponent <BuildQueue>();

        queue.OnBuildComplete += BuildComplete;

        if (resources.CanAfford(buildDefinition))
        {
            resources.Spend(buildDefinition);

            queue.Add(GameObject, Position, buildDefinition.BuildTime, PostBuildAction);
        }

        yield return(0);
    }
        public void UpdateFiresPropertyChangedWhenMessageIsRemoved()
        {
            mocks = new MockRepository();
            var client = mocks.DynamicMock <CruiseServerClientBase>();
            var server = InitialiseServer();
            var status = new QueueSnapshot
            {
                Requests =
                {
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 1"
                    },
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 2"
                    }
                }
            };
            var queue = new BuildQueue(client, server, status);

            mocks.ReplayAll();
            var eventFired = false;

            queue.Update(status);

            var newStatus = new QueueSnapshot
            {
                Requests =
                {
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 2"
                    }
                }
            };

            queue.BuildQueueRequestRemoved += (o, e) =>
            {
                eventFired = true;
            };
            queue.Update(newStatus);
            Assert.IsTrue(eventFired, "BuildQueueRequestRemoved for Requests change not fired");
        }
Example #19
0
        public async Task ProcessSingleBuildIntegrationTest()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));
            var stdout = new Subject<string>();
            var allLines = stdout.CreateCollection();

            var fixture = new BuildQueue(client, cache);
            var result = await fixture.ProcessSingleBuild(new BuildQueueItem() {
                BuildId = 1,
                BuildScriptUrl = TestBuild.BuildScriptUrl,
                RepoUrl = TestBuild.RepoUrl,
                SHA1 = TestBuild.PassingBuildSHA1,
            }, stdout);

            var output = allLines.Aggregate(new StringBuilder(), (acc, x) => { acc.AppendLine(x); return acc; }).ToString();
            Console.WriteLine(output);

            Assert.Equal(0, result);
            Assert.False(String.IsNullOrWhiteSpace(output));
        }
Example #20
0
        public void UpdateFiresPropertyChangedWhenMessageIsAdded()
        {
            mocks = new MockRepository(MockBehavior.Default);
            var client = mocks.Create <CruiseServerClientBase>().Object;
            var server = InitialiseServer();
            var status = new QueueSnapshot
            {
                Requests =
                {
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 1"
                    }
                }
            };
            var queue      = new BuildQueue(client, server, status);
            var eventFired = false;

            var newStatus = new QueueSnapshot
            {
                Requests =
                {
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 1"
                    },
                    new QueuedRequestSnapshot {
                        ProjectName = "Project 2"
                    }
                }
            };

            queue.BuildQueueRequestAdded += (o, e) =>
            {
                eventFired = true;
            };
            queue.Update(newStatus);
            Assert.IsTrue(eventFired, "BuildQueueRequestAdded for Requests change not fired");
        }
Example #21
0
        public static async Task StartBuildAsync(
            EnvDTE.Project project,
            string projectPath,
            string configName,
            Dictionary <string, string> properties,
            IEnumerable <string> targets,
            LoggerVerbosity verbosity)
        {
            if (project == null)
            {
                throw new ArgumentException("Project cannot be null.");
            }
            if (configName == null)
            {
                throw new ArgumentException("Configuration name cannot be null.");
            }

            RequestTimer.Restart();
            var tracker = QtProjectTracker.Get(project, projectPath);
            await tracker.Initialized;

            if (QtVsToolsPackage.Instance.Options.BuildDebugInformation)
            {
                Messages.Print(string.Format(
                                   "{0:HH:mm:ss.FFF} QtProjectBuild({1}): Request [{2}] {3}",
                                   DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                   configName, tracker.UnconfiguredProject.FullPath));
            }

            var knownConfigs = await tracker.UnconfiguredProject.Services
                               .ProjectConfigurationsService.GetKnownProjectConfigurationsAsync();

            ConfiguredProject configuredProject = null;

            foreach (var config in knownConfigs)
            {
                var configProject = await tracker.UnconfiguredProject
                                    .LoadConfiguredProjectAsync(config);

                if (configProject.ProjectConfiguration.Name == configName)
                {
                    configuredProject = configProject;
                    break;
                }
            }
            if (configuredProject == null)
            {
                throw new ArgumentException(string.Format("Unknown configuration '{0}'.", configName));
            }

            BuildQueue.Enqueue(new QtProjectBuild()
            {
                Project             = project,
                VcProject           = tracker.VcProject,
                UnconfiguredProject = tracker.UnconfiguredProject,
                ConfiguredProject   = configuredProject,
                Properties          = properties?.ToDictionary(x => x.Key, x => x.Value),
                Targets             = targets?.ToList(),
                LoggerVerbosity     = verbosity
            });
            StaticThreadSafeInit(() => BuildDispatcher,
                                 () => BuildDispatcher = Task.Run(BuildDispatcherLoopAsync))
            .Forget();
        }
Example #22
0
        public async Task BuildsThatSucceedShouldBeRecorded()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, (q, o) => {
                return Task.FromResult(0);
            });

            fixture.Start();

            var queueItem = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);

            Assert.NotNull(queueItem);
            Assert.True(queueItem.BuildSucceded.Value);

            fixture = new BuildQueue(client, cache);
            var result = await fixture.GetBuildOutput(queueItem.BuildId);

            Assert.Equal(0, result.Item2);
        }
Example #23
0
        public async Task BuildOutputForUnknownBuildsShouldThrow()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, (q, o) => {
                return Task.FromResult(0);
            });

            bool shouldDie = true;
            try {
                await fixture.GetBuildOutput(42);
            } catch (Exception) {
                shouldDie = false;
            }

            Assert.False(shouldDie);
        }
Example #24
0
        public async Task BuildsThatFailShouldBeRecorded()
        {
            var cache = new TestBlobCache();
            var client = new GitHubClient(new ProductHeaderValue("Peasant"));

            var fixture = new BuildQueue(client, cache, async (q, o) => {
                throw new Exception("Didn't work lol");
            });

            fixture.Start();

            var queueItem = await fixture.Enqueue(TestBuild.RepoUrl, TestBuild.PassingBuildSHA1, TestBuild.BuildScriptUrl);

            Assert.NotNull(queueItem);
            Assert.False(queueItem.BuildSucceded.Value);

            fixture = new BuildQueue(client, cache);
            var result = await fixture.GetBuildOutput(queueItem.BuildId);

            Assert.True(result.Item1.Contains("Didn't work lol"));
            Assert.NotEqual(0, result.Item2);
        }
Example #25
0
 public static void Reset()
 {
     BuildQueue.Clear();
 }
Example #26
0
    public void AnimateBuildTimeFirstQueue(float buildTime)
    {
        BuildQueue firstQueue = queuesParent.GetChild(0).GetComponent <BuildQueue>();

        firstQueue.AnimateBuildTime(buildTime);
    }