Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -0,0 +1,117 @@
// ***********************************************************************
// Copyright (c) 2010 Charlie Poole
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************
#if MONO
using System;
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics;
using NUnit.Framework.Api;
namespace NUnit.Framework.Internal.Commands
{
public class FlakyTestRetriesDecorator : ICommandDecorator
{
#region ICommandDecorator Members
CommandStage ICommandDecorator.Stage
{
get { return CommandStage.AboveSetUpTearDown; }
}
int ICommandDecorator.Priority
{
get { return 0; }
}
TestCommand ICommandDecorator.Decorate(TestCommand command)
{
return new FlakyTestRetriesCommand(command);
}
#endregion
}
public class FlakyTestRetriesCommand : DelegatingTestCommand
{
int retries = 0;
const int MASS_FAIL_SAFEGUARD = 10;
private static int globalTotalRetries = 0;
public FlakyTestRetriesCommand(TestCommand innerCommand)
: base(innerCommand)
{
string retriesEnv = Environment.GetEnvironmentVariable ("MONO_FLAKY_TEST_RETRIES");
Int32.TryParse (retriesEnv, out retries);
}
public override TestResult Execute(TestExecutionContext context)
{
// regular test execution
context.CurrentResult = innerCommand.Execute(context);
if (retries == 0 ||
context.CurrentResult.ResultState.Status == TestStatus.Passed ||
context.CurrentResult.ResultState.Status == TestStatus.Skipped)
return context.CurrentResult;
// skip retries after a certain number to avoid retrying mass failures
if (globalTotalRetries++ >= MASS_FAIL_SAFEGUARD)
{
Test.Properties.Set("FlakyTestRetries.MassFailSafeguard", true);
return context.CurrentResult;
}
// regular test execution resulted in a failed test, start doing retries
var passedTestResults = new List<TestResult>();
var failedTestResults = new List<TestResult>();
for (int i = 0; i < retries; i++)
{
Thread.Sleep (1000); // give the test some time to close files, sockets etc
var testResult = innerCommand.Execute(context);
if (testResult.ResultState.Status == TestStatus.Passed)
passedTestResults.Add(testResult);
else
failedTestResults.Add(testResult);
}
// overall result is based on majority of results,
// we return the first passed/failed result here and log stats about the rest
var overallResult = passedTestResults.Count > failedTestResults.Count;
context.CurrentResult = overallResult ? passedTestResults[0] : failedTestResults[0];
Test.Properties.Set("FlakyTestRetries.Result", overallResult ? "PASS" : "FAIL");
Test.Properties.Set("FlakyTestRetries.PassCount", passedTestResults.Count);
Test.Properties.Set("FlakyTestRetries.FailCount", failedTestResults.Count);
return context.CurrentResult;
}
}
}
#endif

View File

@@ -84,7 +84,11 @@ namespace NUnit.Framework.Internal.Filters
public override bool Match( ITest test )
{
foreach( string name in names )
#if MONO
if ( test.FullName.StartsWith (name) )
#else
if ( test.FullName == name )
#endif
return true;
return false;

View File

@@ -249,6 +249,10 @@ namespace NUnit.Framework.Internal
// Add Standard stuff
decorators.Add(new SetUpTearDownDecorator());
#if MONO
decorators.Add(new FlakyTestRetriesDecorator());
#endif
// Add Decorators supplied by attributes and parameter sets
foreach (ICommandDecorator decorator in CustomDecorators)
decorators.Add(decorator);

View File

@@ -71,6 +71,11 @@ namespace NUnitLite.Runner
if (summary.NotRunCount > 0)
PrintNotRunReport();
#if MONO
if (summary.FlakyTestRetriesCount > 0)
PrintFlakyTestRetriesReport();
#endif
//if (commandLineOptions.Full)
// PrintFullReport(result);
}
@@ -117,6 +122,16 @@ namespace NUnitLite.Runner
PrintNotRunResults(this.result);
}
#if MONO
public void PrintFlakyTestRetriesReport()
{
reportCount = 0;
writer.WriteLine();
writer.WriteLine("Flaky Test Retries:");
PrintFlakyTestRetriesResults(this.result);
}
#endif
/// <summary>
/// Prints a full report of all results
/// </summary>
@@ -149,6 +164,20 @@ namespace NUnitLite.Runner
WriteSingleResult(result);
}
#if MONO
private void PrintFlakyTestRetriesResults(ITestResult result)
{
if (result.HasChildren)
foreach (ITestResult childResult in result.Children)
PrintFlakyTestRetriesResults(childResult);
else if (result.Test.Properties.ContainsKey("FlakyTestRetries.Result"))
{
writer.WriteLine();
writer.WriteLine("{0} ({1} passes/{2} fails): {3} ({4})", result.Test.Properties.Get("FlakyTestRetries.Result"), result.Test.Properties.Get("FlakyTestRetries.PassCount"), result.Test.Properties.Get("FlakyTestRetries.FailCount"), result.Name, result.FullName);
}
}
#endif
private void PrintTestProperties(ITest test)
{
foreach (PropertyEntry entry in test.Properties)

View File

@@ -39,6 +39,9 @@ namespace NUnitLite.Runner
private int ignoreCount;
private int skipCount;
private int invalidCount;
#if MONO
private int flakyTestRetriesCount;
#endif
/// <summary>
/// Initializes a new instance of the <see cref="ResultSummary"/> class.
@@ -125,6 +128,13 @@ namespace NUnitLite.Runner
get { return inconclusiveCount; }
}
#if MONO
public int FlakyTestRetriesCount
{
get { return flakyTestRetriesCount; }
}
#endif
private void Visit(ITestResult result)
{
if (result.Test.IsSuite)
@@ -161,6 +171,10 @@ namespace NUnitLite.Runner
break;
}
#if MONO
if (result.Test.Properties.ContainsKey("FlakyTestRetries.Result"))
flakyTestRetriesCount++;
#endif
return;
}
}