diff options
Diffstat (limited to 'OpenSim/Tests/Performance')
-rw-r--r-- | OpenSim/Tests/Performance/NPCPerformanceTests.cs | 191 | ||||
-rw-r--r-- | OpenSim/Tests/Performance/ObjectPerformanceTests.cs | 174 | ||||
-rw-r--r-- | OpenSim/Tests/Performance/ScriptPerformanceTests.cs | 167 |
3 files changed, 532 insertions, 0 deletions
diff --git a/OpenSim/Tests/Performance/NPCPerformanceTests.cs b/OpenSim/Tests/Performance/NPCPerformanceTests.cs new file mode 100644 index 0000000..e222dc2 --- /dev/null +++ b/OpenSim/Tests/Performance/NPCPerformanceTests.cs | |||
@@ -0,0 +1,191 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Communications; | ||
38 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | ||
40 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
41 | using OpenSim.Region.CoreModules.Framework.UserManagement; | ||
42 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; | ||
43 | using OpenSim.Region.Framework.Interfaces; | ||
44 | using OpenSim.Region.Framework.Scenes; | ||
45 | using OpenSim.Region.OptionalModules.World.NPC; | ||
46 | using OpenSim.Services.AvatarService; | ||
47 | using OpenSim.Tests.Common; | ||
48 | |||
49 | namespace OpenSim.Tests.Performance | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// NPC performance tests | ||
53 | /// </summary> | ||
54 | /// <remarks> | ||
55 | /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached, | ||
56 | /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller | ||
57 | /// earlier tests. | ||
58 | /// </remarks> | ||
59 | [TestFixture] | ||
60 | public class NPCPerformanceTests : OpenSimTestCase | ||
61 | { | ||
62 | private TestScene scene; | ||
63 | private AvatarFactoryModule afm; | ||
64 | private UserManagementModule umm; | ||
65 | private AttachmentsModule am; | ||
66 | |||
67 | [TestFixtureSetUp] | ||
68 | public void FixtureInit() | ||
69 | { | ||
70 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
71 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
72 | } | ||
73 | |||
74 | [TestFixtureTearDown] | ||
75 | public void TearDown() | ||
76 | { | ||
77 | scene.Close(); | ||
78 | scene = null; | ||
79 | GC.Collect(); | ||
80 | GC.WaitForPendingFinalizers(); | ||
81 | |||
82 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
83 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
84 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
85 | } | ||
86 | |||
87 | [SetUp] | ||
88 | public void Init() | ||
89 | { | ||
90 | IConfigSource config = new IniConfigSource(); | ||
91 | config.AddConfig("NPC"); | ||
92 | config.Configs["NPC"].Set("Enabled", "true"); | ||
93 | config.AddConfig("Modules"); | ||
94 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
95 | |||
96 | afm = new AvatarFactoryModule(); | ||
97 | umm = new UserManagementModule(); | ||
98 | am = new AttachmentsModule(); | ||
99 | |||
100 | scene = new SceneHelpers().SetupScene(); | ||
101 | SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule()); | ||
102 | } | ||
103 | |||
104 | [Test] | ||
105 | public void Test_0001_AddRemove100NPCs() | ||
106 | { | ||
107 | TestHelpers.InMethod(); | ||
108 | // log4net.Config.XmlConfigurator.Configure(); | ||
109 | |||
110 | TestAddRemoveNPCs(100); | ||
111 | } | ||
112 | |||
113 | [Test] | ||
114 | public void Test_0002_AddRemove1000NPCs() | ||
115 | { | ||
116 | TestHelpers.InMethod(); | ||
117 | // log4net.Config.XmlConfigurator.Configure(); | ||
118 | |||
119 | TestAddRemoveNPCs(1000); | ||
120 | } | ||
121 | |||
122 | [Test] | ||
123 | public void Test_0003_AddRemove2000NPCs() | ||
124 | { | ||
125 | TestHelpers.InMethod(); | ||
126 | // log4net.Config.XmlConfigurator.Configure(); | ||
127 | |||
128 | TestAddRemoveNPCs(2000); | ||
129 | } | ||
130 | |||
131 | private void TestAddRemoveNPCs(int numberOfNpcs) | ||
132 | { | ||
133 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
134 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | ||
135 | |||
136 | // 8 is the index of the first baked texture in AvatarAppearance | ||
137 | UUID originalFace8TextureId = TestHelpers.ParseTail(0x10); | ||
138 | Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero); | ||
139 | Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8); | ||
140 | originalTef.TextureID = originalFace8TextureId; | ||
141 | |||
142 | // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell | ||
143 | // ScenePresence.SendInitialData() to reset our entire appearance. | ||
144 | scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); | ||
145 | |||
146 | /* | ||
147 | afm.SetAppearance(sp, originalTe, null); | ||
148 | |||
149 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | ||
150 | |||
151 | List<UUID> npcs = new List<UUID>(); | ||
152 | |||
153 | long startGcMemory = GC.GetTotalMemory(true); | ||
154 | Stopwatch sw = new Stopwatch(); | ||
155 | sw.Start(); | ||
156 | |||
157 | for (int i = 0; i < numberOfNpcs; i++) | ||
158 | { | ||
159 | npcs.Add( | ||
160 | npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance)); | ||
161 | } | ||
162 | |||
163 | for (int i = 0; i < numberOfNpcs; i++) | ||
164 | { | ||
165 | Assert.That(npcs[i], Is.Not.Null); | ||
166 | |||
167 | ScenePresence npc = scene.GetScenePresence(npcs[i]); | ||
168 | Assert.That(npc, Is.Not.Null); | ||
169 | } | ||
170 | |||
171 | for (int i = 0; i < numberOfNpcs; i++) | ||
172 | { | ||
173 | Assert.That(npcModule.DeleteNPC(npcs[i], scene), Is.True); | ||
174 | ScenePresence npc = scene.GetScenePresence(npcs[i]); | ||
175 | Assert.That(npc, Is.Null); | ||
176 | } | ||
177 | |||
178 | sw.Stop(); | ||
179 | |||
180 | long endGcMemory = GC.GetTotalMemory(true); | ||
181 | |||
182 | Console.WriteLine("Took {0} ms", sw.ElapsedMilliseconds); | ||
183 | Console.WriteLine( | ||
184 | "End {0} MB, Start {1} MB, Diff {2} MB", | ||
185 | endGcMemory / 1024 / 1024, | ||
186 | startGcMemory / 1024 / 1024, | ||
187 | (endGcMemory - startGcMemory) / 1024 / 1024); | ||
188 | */ | ||
189 | } | ||
190 | } | ||
191 | } | ||
diff --git a/OpenSim/Tests/Performance/ObjectPerformanceTests.cs b/OpenSim/Tests/Performance/ObjectPerformanceTests.cs new file mode 100644 index 0000000..9dad423 --- /dev/null +++ b/OpenSim/Tests/Performance/ObjectPerformanceTests.cs | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Diagnostics; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Tests.Common; | ||
37 | |||
38 | namespace OpenSim.Tests.Performance | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Object performance tests | ||
42 | /// </summary> | ||
43 | /// <remarks> | ||
44 | /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached, | ||
45 | /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller | ||
46 | /// earlier tests. | ||
47 | /// </remarks> | ||
48 | [TestFixture] | ||
49 | public class ObjectPerformanceTests : OpenSimTestCase | ||
50 | { | ||
51 | [TearDown] | ||
52 | public void TearDown() | ||
53 | { | ||
54 | GC.Collect(); | ||
55 | GC.WaitForPendingFinalizers(); | ||
56 | } | ||
57 | |||
58 | // [Test] | ||
59 | // public void Test0000Clean() | ||
60 | // { | ||
61 | // TestHelpers.InMethod(); | ||
62 | //// log4net.Config.XmlConfigurator.Configure(); | ||
63 | // | ||
64 | // TestAddObjects(200000); | ||
65 | // } | ||
66 | |||
67 | [Test] | ||
68 | public void Test_0001_10K_1PrimObjects() | ||
69 | { | ||
70 | TestHelpers.InMethod(); | ||
71 | // log4net.Config.XmlConfigurator.Configure(); | ||
72 | |||
73 | TestAddObjects(1, 10000); | ||
74 | } | ||
75 | |||
76 | [Test] | ||
77 | public void Test_0002_100K_1PrimObjects() | ||
78 | { | ||
79 | TestHelpers.InMethod(); | ||
80 | // log4net.Config.XmlConfigurator.Configure(); | ||
81 | |||
82 | TestAddObjects(1, 100000); | ||
83 | } | ||
84 | |||
85 | [Test] | ||
86 | public void Test_0003_200K_1PrimObjects() | ||
87 | { | ||
88 | TestHelpers.InMethod(); | ||
89 | // log4net.Config.XmlConfigurator.Configure(); | ||
90 | |||
91 | TestAddObjects(1, 200000); | ||
92 | } | ||
93 | |||
94 | [Test] | ||
95 | public void Test_0011_100_100PrimObjects() | ||
96 | { | ||
97 | TestHelpers.InMethod(); | ||
98 | // log4net.Config.XmlConfigurator.Configure(); | ||
99 | |||
100 | TestAddObjects(100, 100); | ||
101 | } | ||
102 | |||
103 | [Test] | ||
104 | public void Test_0012_1K_100PrimObjects() | ||
105 | { | ||
106 | TestHelpers.InMethod(); | ||
107 | // log4net.Config.XmlConfigurator.Configure(); | ||
108 | |||
109 | TestAddObjects(100, 1000); | ||
110 | } | ||
111 | |||
112 | [Test] | ||
113 | public void Test_0013_2K_100PrimObjects() | ||
114 | { | ||
115 | TestHelpers.InMethod(); | ||
116 | // log4net.Config.XmlConfigurator.Configure(); | ||
117 | |||
118 | TestAddObjects(100, 2000); | ||
119 | } | ||
120 | |||
121 | private void TestAddObjects(int primsInEachObject, int objectsToAdd) | ||
122 | { | ||
123 | UUID ownerId = new UUID("F0000000-0000-0000-0000-000000000000"); | ||
124 | |||
125 | // Using a local variable for scene, at least on mono 2.6.7, means that it's much more likely to be garbage | ||
126 | // collected when we teardown this test. If it's done in a member variable, even if that is subsequently | ||
127 | // nulled out, the garbage collect can be delayed. | ||
128 | TestScene scene = new SceneHelpers().SetupScene(); | ||
129 | |||
130 | // Process process = Process.GetCurrentProcess(); | ||
131 | // long startProcessMemory = process.PrivateMemorySize64; | ||
132 | long startGcMemory = GC.GetTotalMemory(true); | ||
133 | DateTime start = DateTime.Now; | ||
134 | |||
135 | for (int i = 1; i <= objectsToAdd; i++) | ||
136 | { | ||
137 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(primsInEachObject, ownerId, "part_", i); | ||
138 | Assert.That(scene.AddNewSceneObject(so, false), Is.True, string.Format("Object {0} was not created", i)); | ||
139 | } | ||
140 | |||
141 | TimeSpan elapsed = DateTime.Now - start; | ||
142 | // long processMemoryAlloc = process.PrivateMemorySize64 - startProcessMemory; | ||
143 | long endGcMemory = GC.GetTotalMemory(false); | ||
144 | |||
145 | for (int i = 1; i <= objectsToAdd; i++) | ||
146 | { | ||
147 | Assert.That( | ||
148 | scene.GetSceneObjectGroup(TestHelpers.ParseTail(i)), | ||
149 | Is.Not.Null, | ||
150 | string.Format("Object {0} could not be retrieved", i)); | ||
151 | } | ||
152 | |||
153 | // When a scene object is added to a scene, it is placed in the update list for sending to viewers | ||
154 | // (though in this case we have none). When it is deleted, it is not removed from the update which is | ||
155 | // fine since it will later be ignored. | ||
156 | // | ||
157 | // However, that means that we need to manually run an update here to clear out that list so that deleted | ||
158 | // objects will be clean up by the garbage collector before the next stress test is run. | ||
159 | scene.Update(1); | ||
160 | |||
161 | Console.WriteLine( | ||
162 | "Took {0}ms, {1}MB ({2} - {3}) to create {4} objects each containing {5} prim(s)", | ||
163 | Math.Round(elapsed.TotalMilliseconds), | ||
164 | (endGcMemory - startGcMemory) / 1024 / 1024, | ||
165 | endGcMemory / 1024 / 1024, | ||
166 | startGcMemory / 1024 / 1024, | ||
167 | objectsToAdd, | ||
168 | primsInEachObject); | ||
169 | |||
170 | scene.Close(); | ||
171 | // scene = null; | ||
172 | } | ||
173 | } | ||
174 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tests/Performance/ScriptPerformanceTests.cs b/OpenSim/Tests/Performance/ScriptPerformanceTests.cs new file mode 100644 index 0000000..028f4b0 --- /dev/null +++ b/OpenSim/Tests/Performance/ScriptPerformanceTests.cs | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.CoreModules.Scripting.WorldComm; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.ScriptEngine.XEngine; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Tests.Performance | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// Script performance tests | ||
48 | /// </summary> | ||
49 | /// <remarks> | ||
50 | /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached, | ||
51 | /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller | ||
52 | /// earlier tests. | ||
53 | /// </remarks> | ||
54 | [TestFixture] | ||
55 | public class ScriptPerformanceTests : OpenSimTestCase | ||
56 | { | ||
57 | private TestScene m_scene; | ||
58 | private XEngine m_xEngine; | ||
59 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
60 | |||
61 | private int m_expectedChatMessages; | ||
62 | private List<OSChatMessage> m_osChatMessagesReceived = new List<OSChatMessage>(); | ||
63 | |||
64 | [SetUp] | ||
65 | public void Init() | ||
66 | { | ||
67 | //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin"); | ||
68 | // Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); | ||
69 | m_xEngine = new XEngine(); | ||
70 | |||
71 | // Necessary to stop serialization complaining | ||
72 | WorldCommModule wcModule = new WorldCommModule(); | ||
73 | |||
74 | IniConfigSource configSource = new IniConfigSource(); | ||
75 | |||
76 | IConfig startupConfig = configSource.AddConfig("Startup"); | ||
77 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
78 | |||
79 | IConfig xEngineConfig = configSource.AddConfig("XEngine"); | ||
80 | xEngineConfig.Set("Enabled", "true"); | ||
81 | |||
82 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
83 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
84 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
85 | |||
86 | m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource); | ||
87 | SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule); | ||
88 | |||
89 | m_scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
90 | m_scene.StartScripts(); | ||
91 | } | ||
92 | |||
93 | [TearDown] | ||
94 | public void TearDown() | ||
95 | { | ||
96 | m_scene.Close(); | ||
97 | m_scene = null; | ||
98 | GC.Collect(); | ||
99 | GC.WaitForPendingFinalizers(); | ||
100 | } | ||
101 | |||
102 | [Test] | ||
103 | public void TestCompileAndStart100Scripts() | ||
104 | { | ||
105 | TestHelpers.InMethod(); | ||
106 | log4net.Config.XmlConfigurator.Configure(); | ||
107 | |||
108 | TestCompileAndStartScripts(100); | ||
109 | } | ||
110 | |||
111 | private void TestCompileAndStartScripts(int scriptsToCreate) | ||
112 | { | ||
113 | UUID userId = TestHelpers.ParseTail(0x1); | ||
114 | |||
115 | m_expectedChatMessages = scriptsToCreate; | ||
116 | int startingObjectIdTail = 0x100; | ||
117 | |||
118 | GC.Collect(); | ||
119 | |||
120 | for (int idTail = startingObjectIdTail;idTail < startingObjectIdTail + scriptsToCreate; idTail++) | ||
121 | { | ||
122 | AddObjectAndScript(idTail, userId); | ||
123 | } | ||
124 | |||
125 | m_chatEvent.WaitOne(40000 + scriptsToCreate * 1000); | ||
126 | |||
127 | Assert.That(m_osChatMessagesReceived.Count, Is.EqualTo(m_expectedChatMessages)); | ||
128 | |||
129 | foreach (OSChatMessage msg in m_osChatMessagesReceived) | ||
130 | Assert.That( | ||
131 | msg.Message, | ||
132 | Is.EqualTo("Script running"), | ||
133 | string.Format( | ||
134 | "Message from {0} was {1} rather than {2}", msg.SenderUUID, msg.Message, "Script running")); | ||
135 | } | ||
136 | |||
137 | private void AddObjectAndScript(int objectIdTail, UUID userId) | ||
138 | { | ||
139 | // UUID itemId = TestHelpers.ParseTail(0x3); | ||
140 | string itemName = string.Format("AddObjectAndScript() Item for object {0}", objectIdTail); | ||
141 | |||
142 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "AddObjectAndScriptPart_", objectIdTail); | ||
143 | m_scene.AddNewSceneObject(so, true); | ||
144 | |||
145 | InventoryItemBase itemTemplate = new InventoryItemBase(); | ||
146 | // itemTemplate.ID = itemId; | ||
147 | itemTemplate.Name = itemName; | ||
148 | itemTemplate.Folder = so.UUID; | ||
149 | itemTemplate.InvType = (int)InventoryType.LSL; | ||
150 | |||
151 | m_scene.RezNewScript(userId, itemTemplate); | ||
152 | } | ||
153 | |||
154 | private void OnChatFromWorld(object sender, OSChatMessage oscm) | ||
155 | { | ||
156 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
157 | |||
158 | lock (m_osChatMessagesReceived) | ||
159 | { | ||
160 | m_osChatMessagesReceived.Add(oscm); | ||
161 | |||
162 | if (m_osChatMessagesReceived.Count == m_expectedChatMessages) | ||
163 | m_chatEvent.Set(); | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | } \ No newline at end of file | ||