fix concurrent starts of NuGet.exe'
authorEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 20 Jul 2011 13:35:53 +0000 (17:35 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 20 Jul 2011 13:35:53 +0000 (17:35 +0400)
nuget-extensions/nuget-commands/src/NuGetTeamCityPingCommand.cs
nuget-extensions/nuget-runner/src/NuGetRunMutex.cs
nuget-extensions/nuget-runner/src/NuGetRunner.cs
nuget-extensions/nuget-tests/src/NuGetRunnerTest.cs

index 765e8728411184d871e670558b69aca6cecdc89d..9a9518b7036edfad652fe02a9218ff59643a8605 100644 (file)
@@ -1,3 +1,4 @@
+using System.Threading;\r
 using NuGet;\r
 using NuGet.Commands;\r
 \r
@@ -6,11 +7,19 @@ namespace JetBrains.TeamCity.NuGet.ExtendedCommands
   [Command("TeamCity.Ping", "Command that dump NuGet and TeamCity extension versions. It is used to check NuGet<->TeamCity communications")]\r
   public class NuGetTeamCityPingCommand : Command\r
   {\r
+    [Option("Makes command wait for 1000ms before exit. Used for testing")]\r
+    public bool Sleep { get; set; }\r
+\r
     public override void ExecuteCommand()\r
     {\r
       System.Console.Out.WriteLine("TeamCity NuGet Extension is available.");\r
       System.Console.Out.WriteLine("NuGet Version = {0}", typeof(Command).Assembly.GetName().Version);\r
       System.Console.Out.WriteLine("TeamCity Extension Version = {0}", GetType().Assembly.GetName().Version);\r
+      \r
+      if (Sleep)\r
+      {\r
+        Thread.Sleep(1000);\r
+      }\r
     }\r
   }\r
 }
\ No newline at end of file
index c80f5d5e0e47695f98b60303c6f118963942c209..5435340d8ba21b48eef467caa4c0af1fd2107936 100644 (file)
@@ -8,7 +8,7 @@ namespace JetBrains.TeamCity.NuGetRunner
     {\r
       var m = new Mutex(false, "JetBrains.TeamCity.NuGet.RunMutex");\r
       runner.BeforeNuGetStarted += (_, __) => m.WaitOne();\r
-      runner.BeforeNuGetStarted += (_, __) => m.ReleaseMutex();\r
+      runner.AfterNuGetFinished += (_, __) => m.ReleaseMutex();\r
     }\r
   }\r
 }
\ No newline at end of file
index c1b580195035b98d8a8c6550e96e258ba37ac291..127c093673ef5ae81cf86e5d4fa3585e654dfbcc 100644 (file)
@@ -119,7 +119,7 @@ namespace JetBrains.TeamCity.NuGetRunner
       }\r
       finally\r
       {\r
-        CallEvents(myFinishEvents);\r
+        CallEvents(Enumerable.Reverse(myFinishEvents));\r
       }\r
     }\r
 \r
index 050408357826896841794b441c87c6b9aa40501f..555dc04b11693dffded2569acaa2660fceeed62d 100644 (file)
@@ -1,6 +1,8 @@
 ´╗┐using System;\r
 using System.IO;\r
+using System.Threading;\r
 using NUnit.Framework;\r
+using System.Linq;\r
 \r
 namespace JetBrains.TeamCity.NuGet.Tests\r
 {\r
@@ -70,5 +72,46 @@ namespace JetBrains.TeamCity.NuGet.Tests
         .AssertNoErrorOutput()\r
         .AssertOutputContains("TeamCity NuGet Extension is available.");\r
     }\r
+\r
+    [Test]\r
+    public void TestCommands_RunConcurrently()\r
+    {\r
+      bool failed = false;\r
+      new[] {1, 2, 3, 4, 5, 6, 7}\r
+        .Select(\r
+          x => new Thread(() =>\r
+                            {\r
+                              for (int i = 0; i < 3; i++)\r
+                              {\r
+                                var proc = ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, Files.NuGetExe, "TeamCity.Ping", "-Sleep");\r
+                                if (proc.ExitCode != 0 || !string.IsNullOrWhiteSpace(proc.Error))\r
+                                {\r
+                                  proc.Dump();\r
+                                  failed = true;\r
+                                }\r
+                                proc.AssertNoErrorOutput().AssertExitedSuccessfully();\r
+                              }\r
+                            })\r
+                 {\r
+                   Name = "Checker " + x,\r
+                 })\r
+        .ToList()\r
+        .Select(\r
+          x =>\r
+            {\r
+              x.Start();\r
+              return x;\r
+            })\r
+        .ToList()\r
+        .Select(x =>\r
+                  {\r
+                    x.Join();\r
+                    return 0;\r
+                  })\r
+        .ToList();\r
+\r
+      Assert.IsFalse(failed);\r
+    }\r
+\r
   }\r
 }\r