From 0781ac9a5e307e6ed0a0685c1dad98d5fb51b76b Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Thu, 13 Aug 2009 22:12:37 -0400 Subject: * Add ThreadTracker Tests, Tests default thread, Adding Testing and Removing a thread, a dead thread, and a null Thread * Fix a null thread situation --- OpenSim/Framework/Tests/ThreadTrackerTests.cs | 192 ++++++++++++++++++++++++++ OpenSim/Framework/ThreadTracker.cs | 36 +++-- 2 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 OpenSim/Framework/Tests/ThreadTrackerTests.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/Tests/ThreadTrackerTests.cs b/OpenSim/Framework/Tests/ThreadTrackerTests.cs new file mode 100644 index 0000000..37c75ef --- /dev/null +++ b/OpenSim/Framework/Tests/ThreadTrackerTests.cs @@ -0,0 +1,192 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using NUnit.Framework; +using System.Threading; +using System.Collections.Generic; + +namespace OpenSim.Framework.Tests +{ + [TestFixture] + public class ThreadTrackerTests + { + private bool running = true; + private bool running2 = true; + + [Test] + public void DefaultThreadTrackerTest() + { + List lThread = ThreadTracker.GetThreads(); + + /* + foreach (Thread t in lThread) + { + System.Console.WriteLine(t.Name); + } + */ + + Assert.That(lThread.Count == 1); + Assert.That(lThread[0].Name == "ThreadTrackerThread"); + } + + /// + /// Validate that adding a thread to the thread tracker works + /// Validate that removing a thread from the thread tracker also works. + /// + [Test] + public void AddThreadToThreadTrackerTestAndRemoveTest() + { + Thread t = new Thread(run); + t.Name = "TestThread"; + t.Priority = ThreadPriority.BelowNormal; + t.IsBackground = true; + t.SetApartmentState(ApartmentState.MTA); + t.Start(); + ThreadTracker.Add(t); + + List lThread = ThreadTracker.GetThreads(); + + Assert.That(lThread.Count == 2); + + foreach (Thread tr in lThread) + { + Assert.That((tr.Name == "ThreadTrackerThread" || tr.Name == "TestThread")); + } + running = false; + ThreadTracker.Remove(t); + + lThread = ThreadTracker.GetThreads(); + + Assert.That(lThread.Count == 1); + + foreach (Thread tr in lThread) + { + Assert.That((tr.Name == "ThreadTrackerThread")); + } + + + } + + /// + /// Test a dead thread removal by aborting it and setting it's last seen active date to 50 seconds + /// + [Test] + public void DeadThreadTest() + { + Thread t = new Thread(run2); + t.Name = "TestThread"; + t.Priority = ThreadPriority.BelowNormal; + t.IsBackground = true; + t.SetApartmentState(ApartmentState.MTA); + t.Start(); + ThreadTracker.Add(t); + t.Abort(); + Thread.Sleep(5000); + ThreadTracker.m_Threads[1].LastSeenActive = DateTime.Now.Ticks - (50*10000000); + ThreadTracker.CleanUp(); + List lThread = ThreadTracker.GetThreads(); + + Assert.That(lThread.Count == 1); + + foreach (Thread tr in lThread) + { + Assert.That((tr.Name == "ThreadTrackerThread")); + } + } + + [Test] + public void UnstartedThreadTest() + { + Thread t = new Thread(run2); + t.Name = "TestThread"; + t.Priority = ThreadPriority.BelowNormal; + t.IsBackground = true; + t.SetApartmentState(ApartmentState.MTA); + ThreadTracker.Add(t); + ThreadTracker.m_Threads[1].LastSeenActive = DateTime.Now.Ticks - (50 * 10000000); + ThreadTracker.CleanUp(); + List lThread = ThreadTracker.GetThreads(); + + Assert.That(lThread.Count == 1); + + foreach (Thread tr in lThread) + { + Assert.That((tr.Name == "ThreadTrackerThread")); + } + } + + [Test] + public void NullThreadTest() + { + Thread t = null; + ThreadTracker.Add(t); + + List lThread = ThreadTracker.GetThreads(); + + Assert.That(lThread.Count == 1); + + foreach (Thread tr in lThread) + { + Assert.That((tr.Name == "ThreadTrackerThread")); + } + } + + + /// + /// Worker thread 0 + /// + /// + public void run( object o) + { + while (running) + { + Thread.Sleep(5000); + } + } + + /// + /// Worker thread 1 + /// + /// + public void run2(object o) + { + try + { + while (running2) + { + Thread.Sleep(5000); + } + + } + catch (ThreadAbortException) + { + } + } + + } +} diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs index d8bd2c0..fa6f0b8 100644 --- a/OpenSim/Framework/ThreadTracker.cs +++ b/OpenSim/Framework/ThreadTracker.cs @@ -77,12 +77,15 @@ namespace OpenSim.Framework public static void Add(Thread thread) { #if DEBUG - lock (m_Threads) + if (thread != null) { - ThreadTrackerItem tti = new ThreadTrackerItem(); - tti.Thread = thread; - tti.LastSeenActive = DateTime.Now.Ticks; - m_Threads.Add(tti); + lock (m_Threads) + { + ThreadTrackerItem tti = new ThreadTrackerItem(); + tti.Thread = thread; + tti.LastSeenActive = DateTime.Now.Ticks; + m_Threads.Add(tti); + } } #endif } @@ -107,16 +110,25 @@ namespace OpenSim.Framework { foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) { - if (tti.Thread.IsAlive) + try { - // Its active - tti.LastSeenActive = DateTime.Now.Ticks; + + + if (tti.Thread.IsAlive) + { + // Its active + tti.LastSeenActive = DateTime.Now.Ticks; + } + else + { + // Its not active -- if its expired then remove it + if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) + m_Threads.Remove(tti); + } } - else + catch (NullReferenceException) { - // Its not active -- if its expired then remove it - if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) - m_Threads.Remove(tti); + m_Threads.Remove(tti); } } } -- cgit v1.1 From 6ece8d86e051ffb58afd01d92ee780d98eca997a Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Thu, 13 Aug 2009 23:06:29 -0400 Subject: Deal with possible race in TestAddNeighborRegion in ScenePresenceTests --- .../Framework/Scenes/Tests/ScenePresenceTests.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs index 1836447..a3672d5 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs @@ -147,7 +147,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelper.InMethod(); string reason; + + if (acd1 == null) + fixNullPresence(); + scene.NewUserConnection(acd1, out reason); + if (testclient == null) + testclient = new TestClient(acd1, scene); scene.AddNewClient(testclient); ScenePresence presence = scene.GetScenePresence(agent1); @@ -162,6 +168,24 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(neighbours.Count, Is.EqualTo(2)); } + public void fixNullPresence() + { + string firstName = "testfirstname"; + + AgentCircuitData agent = new AgentCircuitData(); + agent.AgentID = agent1; + agent.firstname = firstName; + agent.lastname = "testlastname"; + agent.SessionID = UUID.Zero; + agent.SecureSessionID = UUID.Zero; + agent.circuitcode = 123; + agent.BaseFolder = UUID.Zero; + agent.InventoryFolder = UUID.Zero; + agent.startpos = Vector3.Zero; + agent.CapsPath = GetRandomCapsObjectPath(); + + acd1 = agent; + } [Test] public void T013_TestRemoveNeighbourRegion() -- cgit v1.1 From 7a2a2e68e7e235b9d79c09d98a4cf0b6f87a2a85 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Aug 2009 14:18:56 +0100 Subject: Remove the script sponsor logic because scripts are timing out again. This needs to be looked into. This commit, unfortunately, reinstates a memory leak in regions that see significant script fluctuation, e.g. lots of scripted attachments, or script development. --- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 6 +++--- .../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 6 +++--- .../Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | 15 ++++++++------- .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 7 +------ 4 files changed, 15 insertions(+), 19 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ff85b96..691732a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -125,9 +125,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (lease.CurrentState == LeaseState.Initial) { - lease.InitialLeaseTime = TimeSpan.FromMinutes(1.0); - lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); - lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); + lease.InitialLeaseTime = TimeSpan.FromMinutes(0); +// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); +// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); } return lease; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 6539bda..6e3a3ab 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -166,9 +166,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (lease.CurrentState == LeaseState.Initial) { - lease.InitialLeaseTime = TimeSpan.FromMinutes(1.0); - lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); - lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); + lease.InitialLeaseTime = TimeSpan.FromMinutes(0); +// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); +// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); } return lease; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index d119a77..838cafb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs @@ -42,16 +42,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public partial class ScriptBaseClass : MarshalByRefObject, IScript { private Dictionary inits = new Dictionary(); - private ScriptSponsor m_sponser; +// private ScriptSponsor m_sponser; public override Object InitializeLifetimeService() { ILease lease = (ILease)base.InitializeLifetimeService(); if (lease.CurrentState == LeaseState.Initial) { - lease.InitialLeaseTime = TimeSpan.FromMinutes(1.0); - lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); - lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); + // Infinite + lease.InitialLeaseTime = TimeSpan.FromMinutes(0); +// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); +// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); } return lease; } @@ -79,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase } } - m_sponser = new ScriptSponsor(); +// m_sponser = new ScriptSponsor(); } private Executor m_Executor = null; @@ -112,7 +113,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return; ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); - lease.Register(m_sponser); +// lease.Register(m_sponser); MethodInfo mi = inits[api]; @@ -126,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public void Close() { - m_sponser.Close(); +// m_sponser.Close(); } public Dictionary GetVars() diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 4211ced..7bbaac0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -53,7 +53,7 @@ using OpenSim.Region.ScriptEngine.Interfaces; namespace OpenSim.Region.ScriptEngine.Shared.Instance { - public class ScriptInstance : MarshalByRefObject, IScriptInstance, ISponsor + public class ScriptInstance : MarshalByRefObject, IScriptInstance { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -1006,10 +1006,5 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { return true; } - - public TimeSpan Renewal(ILease lease) - { - return lease.InitialLeaseTime; - } } } -- cgit v1.1 From a851b68333756d11be2c5afe2aa76c58ae771b4b Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Aug 2009 14:27:56 +0100 Subject: Remove one more sponsor reference --- OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 7bbaac0..225126d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -261,7 +261,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance "SecondLife.Script"); ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); - lease.Register(this); +// lease.Register(this); } catch (Exception) { -- cgit v1.1 From c18f7560d9ab13c0c7a73c679383ceee13d1b1e3 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 9 Aug 2009 02:05:21 -0500 Subject: Adding in Reflection-based testing, to ensure that all properties are covered. --- OpenSim/Data/Tests/PropertyCompareConstraint.cs | 298 ++++++++++++++++++++++++ OpenSim/Data/Tests/ScrambleForTesting.cs | 102 ++++++++ 2 files changed, 400 insertions(+) create mode 100644 OpenSim/Data/Tests/PropertyCompareConstraint.cs create mode 100644 OpenSim/Data/Tests/ScrambleForTesting.cs (limited to 'OpenSim') diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs new file mode 100644 index 0000000..678501e --- /dev/null +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using NUnit.Framework; +using NUnit.Framework.Constraints; +using NUnit.Framework.SyntaxHelpers; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Data.Tests +{ + public static class Constraints + { + //This is here because C# has a gap in the language, you can't infer type from a constructor + public static PropertyCompareConstraint PropertyCompareConstraint(T expected) + { + return new PropertyCompareConstraint(expected); + } + } + + public class PropertyCompareConstraint : NUnit.Framework.Constraints.Constraint + { + private readonly object _expected; + //the reason everywhere uses propertyNames.Reverse().ToArray() is because the stack is backwards of the order we want to display the properties in. + private string failingPropertyName = string.Empty; + private object failingExpected; + private object failingActual; + + public PropertyCompareConstraint(T expected) + { + _expected = expected; + } + + public override bool Matches(object actual) + { + return ObjectCompare(_expected, actual, new Stack()); + } + + private bool ObjectCompare(object expected, object actual, Stack propertyNames) + { + if (actual.GetType() != expected.GetType()) + { + propertyNames.Push("GetType()"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actual.GetType(); + failingExpected = expected.GetType(); + return false; + } + + if(actual.GetType() == typeof(Color)) + { + Color actualColor = (Color) actual; + Color expectedColor = (Color) expected; + if (actualColor.R != expectedColor.R) + { + propertyNames.Push("R"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualColor.R; + failingExpected = expectedColor.R; + return false; + } + if (actualColor.G != expectedColor.G) + { + propertyNames.Push("G"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualColor.G; + failingExpected = expectedColor.G; + return false; + } + if (actualColor.B != expectedColor.B) + { + propertyNames.Push("B"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualColor.B; + failingExpected = expectedColor.B; + return false; + } + if (actualColor.A != expectedColor.A) + { + propertyNames.Push("A"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualColor.A; + failingExpected = expectedColor.A; + return false; + } + return true; + } + + //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors. + PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); + foreach (var property in properties) + { + if (ignores.Contains(property.Name)) + continue; + + object actualValue = property.GetValue(actual, null); + object expectedValue = property.GetValue(expected, null); + + //If they are both null, they are equal + if (actualValue == null && expectedValue == null) + continue; + + //If only one is null, then they aren't + if (actualValue == null || expectedValue == null) + { + propertyNames.Push(property.Name); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualValue; + failingExpected = expectedValue; + return false; + } + + IComparable comp = actualValue as IComparable; + if (comp != null) + { + if (comp.CompareTo(expectedValue) != 0) + { + propertyNames.Push(property.Name); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + propertyNames.Pop(); + failingActual = actualValue; + failingExpected = expectedValue; + return false; + } + continue; + } + + IEnumerable arr = actualValue as IEnumerable; + if (arr != null) + { + List actualList = arr.Cast().ToList(); + List expectedList = ((IEnumerable)expectedValue).Cast().ToList(); + if (actualList.Count != expectedList.Count) + { + propertyNames.Push(property.Name); + propertyNames.Push("Count"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actualList.Count; + failingExpected = expectedList.Count; + propertyNames.Pop(); + propertyNames.Pop(); + } + //Todo: A value-wise comparison of all of the values. + //Everything seems okay... + continue; + } + + propertyNames.Push(property.Name); + if (!ObjectCompare(expectedValue, actualValue, propertyNames)) + return false; + propertyNames.Pop(); + } + + return true; + } + + public override void WriteDescriptionTo(MessageWriter writer) + { + writer.WriteExpectedValue(failingExpected); + } + + public override void WriteActualValueTo(MessageWriter writer) + { + writer.WriteActualValue(failingActual); + writer.WriteLine(); + writer.Write(" On Property: " + failingPropertyName); + } + + //These notes assume the lambda: (x=>x.Parent.Value) + //ignores should really contain like a fully dotted version of the property name, but I'm starting with small steps + readonly List ignores = new List(); + public PropertyCompareConstraint IgnoreProperty(Expression> func) + { + Expression express = func.Body; + PullApartExpression(express); + + return this; + } + + private void PullApartExpression(Expression express) + { + //This deals with any casts... like implicit casts to object. Not all UnaryExpression are casts, but this is a first attempt. + if (express is UnaryExpression) + PullApartExpression(((UnaryExpression)express).Operand); + if (express is MemberExpression) + { + //If the inside of the lambda is the access to x, we've hit the end of the chain. + // We should track by the fully scoped parameter name, but this is the first rev of doing this. + if (((MemberExpression)express).Expression is ParameterExpression) + { + ignores.Add(((MemberExpression)express).Member.Name); + } + else + { + //Otherwise there could be more parameters inside... + PullApartExpression(((MemberExpression)express).Expression); + } + } + } + } + + [TestFixture] + public class PropertyCompareConstraintTest + { + public class HasInt + { + public int TheValue { get; set; } + } + + [Test] + public void IntShouldMatch() + { + HasInt actual = new HasInt { TheValue = 5 }; + HasInt expected = new HasInt { TheValue = 5 }; + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.True); + } + + [Test] + public void IntShouldNotMatch() + { + HasInt actual = new HasInt { TheValue = 5 }; + HasInt expected = new HasInt { TheValue = 4 }; + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.False); + } + + + [Test] + public void IntShouldIgnore() + { + HasInt actual = new HasInt { TheValue = 5 }; + HasInt expected = new HasInt { TheValue = 4 }; + var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x=>x.TheValue); + + Assert.That(constraint.Matches(actual), Is.True); + } + + [Test] + public void AssetShouldMatch() + { + UUID uuid1 = UUID.Random(); + AssetBase actual = new AssetBase(uuid1, "asset one"); + AssetBase expected = new AssetBase(uuid1, "asset one"); + + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.True); + } + + [Test] + public void AssetShouldNotMatch() + { + UUID uuid1 = UUID.Random(); + AssetBase actual = new AssetBase(uuid1, "asset one"); + AssetBase expected = new AssetBase(UUID.Random(), "asset one"); + + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.False); + } + + [Test] + public void AssetShouldNotMatch2() + { + UUID uuid1 = UUID.Random(); + AssetBase actual = new AssetBase(uuid1, "asset one"); + AssetBase expected = new AssetBase(uuid1, "asset two"); + + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.False); + } + + [Test] + public void TestColors() + { + Color actual = Color.Red; + Color expected = Color.FromArgb(actual.A, actual.R, actual.G, actual.B); + + var constraint = Constraints.PropertyCompareConstraint(expected); + + Assert.That(constraint.Matches(actual), Is.True); + } + } +} \ No newline at end of file diff --git a/OpenSim/Data/Tests/ScrambleForTesting.cs b/OpenSim/Data/Tests/ScrambleForTesting.cs new file mode 100644 index 0000000..c6e467f --- /dev/null +++ b/OpenSim/Data/Tests/ScrambleForTesting.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections; +using System.Reflection; +using System.Text; +using NUnit.Framework; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Data.Tests +{ + public static class ScrambleForTesting + { + private static readonly Random random = new Random(); + public static void Scramble(object obj) + { + PropertyInfo[] properties = obj.GetType().GetProperties(); + foreach (var property in properties) + { + //Skip indexers of classes. We will assume that everything that has an indexer + // is also IEnumberable. May not always be true, but should be true normally. + if(property.GetIndexParameters().Length > 0) + continue; + + RandomizeProperty(obj, property, null); + } + //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize + // everything inside of it. + IEnumerable enumerable = obj as IEnumerable; + if(enumerable != null) + { + foreach (object value in enumerable) + { + Scramble(value); + } + } + } + + private static void RandomizeProperty(object obj, PropertyInfo property, object[] index) + { + Type t = property.PropertyType; + if (!property.CanWrite) + return; + object value = property.GetValue(obj, index); + if (value == null) + return; + + if (t == typeof (string)) + property.SetValue(obj, RandomName(), index); + else if (t == typeof (UUID)) + property.SetValue(obj, UUID.Random(), index); + else if (t == typeof (sbyte)) + property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index); + else if (t == typeof (short)) + property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index); + else if (t == typeof (int)) + property.SetValue(obj, random.Next(), index); + else if (t == typeof (long)) + property.SetValue(obj, random.Next() * int.MaxValue, index); + else if (t == typeof (byte)) + property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index); + else if (t == typeof (ushort)) + property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index); + else if (t == typeof (uint)) + property.SetValue(obj, Convert.ToUInt32(random.Next()), index); + else if (t == typeof (ulong)) + property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index); + else if (t == typeof (bool)) + property.SetValue(obj, true, index); + else if (t == typeof (byte[])) + { + byte[] bytes = new byte[30]; + random.NextBytes(bytes); + property.SetValue(obj, bytes, index); + } + else + Scramble(value); + } + + private static string RandomName() + { + StringBuilder name = new StringBuilder(); + int size = random.Next(5, 12); + for (int i = 0; i < size; i++) + { + char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); + name.Append(ch); + } + return name.ToString(); + } + } + + [TestFixture] + public class ScrableForTestingTest + { + [Test] + public void TestScramble() + { + AssetBase actual = new AssetBase(UUID.Random(), "asset one"); + ScrambleForTesting.Scramble(actual); + } + } +} \ No newline at end of file -- cgit v1.1 From 31820b002618b773b38ce1c1a073383cec89277b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 14 Aug 2009 18:36:09 +0100 Subject: minor formatting adjustments --- OpenSim/Data/Tests/BasicUserTest.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index d3e6f41..4e4ddc8 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs @@ -204,8 +204,16 @@ namespace OpenSim.Data.Tests UUID webloginkey = UUID.Random(); uint homeregx = (uint) random.Next(); uint homeregy = (uint) random.Next(); - Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); - Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); + Vector3 homeloc + = new Vector3( + (float)Math.Round(random.NextDouble(), 5), + (float)Math.Round(random.NextDouble(), 5), + (float)Math.Round(random.NextDouble(), 5)); + Vector3 homelookat + = new Vector3( + (float)Math.Round(random.NextDouble(), 5), + (float)Math.Round(random.NextDouble(), 5), + (float)Math.Round(random.NextDouble(), 5)); int created = random.Next(); int lastlogin = random.Next(); string userinvuri = RandomName(); -- cgit v1.1 From 957962b48276861948267701159775c2361b235b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 14 Aug 2009 19:06:24 +0100 Subject: Remove NRE catching on TestReplicateArchivePathToUserInventory() since race failure now appears to have gone --- .../Archiver/Tests/InventoryArchiverTests.cs | 36 ++++++---------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 28b4d64..2169e36 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -395,17 +395,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, InventoryReceived); Monitor.Wait(this, 60000); } - - //userInfo.FetchInventory(); - /* - for (int i = 0 ; i < 50 ; i++) - { - if (userInfo.HasReceivedInventory == true) - break; - Thread.Sleep(200); - } - Assert.That(userInfo.HasReceivedInventory, Is.True, "FetchInventory timed out (10 seconds)"); - */ Console.WriteLine("userInfo.RootFolder 1: {0}", userInfo.RootFolder); @@ -429,22 +418,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder); - try - { - new InventoryArchiveReadRequest(userInfo, null, (Stream)null, null, null) - .ReplicateArchivePathToUserInventory(itemArchivePath, false, userInfo.RootFolder, foldersCreated, nodesLoaded); - - Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder); - InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a"); - Assert.That(folder1, Is.Not.Null, "Could not find folder a"); - InventoryFolderImpl folder2 = folder1.FindFolderByPath("b"); - Assert.That(folder2, Is.Not.Null, "Could not find folder b"); - } - catch (NullReferenceException e) - { - // Non fatal for now until we resolve the race condition - Console.WriteLine("Test failed with {0}", e); - } + new InventoryArchiveReadRequest(userInfo, null, (Stream)null, null, null) + .ReplicateArchivePathToUserInventory( + itemArchivePath, false, userInfo.RootFolder, foldersCreated, nodesLoaded); + + Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder); + InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a"); + Assert.That(folder1, Is.Not.Null, "Could not find folder a"); + InventoryFolderImpl folder2 = folder1.FindFolderByPath("b"); + Assert.That(folder2, Is.Not.Null, "Could not find folder b"); } } } -- cgit v1.1 From dce81225c50e9ce15187bfb412870716127a31fa Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Fri, 14 Aug 2009 14:15:49 -0400 Subject: * allocate the dictionary for AgentCircuitData.ChildrenCapSeeds when creating the circuitdata object to see if it's the cause of a null reference exception in the TestAddNeighbourRegio test --- OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs index a3672d5..88452d2 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs @@ -113,6 +113,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests agent.InventoryFolder = UUID.Zero; agent.startpos = Vector3.Zero; agent.CapsPath = GetRandomCapsObjectPath(); + agent.ChildrenCapSeeds = new Dictionary(); string reason; scene.NewUserConnection(agent, out reason); -- cgit v1.1 From a668a5b0d39f04497e5ea170e5af0e659a43febb Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 14 Aug 2009 19:59:42 +0100 Subject: Add standard doc and standard doc formatting to IAssetService --- .../Archiver/Tests/InventoryArchiverTests.cs | 2 +- OpenSim/Services/Interfaces/IAssetService.cs | 46 +++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 2169e36..9784fcf 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -82,7 +82,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests InventoryArchiverModule archiverModule = new InventoryArchiverModule(); - Scene scene = SceneSetupHelpers.SetupScene(""); + Scene scene = SceneSetupHelpers.SetupScene("Inventory"); SceneSetupHelpers.SetupSceneModules(scene, archiverModule); CommunicationsManager cm = scene.CommsManager; diff --git a/OpenSim/Services/Interfaces/IAssetService.cs b/OpenSim/Services/Interfaces/IAssetService.cs index ec8a71b..6dfe78d 100644 --- a/OpenSim/Services/Interfaces/IAssetService.cs +++ b/OpenSim/Services/Interfaces/IAssetService.cs @@ -34,25 +34,53 @@ namespace OpenSim.Services.Interfaces public interface IAssetService { - // Three different ways to retrieve an asset - // + /// + /// Get an asset synchronously. + /// + /// + /// AssetBase Get(string id); + + /// + /// Get an asset's metadata + /// + /// + /// AssetMetadata GetMetadata(string id); + byte[] GetData(string id); + /// + /// Get an asset asynchronously + /// + /// The asset id + /// Represents the requester. Passed back via the handler + /// The handler to call back once the asset has been retrieved + /// True if the id was parseable, false otherwise bool Get(string id, Object sender, AssetRetrieved handler); - // Creates a new asset - // Returns a random ID if none is passed into it - // + /// + /// Creates a new asset + /// + /// Returns a random ID if none is passed into it + /// + /// string Store(AssetBase asset); - // Attachments and bare scripts need this!! - // + /// + /// Update an asset's content + /// + /// Attachments and bare scripts need this!! + /// + /// + /// bool UpdateContent(string id, byte[] data); - // Kill an asset - // + /// + /// Delete an asset + /// + /// + /// bool Delete(string id); } } -- cgit v1.1 From ff28ecee1b35ba24ec538d8ed018c764476c62b4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 14 Aug 2009 20:07:13 +0100 Subject: Re-enable TestSaveIarV0_1() Implement more parts of TestAssetService --- .../Inventory/Archiver/Tests/InventoryArchiverTests.cs | 2 +- OpenSim/Tests/Common/Mock/TestAssetService.cs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 9784fcf..c66678f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -74,7 +74,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests /// /// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet). /// - //[Test] + [Test] public void TestSaveIarV0_1() { TestHelper.InMethod(); diff --git a/OpenSim/Tests/Common/Mock/TestAssetService.cs b/OpenSim/Tests/Common/Mock/TestAssetService.cs index 5f1184b..81f123a 100644 --- a/OpenSim/Tests/Common/Mock/TestAssetService.cs +++ b/OpenSim/Tests/Common/Mock/TestAssetService.cs @@ -45,7 +45,13 @@ namespace OpenSim.Tests.Common.Mock public AssetBase Get(string id) { - return Assets[ id ]; + AssetBase asset; + if (Assets.ContainsKey(id)) + asset = Assets[id]; + else + asset = null; + + return asset; } public AssetMetadata GetMetadata(string id) @@ -59,8 +65,10 @@ namespace OpenSim.Tests.Common.Mock } public bool Get(string id, object sender, AssetRetrieved handler) - { - throw new NotImplementedException(); + { + handler(id, sender, Get(id)); + + return true; } public string Store(AssetBase asset) -- cgit v1.1 From e17a2331a02d36a3b9f6f37630601ab4a63a4fb2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 14 Aug 2009 20:38:56 +0100 Subject: * Re-enable TestLoadIarV0_1ExistingUsers() --- .../Inventory/Archiver/Tests/InventoryArchiverTests.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index c66678f..470a386 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -222,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where /// an account exists with the creator name. /// - //[Test] + [Test] public void TestLoadIarV0_1ExistingUsers() { TestHelper.InMethod(); @@ -262,7 +262,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests InventoryArchiverModule archiverModule = new InventoryArchiverModule(); // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene - Scene scene = SceneSetupHelpers.SetupScene(); + Scene scene = SceneSetupHelpers.SetupScene("inventory"); IUserAdminService userAdminService = scene.CommsManager.UserAdminService; SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); @@ -276,16 +276,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); - //userInfo.FetchInventory(); - /* - for (int i = 0 ; i < 50 ; i++) - { - if (userInfo.HasReceivedInventory == true) - break; - Thread.Sleep(200); - } - Assert.That(userInfo.HasReceivedInventory, Is.True, "FetchInventory timed out (10 seconds)"); - */ + InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); Assert.That(foundItem, Is.Not.Null, "Didn't find loaded item"); Assert.That( -- cgit v1.1