You've already forked linux-packaging-mono
Imported Upstream version 5.16.0.100
Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
parent
0a9828183b
commit
7d7f676260
@@ -33,6 +33,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Caching;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -143,6 +144,18 @@ namespace MonoTests.System.Runtime.Caching
|
||||
mc = new MemoryCache("MyCache", config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.AnyUnix)] // Negative case for "physicalMemoryLimitPercentage" on non Windows
|
||||
public void PhysicalMemoryLimitNotSupported()
|
||||
{
|
||||
var config = new NameValueCollection();
|
||||
config.Add("PhysicalMemoryLimitPercentage", "99");
|
||||
Assert.Throws<PlatformNotSupportedException>(() =>
|
||||
{
|
||||
new MemoryCache("MyCache", config);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Defaults()
|
||||
{
|
||||
@@ -176,6 +189,7 @@ namespace MonoTests.System.Runtime.Caching
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
|
||||
public void ConstructorValues()
|
||||
{
|
||||
var config = new NameValueCollection();
|
||||
@@ -991,6 +1005,7 @@ namespace MonoTests.System.Runtime.Caching
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
|
||||
public void TestExpiredGetValues()
|
||||
{
|
||||
var config = new NameValueCollection();
|
||||
@@ -1024,6 +1039,8 @@ namespace MonoTests.System.Runtime.Caching
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
|
||||
[OuterLoop] // makes long wait
|
||||
public void TestCacheSliding()
|
||||
{
|
||||
var config = new NameValueCollection();
|
||||
@@ -1039,7 +1056,8 @@ namespace MonoTests.System.Runtime.Caching
|
||||
// The sliding expiration timeout has to be greater than 1 second because
|
||||
// .NET implementation ignores timeouts updates smaller than
|
||||
// CacheExpires.MIN_UPDATE_DELTA which is equal to 1.
|
||||
cip.SlidingExpiration = TimeSpan.FromSeconds(2);
|
||||
const int SlidingExpirationThresholdMSec = 4000;
|
||||
cip.SlidingExpiration = TimeSpan.FromMilliseconds(SlidingExpirationThresholdMSec);
|
||||
mc.Add("slidingtest", "42", cip);
|
||||
|
||||
mc.Add("expire1", "1", cip);
|
||||
@@ -1049,13 +1067,28 @@ namespace MonoTests.System.Runtime.Caching
|
||||
mc.Add("expire5", "5", cip);
|
||||
|
||||
Assert.Equal(6, mc.GetCount());
|
||||
|
||||
// The loop below would sleep for ~5 seconds total (in 50 intervals).
|
||||
// Each of these intervals is only supposed to be ~100ms.
|
||||
// However due to concurrency with other tests and various system conditions,
|
||||
// we observe occasional delays that are much longer than the SlidingExpirationThresholdMSec
|
||||
// expiration period which causes the "slidingtest" cache item to expire
|
||||
Stopwatch sw = new Stopwatch();
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
sw.Restart();
|
||||
Thread.Sleep(100);
|
||||
|
||||
var item = mc.Get("slidingtest");
|
||||
Assert.NotEqual(null, item);
|
||||
sw.Stop();
|
||||
|
||||
if (sw.ElapsedMilliseconds < SlidingExpirationThresholdMSec)
|
||||
{
|
||||
Assert.NotEqual(null, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
// for the sake of simplicity skip an inversed assert here (Assert.Equal(null, item))
|
||||
// (to avoid further complicating the test as we would need to address a few more subtle timing cases)
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Null(mc.Get("expire1"));
|
||||
@@ -1065,7 +1098,7 @@ namespace MonoTests.System.Runtime.Caching
|
||||
Assert.Null(mc.Get("expire5"));
|
||||
Assert.Equal(1, mc.GetCount());
|
||||
|
||||
Thread.Sleep(3000);
|
||||
Thread.Sleep(SlidingExpirationThresholdMSec + 1000);
|
||||
|
||||
Assert.Null(mc.Get("slidingtest"));
|
||||
Assert.Equal(0, mc.GetCount());
|
||||
@@ -1314,6 +1347,7 @@ namespace MonoTests.System.Runtime.Caching
|
||||
public class MemoryCacheTestExpires4
|
||||
{
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
|
||||
public async Task TestCacheShrink()
|
||||
{
|
||||
const int HEAP_RESIZE_THRESHOLD = 8192 + 2;
|
||||
@@ -1371,6 +1405,7 @@ namespace MonoTests.System.Runtime.Caching
|
||||
public class MemoryCacheTestExpires5
|
||||
{
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Uses "physicalMemoryLimitPercentage" not supported on other platforms
|
||||
public async Task TestCacheExpiryOrdering()
|
||||
{
|
||||
var config = new NameValueCollection();
|
||||
|
||||
Reference in New Issue
Block a user