Esempio n. 1
0
 private static void ConnectToImageServer()
 {
     // Use connection router to connect back to image tester
     // Connect during startup, so that first test timing is not affected by initial connection
     try
     {
         var imageServerSocket = RouterClient.RequestServer($"/redirect/{ImageTester.XenkoImageServerHost}/{ImageTester.XenkoImageServerPort}").Result;
         ImageTester.Connect(imageServerSocket);
     }
     catch (Exception e)
     {
         Logger.Error("Error connecting to image tester server: {0}", e);
     }
 }
        private void RunTests()
        {
            var serverAddresses = Intent.GetStringExtra(TestRunner.ParadoxServerIp);
            var serverPort      = Int32.Parse(Intent.GetStringExtra(TestRunner.ParadoxServerPort) ?? "8080");
            var buildNumber     = Int32.Parse(Intent.GetStringExtra(TestRunner.ParadoxBuildNumber) ?? "-1");
            var branchName      = Intent.GetStringExtra(TestRunner.ParadoxBranchName) ?? "";

            // Remove extra (if activity is recreated)
            Intent.RemoveExtra(TestRunner.ParadoxServerIp);
            Intent.RemoveExtra(TestRunner.ParadoxServerPort);
            Intent.RemoveExtra(TestRunner.ParadoxBuildNumber);
            Intent.RemoveExtra(TestRunner.ParadoxBranchName);


            Logger.Info(@"*******************************************************************************************************************************");
            Logger.Info(@"date: " + DateTime.Now);
            Logger.Info(@"server addresses: " + serverAddresses);
            Logger.Info(@"port: " + serverPort);
            Logger.Info(@"*******************************************************************************************************************************");

            // Connect to server right away to let it know we're alive
            var client = Connect(serverAddresses, serverPort);

            // Update build number (if available)
            ImageTester.ImageTestResultConnection.BuildNumber = buildNumber;
            ImageTester.ImageTestResultConnection.BranchName  = branchName ?? "";

            // Connect beforehand to image tester, so that first test timing is not affected by initial connection
            try
            {
                ImageTester.Connect();
            }
            catch (Exception e)
            {
                Logger.Error("Error connecting to image tester server: {0}", e);
            }

            // Start unit test
            var cachePath = CacheDir.AbsolutePath;
            var timeNow   = DateTime.Now;

            // Generate result file name
            var resultFile = Path.Combine(cachePath, string.Format("TestResult-{0:yyyy-MM-dd_hh-mm-ss-tt}.xml", timeNow));

            Logger.Debug(@"Execute tests");

            var stringBuilder = new StringBuilder();
            var stringWriter  = new StringWriter(stringBuilder);

            new TextUI(stringWriter).Execute(new [] { "-format:nunit2", string.Format("-result:{0}", resultFile) });

            Logger.Debug(@"Execute tests done");

            // Read result file
            var result = File.ReadAllText(resultFile);

            // Delete result file
            File.Delete(resultFile);

            // Display some useful info
            var output = stringBuilder.ToString();

            Console.WriteLine(output);

            Logger.Debug(@"Sending results to server");

            // Send back result
            var binaryWriter = new BinaryWriter(client.GetStream());

            binaryWriter.Write(output);
            binaryWriter.Write(result);

            Logger.Debug(@"Close connection");

            ImageTester.Disconnect();

            client.Close();

            Finish();
        }
Esempio n. 3
0
        private void RunTests()
        {
            AppDomain.CurrentDomain.UnhandledException += (a, e) =>
            {
                var exception = e.ExceptionObject as Exception;
                if (exception != null)
                {
                    var exceptionText = exception.ToString();
                    stringBuilder.Append($"Tests fatal failure: {exceptionText}");
                    Logger.Debug($"Unhandled fatal exception: {exception.ToString()}");
                    EndTesting(true);
                }
            };

            var xenkoVersion = Intent.GetStringExtra(TestRunner.XenkoVersion);
            var buildNumber  = Parse(Intent.GetStringExtra(TestRunner.XenkoBuildNumber) ?? "-1");
            var branchName   = Intent.GetStringExtra(TestRunner.XenkoBranchName) ?? "";

            // Remove extra (if activity is recreated)
            Intent.RemoveExtra(TestRunner.XenkoVersion);
            Intent.RemoveExtra(TestRunner.XenkoBuildNumber);
            Intent.RemoveExtra(TestRunner.XenkoBranchName);

            Logger.Info(@"*******************************************************************************************************************************");
            Logger.Info(@"date: " + DateTime.Now);
            Logger.Info(@"*******************************************************************************************************************************");

            // Connect to server right away to let it know we're alive
            //var client = Connect(serverAddresses, serverPort);

            var url = "/task/SiliconStudio.Xenko.TestRunner.exe";

            socketContext      = RouterClient.RequestServer(url).Result;
            socketBinaryWriter = new BinaryWriter(socketContext.WriteStream);

            // Update build number (if available)
            ImageTester.ImageTestResultConnection.BuildNumber = buildNumber;
            ImageTester.ImageTestResultConnection.BranchName  = branchName ?? "";

            // Connect beforehand to image tester, so that first test timing is not affected by initial connection
            try
            {
                ImageTester.Connect();
            }
            catch (Exception e)
            {
                Logger.Error("Error connecting to image tester server: {0}", e);
            }

            // Start unit test
            var cachePath = CacheDir.AbsolutePath;
            var timeNow   = DateTime.Now;

            // Generate result file name
            resultFile = Path.Combine(cachePath, $"TestResult-{timeNow:yyyy-MM-dd_hh-mm-ss-tt}.xml");

            Logger.Debug(@"Execute tests");

            stringBuilder = new StringBuilder();
            var stringWriter = new StringWriter(stringBuilder);

            try
            {
                new TextUI(stringWriter)
                {
                    TestListener = this
                }.Execute(new[] { "-format:nunit2", $"-result:{resultFile}" });
            }
            catch (Exception ex)
            {
                stringBuilder.Append($"Tests fatal failure: {ex}");
                Logger.Error($"Tests fatal failure: {ex}");
            }

            EndTesting(false);
        }