diff options
author | Justin Clark-Casey (justincc) | 2012-02-09 00:38:09 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-02-09 00:38:09 +0000 |
commit | 16c46360486cddb3968d12857e0f84c7cb9ede55 (patch) | |
tree | 344960d92f4cec7bd6f7114e390a5cefb4596818 | |
parent | minor: put in commented out logging statements for future reuse (diff) | |
download | opensim-SC-16c46360486cddb3968d12857e0f84c7cb9ede55.zip opensim-SC-16c46360486cddb3968d12857e0f84c7cb9ede55.tar.gz opensim-SC-16c46360486cddb3968d12857e0f84c7cb9ede55.tar.bz2 opensim-SC-16c46360486cddb3968d12857e0f84c7cb9ede55.tar.xz |
Add NPC torture tests for 100, 1000 and 2000 create and delete NPC calls.
-rw-r--r-- | OpenSim/Tests/Torture/NPCTortureTests.cs | 185 | ||||
-rw-r--r-- | prebuild.xml | 3 |
2 files changed, 188 insertions, 0 deletions
diff --git a/OpenSim/Tests/Torture/NPCTortureTests.cs b/OpenSim/Tests/Torture/NPCTortureTests.cs new file mode 100644 index 0000000..8078d9d --- /dev/null +++ b/OpenSim/Tests/Torture/NPCTortureTests.cs | |||
@@ -0,0 +1,185 @@ | |||
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 | using OpenSim.Tests.Common.Mock; | ||
49 | |||
50 | namespace OpenSim.Tests.Torture | ||
51 | { | ||
52 | /// <summary> | ||
53 | /// NPC torture tests | ||
54 | /// </summary> | ||
55 | /// <remarks> | ||
56 | /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached, | ||
57 | /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller | ||
58 | /// earlier tests. | ||
59 | /// </remarks> | ||
60 | [TestFixture] | ||
61 | public class NPCTortureTests | ||
62 | { | ||
63 | private TestScene scene; | ||
64 | private AvatarFactoryModule afm; | ||
65 | private UserManagementModule umm; | ||
66 | private AttachmentsModule am; | ||
67 | |||
68 | [TestFixtureSetUp] | ||
69 | public void FixtureInit() | ||
70 | { | ||
71 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
72 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
73 | } | ||
74 | |||
75 | [TestFixtureTearDown] | ||
76 | public void TearDown() | ||
77 | { | ||
78 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
79 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
80 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
81 | } | ||
82 | |||
83 | [SetUp] | ||
84 | public void Init() | ||
85 | { | ||
86 | IConfigSource config = new IniConfigSource(); | ||
87 | config.AddConfig("NPC"); | ||
88 | config.Configs["NPC"].Set("Enabled", "true"); | ||
89 | config.AddConfig("Modules"); | ||
90 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
91 | |||
92 | afm = new AvatarFactoryModule(); | ||
93 | umm = new UserManagementModule(); | ||
94 | am = new AttachmentsModule(); | ||
95 | |||
96 | scene = SceneHelpers.SetupScene(); | ||
97 | SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule()); | ||
98 | } | ||
99 | |||
100 | [Test] | ||
101 | public void TestAddRemove100NPCs() | ||
102 | { | ||
103 | TestHelpers.InMethod(); | ||
104 | // log4net.Config.XmlConfigurator.Configure(); | ||
105 | |||
106 | TestAddRemoveNPCs(100); | ||
107 | } | ||
108 | |||
109 | [Test] | ||
110 | public void TestAddRemove1000NPCs() | ||
111 | { | ||
112 | TestHelpers.InMethod(); | ||
113 | // log4net.Config.XmlConfigurator.Configure(); | ||
114 | |||
115 | TestAddRemoveNPCs(1000); | ||
116 | } | ||
117 | |||
118 | [Test] | ||
119 | public void TestAddRemove2000NPCs() | ||
120 | { | ||
121 | TestHelpers.InMethod(); | ||
122 | // log4net.Config.XmlConfigurator.Configure(); | ||
123 | |||
124 | TestAddRemoveNPCs(2000); | ||
125 | } | ||
126 | |||
127 | private void TestAddRemoveNPCs(int numberOfNpcs) | ||
128 | { | ||
129 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); | ||
130 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | ||
131 | |||
132 | // 8 is the index of the first baked texture in AvatarAppearance | ||
133 | UUID originalFace8TextureId = TestHelpers.ParseTail(0x10); | ||
134 | Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero); | ||
135 | Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8); | ||
136 | originalTef.TextureID = originalFace8TextureId; | ||
137 | |||
138 | // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell | ||
139 | // ScenePresence.SendInitialData() to reset our entire appearance. | ||
140 | scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); | ||
141 | |||
142 | afm.SetAppearance(sp, originalTe, null); | ||
143 | |||
144 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | ||
145 | |||
146 | List<UUID> npcs = new List<UUID>(); | ||
147 | |||
148 | long startGcMemory = GC.GetTotalMemory(true); | ||
149 | Stopwatch sw = new Stopwatch(); | ||
150 | sw.Start(); | ||
151 | |||
152 | for (int i = 0; i < numberOfNpcs; i++) | ||
153 | { | ||
154 | npcs.Add( | ||
155 | npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance)); | ||
156 | } | ||
157 | |||
158 | for (int i = 0; i < numberOfNpcs; i++) | ||
159 | { | ||
160 | Assert.That(npcs[i], Is.Not.Null); | ||
161 | |||
162 | ScenePresence npc = scene.GetScenePresence(npcs[i]); | ||
163 | Assert.That(npc, Is.Not.Null); | ||
164 | } | ||
165 | |||
166 | for (int i = 0; i < numberOfNpcs; i++) | ||
167 | { | ||
168 | Assert.That(npcModule.DeleteNPC(npcs[i], scene), Is.True); | ||
169 | ScenePresence npc = scene.GetScenePresence(npcs[i]); | ||
170 | Assert.That(npc, Is.Null); | ||
171 | } | ||
172 | |||
173 | sw.Stop(); | ||
174 | |||
175 | long endGcMemory = GC.GetTotalMemory(true); | ||
176 | |||
177 | Console.WriteLine("Took {0} ms", sw.ElapsedMilliseconds); | ||
178 | Console.WriteLine( | ||
179 | "End {0} MB, Start {1} MB, Diff {2} MB", | ||
180 | endGcMemory / 1024 / 1024, | ||
181 | startGcMemory / 1024 / 1024, | ||
182 | (endGcMemory - startGcMemory) / 1024 / 1024); | ||
183 | } | ||
184 | } | ||
185 | } \ No newline at end of file | ||
diff --git a/prebuild.xml b/prebuild.xml index 1bf4972..c64f1cc 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -3284,12 +3284,15 @@ | |||
3284 | <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/> | 3284 | <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/> |
3285 | <Reference name="XMLRPC" path="../../../bin/"/> | 3285 | <Reference name="XMLRPC" path="../../../bin/"/> |
3286 | <Reference name="OpenSim.Framework"/> | 3286 | <Reference name="OpenSim.Framework"/> |
3287 | <Reference name="OpenSim.Framework.Communications"/> | ||
3287 | <Reference name="OpenSim.Framework.Console"/> | 3288 | <Reference name="OpenSim.Framework.Console"/> |
3288 | <Reference name="OpenSim.Framework.Servers.HttpServer"/> | 3289 | <Reference name="OpenSim.Framework.Servers.HttpServer"/> |
3289 | <Reference name="OpenSim.Region.CoreModules"/> | 3290 | <Reference name="OpenSim.Region.CoreModules"/> |
3290 | <Reference name="OpenSim.Region.Framework"/> | 3291 | <Reference name="OpenSim.Region.Framework"/> |
3292 | <Reference name="OpenSim.Region.OptionalModules"/> | ||
3291 | <Reference name="OpenSim.Region.ScriptEngine.Shared"/> | 3293 | <Reference name="OpenSim.Region.ScriptEngine.Shared"/> |
3292 | <Reference name="OpenSim.Region.ScriptEngine.XEngine"/> | 3294 | <Reference name="OpenSim.Region.ScriptEngine.XEngine"/> |
3295 | <Reference name="OpenSim.Services.AvatarService"/> | ||
3293 | <Reference name="OpenSim.Tests.Common"/> | 3296 | <Reference name="OpenSim.Tests.Common"/> |
3294 | <Files> | 3297 | <Files> |
3295 | <Match pattern="*.cs" recurse="false"/> | 3298 | <Match pattern="*.cs" recurse="false"/> |