Fix the HealthCheck tests - RequestUploadTaskTests

- Now that the credential receiver ignores empty credentials, this test needed to be updated to not send an empty password
- Moved initializing code in TestFixtureSetUp (and similarly tear-down code in TestFixtureTearDown) for both RequestUploadTaskTests and CredentialTests classes
- Also removed unnecessary calls to CreateNewConnection and LoadCache

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2017-05-30 13:28:09 +01:00
parent f9b7f71b18
commit 209014dd2c
2 changed files with 32 additions and 18 deletions

View File

@ -50,11 +50,22 @@ namespace XenAdminTests.HealthCheckTests
{
private const char SEPARATOR = '\x202f'; // narrow non-breaking space.
[Test]
public void CredentialOp()
[TestFixtureSetUp]
public void FixtureSetup()
{
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
}
[TestFixtureTearDown]
public void FixtureTearDown()
{
CredentialReceiver.instance.UnInit();
}
[Test]
public void CredentialOp()
{
string HostName = "Host1";
string UserName = "User1";
string Password = "password1";
@ -156,8 +167,6 @@ namespace XenAdminTests.HealthCheckTests
System.Threading.Thread.Sleep(1000);
con = ServerListHelper.instance.GetServerList();
Assert.IsTrue(con.Count == conSize);
CredentialReceiver.instance.UnInit();
}
}
}

View File

@ -50,6 +50,8 @@ namespace XenAdminTests.HealthCheckTests
{
private const char SEPARATOR = '\x202f'; // narrow non-breaking space.
private const string dbName = "TampaTwoHostPoolSelectioniSCSI.xml";
private const string nonEmptyPassword = "nonemptypassword"; // needed when the credentials are sent to the HealthCheck, as the credential receiver will othrwise ignore them
public RequestUploadTaskTests() : base(dbName) { }
private static string UUID = "test-test";
@ -64,24 +66,32 @@ namespace XenAdminTests.HealthCheckTests
config[HealthCheckSettings.LAST_FAILED_UPLOAD] = "";
return config;
}
[TestFixtureSetUp]
public void FixtureSetup()
{
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
}
[TestFixtureTearDown]
public void FixtureTearDown()
{
CredentialReceiver.instance.UnInit();
}
[Test]
public void CheckUnenrolledHostShouldRemoved()
{
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
DatabaseManager.CreateNewConnection(dbName);
IXenConnection connection = DatabaseManager.ConnectionFor(dbName);
Session _session = DatabaseManager.ConnectionFor(dbName).Session;
DatabaseManager.ConnectionFor(dbName).LoadCache(_session);
Dictionary<string, string> config = cleanStack();
connection.LoadCache(_session);
ServerListHelper.instance.ClearServerList();
int conSize = ServerListHelper.instance.GetServerList().Count;
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
pipeClient.Connect();
string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { connection.Hostname, connection.Username, connection.Password }));
string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { connection.Hostname, connection.Username, nonEmptyPassword }));
pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
pipeClient.Close();
System.Threading.Thread.Sleep(1000);
@ -96,20 +106,17 @@ namespace XenAdminTests.HealthCheckTests
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
con = ServerListHelper.instance.GetServerList();
Assert.IsTrue(con.Count == conSize);
CredentialReceiver.instance.UnInit();
}
[Test, Timeout( 100 * 1000 )]
public void checkUploadLock()
{
DatabaseManager.CreateNewConnection(dbName);
IXenConnection connection = DatabaseManager.ConnectionFor(dbName);
Session _session = DatabaseManager.ConnectionFor(dbName).Session;
DatabaseManager.ConnectionFor(dbName).LoadCache(_session);
Dictionary<string, string> config = cleanStack();
connection.LoadCache(_session);
//1. If XenServer has not enroll, lock will not been set.
config = cleanStack();
config[HealthCheckSettings.STATUS] = "false";
@ -217,12 +224,10 @@ namespace XenAdminTests.HealthCheckTests
[Test]
public void checkDemandLock()
{
DatabaseManager.CreateNewConnection(dbName);
IXenConnection connection = DatabaseManager.ConnectionFor(dbName);
Session _session = DatabaseManager.ConnectionFor(dbName).Session;
DatabaseManager.ConnectionFor(dbName).LoadCache(_session);
Dictionary<string, string> config = cleanStack();
connection.LoadCache(_session);
//1 Uploading is inprocess by current service, demand will be ignore
config = cleanStack();
config[HealthCheckSettings.UPLOAD_LOCK] = UUID + "|" + HealthCheckSettings.DateTimeToString(DateTime.UtcNow);