Beispiel #1
0
        public async Task StartBuild(BuildRunRequest request)
        {
            try
            {
                ReportStatus($"[{request.Build}] Staring");

                RunBuild buildInstruction = CreateBuildInstruction(request);

                string testOutput;

                using (DockerWrapper docker = new DockerWrapper())
                {
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                    //cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(60));

                    Dictionary <string, string> environmentVariable = new Dictionary <string, string>
                    {
                        { "TESTER_LISTTESTS", "true" }
                    };

                    testOutput = await docker.Run(buildInstruction.Image, environmentVariables : environmentVariable,
                                                  command : buildInstruction.Command, cancellationToken : cancellationTokenSource.Token);
                }

                List <RunTest> tests = new List <RunTest>();

                string[] testNames = testOutput.Split('\n');

                foreach (string testName in testNames)
                {
                    if (!string.IsNullOrEmpty(testName))
                    {
                        RunTest item = new RunTest
                        {
                            Build    = request.Build,
                            FullName = testName.Trim()
                        };

                        tests.Add(item);
                    }
                }

                AddTestsToDictionary(_expectedTests, tests);

                // Configure receivers
                statusMessageReceiver = ConfigureReceiver(QueueNames.Status(request.Build));
                testResultReceiver    = ConfigureReceiver(QueueNames.TestResponse(request.Build));

                // Add all the tests to the queue
                ReportStatus($"[{request.Build}] Sending Test Instructions ...");
                testInstructionSender = ConfigureSender(QueueNames.TestRequest(request.Build));
                SendTestInstructions(testInstructionSender, tests);
                ReportStatus($"[{request.Build}] Test Instructions sent.");

                // Add the build instruction to the queue
                ReportStatus($"[{request.Build}] Sending Build Instruction ...");
                buildInstructionSender = ConfigureSender(QueueNames.Build());
                buildInstructionSender.Send(buildInstruction);
                ReportStatus($"[{request.Build}] Build Instruction sent.");

                // Subscribe to the test result queue until all the tests have been completed (notifying subscribers)
                testResultReceiver.Receive <TestResult>(TestResultReceived);
                statusMessageReceiver.Receive <StatusMessage>(StatusMessageReceived);

                // Wait for tests to complete
                await TestsStillRunning(_cancellationTokenSource.Token);

                ReportStatus($"DONE");

                // Notify cubscribers that the run is complete
                _testResultMonitor.notifyComplete();
                _statusMessageMonitor.notifyComplete();
            } catch (Exception ex)
            {
                ReportError(ex.Message);
            }
        }