Fixed Environment Variable conflict in IISProvider
This commit is contained in:
parent
fbf7d20c5d
commit
bc5307a4d3
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Ninject;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Providers;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Dummy;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class IISProviderFixture : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_not_set_env_varibles_twice()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
|
||||
var dummy = StartDummyProcess();
|
||||
|
||||
Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PID, "Test");
|
||||
Environment.SetEnvironmentVariable(EnviromentProvider.NZBDRONE_PATH, "Test");
|
||||
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
.Setup(c => c.Start(It.IsAny<ProcessStartInfo>()))
|
||||
.Returns(dummy);
|
||||
|
||||
Mocker.Resolve<IISProvider>().StartServer();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_iis_procces_id()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
var dummy = StartDummyProcess();
|
||||
|
||||
Mocker.GetMock<ProcessProvider>()
|
||||
.Setup(c => c.Start(It.IsAny<ProcessStartInfo>()))
|
||||
.Returns(dummy);
|
||||
|
||||
//act
|
||||
Mocker.Resolve<IISProvider>().StartServer();
|
||||
|
||||
//assert
|
||||
Mocker.Resolve<IISProvider>().IISProcessId.Should().Be(dummy.Id);
|
||||
}
|
||||
|
||||
|
||||
public Process StartDummyProcess()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
startInfo.RedirectStandardError = true;
|
||||
startInfo.CreateNoWindow = true;
|
||||
return new ProcessProvider().Start(startInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -66,6 +66,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CentralDispatchTests.cs" />
|
||||
<Compile Include="IISProviderFixture.cs" />
|
||||
<Compile Include="RouterTest.cs" />
|
||||
<Compile Include="MonitoringProviderTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
|
@ -4,26 +4,27 @@ using System.Linq;
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Dummy;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessProviderTests : TestBase
|
||||
{
|
||||
private const string DummyProccessName = "NzbDrone.Test.Dummy";
|
||||
|
||||
ProcessProvider _processProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill());
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
|
||||
_processProvider = new ProcessProvider();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Process.GetProcessesByName(DummyProccessName).ToList().ForEach(c => c.Kill());
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
|
@ -58,20 +59,20 @@ namespace NzbDrone.Common.Test
|
|||
[Test]
|
||||
public void Should_be_able_to_start_process()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(DummyProccessName + ".exe");
|
||||
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
||||
|
||||
//Act/Assert
|
||||
_processProvider.GetProcessByName(DummyProccessName).Should()
|
||||
_processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
||||
.BeEmpty("Dummy process is already running");
|
||||
_processProvider.Start(startInfo).Should().NotBeNull();
|
||||
|
||||
_processProvider.GetProcessByName(DummyProccessName).Should()
|
||||
_processProvider.GetProcessByName(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
||||
.HaveCount(1, "excepted one dummy process to be already running");
|
||||
}
|
||||
|
||||
public Process StartDummyProcess()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(DummyProccessName + ".exe");
|
||||
var startInfo = new ProcessStartInfo(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
||||
return _processProvider.Start(startInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ namespace NzbDrone.Common
|
|||
{
|
||||
public const string IIS_FOLDER_NAME = "iisexpress";
|
||||
|
||||
public const string NZBDRONE_PATH = "NZBDRONE_PATH";
|
||||
public const string NZBDRONE_PID = "NZBDRONE_PID";
|
||||
|
||||
#if DEBUG
|
||||
private static readonly bool isInDebug = true;
|
||||
#else
|
||||
|
@ -98,7 +101,7 @@ namespace NzbDrone.Common
|
|||
{
|
||||
get
|
||||
{
|
||||
var id = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID"));
|
||||
var id = Convert.ToInt32(Environment.GetEnvironmentVariable(NZBDRONE_PID));
|
||||
|
||||
if (id == 0)
|
||||
throw new InvalidOperationException("NZBDRONE_PID isn't a valid environment variable.");
|
||||
|
|
|
@ -3,8 +3,10 @@ using System.Diagnostics;
|
|||
|
||||
namespace NzbDrone.Test.Dummy
|
||||
{
|
||||
class Program
|
||||
public class DummyApp
|
||||
{
|
||||
public const string DUMMY_PROCCESS_NAME = "NzbDrone.Test.Dummy";
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Dummy process. ID:{0} Path:{1}", Process.GetCurrentProcess().Id, Process.GetCurrentProcess().MainModule.FileName);
|
|
@ -43,7 +43,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="DummyApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
@ -53,9 +53,15 @@ namespace NzbDrone.Providers
|
|||
startInfo.RedirectStandardError = true;
|
||||
startInfo.CreateNoWindow = true;
|
||||
|
||||
//Set Variables for the config file.
|
||||
startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _enviromentProvider.ApplicationPath);
|
||||
startInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString());
|
||||
if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PATH))
|
||||
{
|
||||
startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PATH, _enviromentProvider.ApplicationPath);
|
||||
}
|
||||
|
||||
if (!startInfo.EnvironmentVariables.ContainsKey(EnviromentProvider.NZBDRONE_PID))
|
||||
{
|
||||
startInfo.EnvironmentVariables.Add(EnviromentProvider.NZBDRONE_PID, Process.GetCurrentProcess().Id.ToString());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -117,7 +117,7 @@ namespace NzbDrone.Providers
|
|||
}.Submit();
|
||||
}
|
||||
|
||||
Logger.FatalException("EPIC FAIL: {0}", excepion);
|
||||
Logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue