From e484ef50291d6e3faa66833d0b68039362b26591 Mon Sep 17 00:00:00 2001 From: Blake Bender Date: Wed, 9 Jun 2021 18:44:10 -0700 Subject: [PATCH] Fix parallel test running - Geode 'Client' is a singleton, so needs to be a global resource in tests - XUnit uses a 'Collection' for this, so added NetCoreCollectionFixture and NetCoreCollection classes. Now Client is created before any tests run, and torn down when the last test completes. --- NetCore.Test/CacheFactoryUnitTest.cs | 64 +++----- NetCore.Test/CacheUnitTest.cs | 187 +++++++++-------------- NetCore.Test/NetCoreCollectionFixture.cs | 22 +++ NetCore.Test/ObjectLeakUnitTest.cs | 3 +- NetCore.Test/PoolFactoryUnitTest.cs | 82 +++------- NetCore.Test/PoolManagerUnitTest.cs | 20 +-- NetCore.Test/RegionFactoryUnitTest.cs | 72 ++++----- NetCore.Test/xunit.runner.json | 4 +- 8 files changed, 172 insertions(+), 282 deletions(-) create mode 100644 NetCore.Test/NetCoreCollectionFixture.cs diff --git a/NetCore.Test/CacheFactoryUnitTest.cs b/NetCore.Test/CacheFactoryUnitTest.cs index cdcd581..d451778 100644 --- a/NetCore.Test/CacheFactoryUnitTest.cs +++ b/NetCore.Test/CacheFactoryUnitTest.cs @@ -4,83 +4,66 @@ using Xunit; namespace GemfireDotNetTest { - public class CacheFactoryUnitTests + [Collection("Geode .net Core Collection")] + public class CacheFactoryUnitTests { [Fact] public void TestCreateFactory() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - Assert.NotNull(cacheFactory); - } + Assert.NotNull(cacheFactory); } } [Fact] public void TestCacheFactoryGetVersion() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - var version = cacheFactory.Version; - Assert.NotEqual(version, String.Empty); - } + var version = cacheFactory.Version; + Assert.NotEqual(version, String.Empty); } } [Fact] public void TestCacheFactoryGetProductDescription() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - var description = cacheFactory.ProductDescription; - Assert.NotEqual(description, String.Empty); - } + var description = cacheFactory.ProductDescription; + Assert.NotEqual(description, String.Empty); } } [Fact] public void TestCacheFactorySetPdxIgnoreUnreadFields() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - cacheFactory.PdxIgnoreUnreadFields = true; - cacheFactory.PdxIgnoreUnreadFields = false; - } + cacheFactory.PdxIgnoreUnreadFields = true; + cacheFactory.PdxIgnoreUnreadFields = false; } } [Fact] public void TestCacheFactorySetPdxReadSerialized() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - cacheFactory.PdxReadSerialized = true; - cacheFactory.PdxReadSerialized = false; - } + cacheFactory.PdxReadSerialized = true; + cacheFactory.PdxReadSerialized = false; } } [Fact] public void TestCacheFactoryCreateCache() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) + using (var cache = cacheFactory.CreateCache()) { - using (var cache = cacheFactory.CreateCache()) - { - ; - } + ; } } } @@ -88,13 +71,10 @@ namespace GemfireDotNetTest [Fact] public void TestCacheFactorySetProperty() { - using (var client = new Client()) + using (var cacheFactory = CacheFactory.Create()) { - using (var cacheFactory = CacheFactory.Create()) - { - cacheFactory.SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log"); - } + cacheFactory.SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); } } } diff --git a/NetCore.Test/CacheUnitTest.cs b/NetCore.Test/CacheUnitTest.cs index e19ccb3..9c01608 100644 --- a/NetCore.Test/CacheUnitTest.cs +++ b/NetCore.Test/CacheUnitTest.cs @@ -5,166 +5,115 @@ using Xunit; namespace GemfireDotNetTest { + [Collection("Geode .net Core Collection")] public class CacheUnitTests { [Fact] public void TestClientCacheGetPdxReadSerialized() { - using (var client = new Client()) + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "debug") + .SetProperty("log-file", "TestClientCacheGetPdxReadSerialized.log"); + try { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "debug") - .SetProperty("log-file", "TestClientCacheGetPdxReadSerialized.log")) - { - try - { - cacheFactory.PdxReadSerialized = true; - using (var cache = cacheFactory.CreateCache()) - { - Assert.True(cache.GetPdxReadSerialized()); - } + cacheFactory.PdxReadSerialized = true; + using var cache = cacheFactory.CreateCache(); - cacheFactory.PdxReadSerialized = false; - using (var otherCache = cacheFactory.CreateCache()) - { - Assert.False(otherCache.GetPdxReadSerialized()); - } - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - } + Assert.True(cache.GetPdxReadSerialized()); + + cacheFactory.PdxReadSerialized = false; + using var otherCache = cacheFactory.CreateCache(); + + Assert.False(otherCache.GetPdxReadSerialized()); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; } } [Fact] public void TestClientCacheGetPdxIgnoreUnreadFields() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - Assert.True(cache.GetPdxIgnoreUnreadFields()); - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); - cacheFactory.PdxIgnoreUnreadFields = false; - using (var otherCache = cacheFactory.CreateCache()) - { - Assert.False(otherCache.GetPdxIgnoreUnreadFields()); - } - } - } + Assert.True(cache.GetPdxIgnoreUnreadFields()); + + cacheFactory.PdxIgnoreUnreadFields = false; + using var otherCache = cacheFactory.CreateCache(); + Assert.False(otherCache.GetPdxIgnoreUnreadFields()); } [Fact] public void TestClientCacheGetPoolManager() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - var poolManager = cache.PoolManager; - poolManager.Dispose(); - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); + using var poolManager = cache.PoolManager; } [Fact] public void TestClientCacheCreateRegionFactory() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - using (var regionFactory = cache.CreateRegionFactory(RegionShortcut.Proxy)) - { - ; - } - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); + using var regionFactory = cache.CreateRegionFactory(RegionShortcut.Proxy); } [Fact] public void TestClientCacheGetName() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - var cacheName = cache.Name; - Assert.NotEqual(cacheName, String.Empty); - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none"); + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); + + var cacheName = cache.Name; + Assert.NotEqual(cacheName, String.Empty); } [Fact] public void TestClientCacheClose() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - Assert.False(cache.Closed); - cache.Close(); - Assert.True(cache.Closed); - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none"); + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); + + Assert.False(cache.Closed); + cache.Close(); + Assert.True(cache.Closed); } [Fact] public void TestClientCacheCloseWithKeepalive() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none")) - { - cacheFactory.PdxIgnoreUnreadFields = true; - using (var cache = cacheFactory.CreateCache()) - { - Assert.False(cache.Closed); - cache.Close(true); - Assert.True(cache.Closed); + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none"); + cacheFactory.PdxIgnoreUnreadFields = true; + using var cache = cacheFactory.CreateCache(); + + Assert.False(cache.Closed); + cache.Close(true); + Assert.True(cache.Closed); - } + using var otherCache = cacheFactory.CreateCache(); - using (var otherCache = cacheFactory.CreateCache()) - { - Assert.False(otherCache.Closed); - otherCache.Close(false); - Assert.True(otherCache.Closed); - } - } - } + Assert.False(otherCache.Closed); + otherCache.Close(false); + Assert.True(otherCache.Closed); } } } diff --git a/NetCore.Test/NetCoreCollectionFixture.cs b/NetCore.Test/NetCoreCollectionFixture.cs new file mode 100644 index 0000000..49a14ce --- /dev/null +++ b/NetCore.Test/NetCoreCollectionFixture.cs @@ -0,0 +1,22 @@ +using System; +using Apache.Geode.NetCore; +using Xunit; + +public class NetCoreCollectionFixture : IDisposable +{ + public NetCoreCollectionFixture() + { + client_ = new Client(); + } + public void Dispose() + { + client_.Dispose(); + } + + Client client_; +} + +[CollectionDefinition("Geode .net Core Collection")] +public class NetCoreCollection : ICollectionFixture +{ +} diff --git a/NetCore.Test/ObjectLeakUnitTest.cs b/NetCore.Test/ObjectLeakUnitTest.cs index acfa131..56d41d4 100644 --- a/NetCore.Test/ObjectLeakUnitTest.cs +++ b/NetCore.Test/ObjectLeakUnitTest.cs @@ -4,7 +4,8 @@ using Xunit; namespace GemfireDotNetTest { - public class ObjectLeakUnitTests + [Collection("Geode .net Core Collection")] + public class ObjectLeakUnitTests { [Fact] public void TestLeakCacheFactory() diff --git a/NetCore.Test/PoolFactoryUnitTest.cs b/NetCore.Test/PoolFactoryUnitTest.cs index 766fb40..8ec8dde 100644 --- a/NetCore.Test/PoolFactoryUnitTest.cs +++ b/NetCore.Test/PoolFactoryUnitTest.cs @@ -4,78 +4,46 @@ using Xunit; namespace GemfireDotNetTest { + [Collection("Geode .net Core Collection")] public class PoolFactoryUnitTests { [Fact] public void TestPoolFactoryAddLocator() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - using (var cache = cacheFactory.CreateCache()) - { - using (var poolManager = cache.PoolManager) - { - using (var poolFactory = poolManager.CreatePoolFactory()) - { - poolFactory.AddLocator("localhost", 10334); - } - } - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + using var cache = cacheFactory.CreateCache(); + using var poolManager = cache.PoolManager; + using var poolFactory = poolManager.CreatePoolFactory(); + + poolFactory.AddLocator("localhost", 10334); } [Fact] public void TestPoolFactoryCreatePool() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - using (var cache = cacheFactory.CreateCache()) - { - using (var poolManager = cache.PoolManager) - { - using (var poolFactory = poolManager.CreatePoolFactory()) - { - poolFactory.AddLocator("localhost", 10334); - using (var pool = poolFactory.CreatePool("myPool")) - { - ; - } - } - } - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + using var cache = cacheFactory.CreateCache(); + using var poolManager = cache.PoolManager; + using var poolFactory = poolManager.CreatePoolFactory(); + + poolFactory.AddLocator("localhost", 10334); + using var pool = poolFactory.CreatePool("myPool"); } [Fact] public void TestCreatePoolWithoutPoolManager() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create()) - { - using (var cache = cacheFactory.CreateCache()) - { - using (var poolFactory = cache.PoolFactory) - { - poolFactory.AddLocator("localhost", 10334); - using (var pool = poolFactory.CreatePool("myPool")) - { - } - } - } - } - } + using var cacheFactory = CacheFactory.Create(); + using var cache = cacheFactory.CreateCache(); + using var poolFactory = cache.PoolFactory; + + poolFactory.AddLocator("localhost", 10334); + using var pool = poolFactory.CreatePool("myPool"); } - } + } } diff --git a/NetCore.Test/PoolManagerUnitTest.cs b/NetCore.Test/PoolManagerUnitTest.cs index 5dfec19..14767a5 100644 --- a/NetCore.Test/PoolManagerUnitTest.cs +++ b/NetCore.Test/PoolManagerUnitTest.cs @@ -4,26 +4,16 @@ using Xunit; namespace GemfireDotNetTest { + [Collection("Geode .net Core Collection")] public class PoolManagerUnitTests { [Fact] public void TestPoolManagerCreatePoolFactory() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create()) - { - using (var cache = cacheFactory.CreateCache()) - { - using (var poolManager = cache.PoolManager) - { - using (var poolFactory = poolManager.CreatePoolFactory()) - { - } - } - } - } - } + using var cacheFactory = CacheFactory.Create(); + using var cache = cacheFactory.CreateCache(); + using var poolManager = cache.PoolManager; + using var poolFactory = poolManager.CreatePoolFactory(); } } } diff --git a/NetCore.Test/RegionFactoryUnitTest.cs b/NetCore.Test/RegionFactoryUnitTest.cs index e998931..aee341f 100644 --- a/NetCore.Test/RegionFactoryUnitTest.cs +++ b/NetCore.Test/RegionFactoryUnitTest.cs @@ -23,6 +23,8 @@ namespace GemfireDotNetTest } } + + [Collection("Geode .net Core Collection")] public class RegionFactoryUnitTests { private const string Username1 = "rtimmons"; @@ -30,17 +32,10 @@ namespace GemfireDotNetTest private void createPool(IGeodeCache cache, int port) { - using (var poolManager = cache.PoolManager) - { - using (var poolFactory = poolManager.CreatePoolFactory() - .AddLocator("localhost", port)) - { - using (var pool = poolFactory.CreatePool("myPool")) - { - ; - } - } - } + using var poolManager = cache.PoolManager; + using var poolFactory = poolManager.CreatePoolFactory() + .AddLocator("localhost", port); + using var pool = poolFactory.CreatePool("myPool"); } private void doPutsAndGets(Region region) @@ -72,51 +67,36 @@ namespace GemfireDotNetTest private void CreateRegionAndDoWork(IGeodeCache cache, string regionName, RegionShortcut regionType) { - using (var regionFactory = cache.CreateRegionFactory(regionType)) - { - using (var region = regionFactory.CreateRegion(regionName)) - { - doPutsAndGets(region); - DoRemoves(region); - } - } + using var regionFactory = cache.CreateRegionFactory(regionType); + using var region = regionFactory.CreateRegion(regionName); + + doPutsAndGets(region); + DoRemoves(region); } [Fact] public void TestRegionFactoryCreateProxyRegion() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "none") - .SetProperty("log-file", "geode_native.log")) - { - using (var cache = cacheFactory.CreateCache()) - { - createPool(cache, 10334); - CreateRegionAndDoWork(cache, "exampleRegion", RegionShortcut.Proxy); - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none") + .SetProperty("log-file", "geode_native.log"); + using var cache = cacheFactory.CreateCache(); + + createPool(cache, 10334); + CreateRegionAndDoWork(cache, "exampleRegion", RegionShortcut.Proxy); } [Fact] public void TestRegionFactoryCreateRegionWithAuthentication() { - using (var client = new Client()) - { - using (var cacheFactory = CacheFactory.Create() - .SetProperty("log-level", "debug") - .SetProperty("log-file", "geode_native_with_auth.log")) - { - cacheFactory.AuthInitialize = new SimpleAuthInitialize(); - using (var cache = cacheFactory.CreateCache()) - { - createPool(cache, 10335); - CreateRegionAndDoWork(cache, "authExampleRegion", RegionShortcut.CachingProxy); - } - } - } + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "debug") + .SetProperty("log-file", "geode_native_with_auth.log"); + cacheFactory.AuthInitialize = new SimpleAuthInitialize(); + using var cache = cacheFactory.CreateCache(); + + createPool(cache, 10335); + CreateRegionAndDoWork(cache, "authExampleRegion", RegionShortcut.CachingProxy); } } } diff --git a/NetCore.Test/xunit.runner.json b/NetCore.Test/xunit.runner.json index c977ea0..0243b2c 100644 --- a/NetCore.Test/xunit.runner.json +++ b/NetCore.Test/xunit.runner.json @@ -1,5 +1,5 @@ { "methodDisplay": "classAndMethod", "parallelizeAssembly": true, - "parallelizeTestCollections": false -} + "parallelizeTestCollections": true +} \ No newline at end of file -- 2.25.1