Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,29 @@ public void TaskOutputsToLoggers ()
[Test]
public void EndBuildWaitsForSubmissionCompletion ()
{
// Windows does not have useful sleep or alternative, so skip it
bool is_windows = true;
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
is_windows = false;
break;
}
string project_xml = string.Format (@"<Project DefaultTargets='Wait1Sec' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Wait1Sec'>
<Exec Command='{0}' />
</Target>
</Project>", is_windows ? "powershell -command \"Start-Sleep -s 1\"" : "/bin/sleep 1");
</Project>", Environment.OSVersion.Platform == PlatformID.Win32NT ? "powershell -command \"Start-Sleep -s 1\"" : "/bin/sleep 1");
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "BuildSubmissionTest.EndBuildWaitsForSubmissionCompletion.proj";
var proj = new ProjectInstance (root);
var bm = new BuildManager ();
bm.BeginBuild (new BuildParameters ());
DateTime waitDone = DateTime.MinValue;
DateTime beforeExec = DateTime.UtcNow;
var waitDone = TimeSpan.MinValue;
var sw = System.Diagnostics.Stopwatch.StartNew ();
var sub = bm.PendBuildRequest (new BuildRequestData (proj, new string [] { "Wait1Sec" }));
sub.ExecuteAsync (delegate { waitDone = DateTime.UtcNow; }, null);
sub.ExecuteAsync (cb => waitDone = sw.Elapsed, null);
bm.EndBuild ();
Assert.AreEqual (BuildResultCode.Success, sub.BuildResult.OverallResult, "#1");
DateTime endBuildDone = DateTime.UtcNow;
AssertHelper.GreaterOrEqual (endBuildDone - beforeExec, TimeSpan.FromSeconds (1), "#2");
AssertHelper.GreaterOrEqual (waitDone, beforeExec, "#3");
var endBuildDone = sw.Elapsed;
AssertHelper.GreaterOrEqual (endBuildDone, TimeSpan.FromSeconds (1), "#2");
AssertHelper.GreaterOrEqual (waitDone, TimeSpan.FromSeconds (1), "#3");
AssertHelper.GreaterOrEqual (endBuildDone, waitDone, "#4");
AssertHelper.LessOrEqual (endBuildDone, TimeSpan.FromSeconds (1.5), "#5");
AssertHelper.LessOrEqual (waitDone, TimeSpan.FromSeconds (1.5), "#6");
}

[Test]
Expand Down
15 changes: 15 additions & 0 deletions mcs/class/test-helpers/NunitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ public static void LessOrEqual (int arg1, int arg2, string message = null, param
Assert.That(arg1, Is.LessThanOrEqualTo(arg2), message, args);
}

public static void LessOrEqual(long arg1, long arg2, string message = null, params object[] args)
{
Assert.That(arg1, Is.LessThanOrEqualTo(arg2), message, args);
}

public static void LessOrEqual(System.DateTime arg1, System.DateTime arg2, string message = null, params object[] args)
{
Assert.That(arg1, Is.LessThanOrEqualTo(arg2), message, args);
}

public static void LessOrEqual(System.TimeSpan arg1, System.TimeSpan arg2, string message = null, params object[] args)
{
Assert.That(arg1, Is.LessThanOrEqualTo(arg2), message, args);
}

public static void IsNotInstanceOfType(System.Type expected, object actual, string message, params object[] args )
{
Assert.IsFalse (actual.GetType ().IsInstanceOfType (expected), message, args);
Expand Down