This commit is contained in:
Tomas Dirvanauskas 2024-04-10 17:43:59 +03:00
Родитель f03e00aa57
Коммит 3ed5f6321c
4 изменённых файлов: 39 добавлений и 47 удалений

Просмотреть файл

@ -2,7 +2,6 @@ using System;
using NUnit.Framework;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Unity.Android.Logcat;
using UnityEngine;

Просмотреть файл

@ -12,45 +12,38 @@ internal class AndroidLogcatPackageTests : AndroidLogcatRuntimeTestBase
[Test]
public void DeadPackagesAreCleanupCorrectly()
{
try
using var autoRuntime = new AutoRuntime(this);
const int kPackagesToCreate = 10;
var fakeDevice = new AndroidLogcatFakeDevice90("androiddevice0");
for (int i = 0; i < kPackagesToCreate; i++)
{
InitRuntime();
const int kPackagesToCreate = 10;
var fakeDevice = new AndroidLogcatFakeDevice90("androiddevice0");
for (int i = 0; i < kPackagesToCreate; i++)
{
var d = m_Runtime.UserSettings.CreateProcessInformation("com.unity.test" + i, i + 1, fakeDevice);
}
// All packages are alive, calling cleanup dead packages, shouldn't clean anything
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
var packages = m_Runtime.UserSettings.GetKnownProcesses(fakeDevice);
Assert.AreEqual(kPackagesToCreate, packages.Count);
foreach (var p in packages)
p.SetExited();
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
Assert.AreEqual(m_Runtime.Settings.MaxExitedPackagesToShow, packages.Count);
// Check that recent packages are still there, only the old packages should be removed
foreach (var p in packages)
Assert.IsTrue(p.processId > 5);
// Lower the number of max exited packages
m_Runtime.Settings.MaxExitedPackagesToShow = 4;
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
packages = m_Runtime.UserSettings.GetKnownProcesses(fakeDevice);
Assert.AreEqual(m_Runtime.Settings.MaxExitedPackagesToShow, packages.Count);
foreach (var p in packages)
Assert.IsTrue(p.processId > 6);
}
finally
{
ShutdownRuntime();
var d = m_Runtime.UserSettings.CreateProcessInformation("com.unity.test" + i, i + 1, fakeDevice);
}
// All packages are alive, calling cleanup dead packages, shouldn't clean anything
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
var packages = m_Runtime.UserSettings.GetKnownProcesses(fakeDevice);
Assert.AreEqual(kPackagesToCreate, packages.Count);
foreach (var p in packages)
p.SetExited();
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
Assert.AreEqual(m_Runtime.Settings.MaxExitedPackagesToShow, packages.Count);
// Check that recent packages are still there, only the old packages should be removed
foreach (var p in packages)
Assert.IsTrue(p.processId > 5);
// Lower the number of max exited packages
m_Runtime.Settings.MaxExitedPackagesToShow = 4;
m_Runtime.UserSettings.CleanupDeadProcessesForDevice(fakeDevice, m_Runtime.Settings.MaxExitedPackagesToShow);
packages = m_Runtime.UserSettings.GetKnownProcesses(fakeDevice);
Assert.AreEqual(m_Runtime.Settings.MaxExitedPackagesToShow, packages.Count);
foreach (var p in packages)
Assert.IsTrue(p.processId > 6);
}
}

Просмотреть файл

@ -18,7 +18,7 @@ class AndroidLogcatDeviceQueryTests : AndroidLogcatRuntimeTestBase
m_UpdatedCount = 0;
m_SelectedCount = 0;
bool notUsed = true;
InitRuntime();
using var autoRuntime = new AutoRuntime(this);
var query = (AndroidLogcatFakeDeviceQuery)m_Runtime.DeviceQuery;
query.DeviceSelected += Query_DeviceSelected;
@ -78,8 +78,6 @@ myandroid3 offline
Assert.AreEqual(null, query.SelectedDevice);
Assert.AreEqual(2, m_SelectedCount);
ShutdownRuntime();
}
private void Query_DevicesUpdated()

Просмотреть файл

@ -52,15 +52,17 @@ internal class AndroidLogcatRuntimeTestBase
protected class AutoRuntime : IDisposable
{
AndroidLogcatRuntimeTestBase m_Parent;
public AutoRuntime(AndroidLogcatRuntimeTestBase parent)
bool m_CleanUp;
public AutoRuntime(AndroidLogcatRuntimeTestBase parent, bool cleanup = true)
{
m_Parent = parent;
m_Parent.InitRuntime();
m_CleanUp = cleanup;
m_Parent.InitRuntime(m_CleanUp);
}
public void Dispose()
{
m_Parent.ShutdownRuntime();
m_Parent.ShutdownRuntime(m_CleanUp);
}
}
@ -70,7 +72,7 @@ internal class AndroidLogcatRuntimeTestBase
Directory.Delete("Tests", true);
}
protected void InitRuntime(bool cleanup = true)
protected void InitRuntime(bool cleanup)
{
if (m_Runtime != null)
throw new Exception("Runtime was not shutdown by previous test?");
@ -80,7 +82,7 @@ internal class AndroidLogcatRuntimeTestBase
m_Runtime.Initialize();
}
protected void ShutdownRuntime(bool cleanup = true)
protected void ShutdownRuntime(bool cleanup)
{
if (m_Runtime == null)
throw new Exception("Runtime was not created?");