aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-03-17 20:51:35 +0000
committerJustin Clark-Casey (justincc)2014-03-17 20:51:35 +0000
commitf3e177814a30ee91a2fdd27f2a1aebf06a39cd15 (patch)
treec511df5ec9e48d961241341e30adce3e33eb7ad7 /OpenSim/Region
parentImplement osForceBreakAllLinks(). (diff)
downloadopensim-SC_OLD-f3e177814a30ee91a2fdd27f2a1aebf06a39cd15.zip
opensim-SC_OLD-f3e177814a30ee91a2fdd27f2a1aebf06a39cd15.tar.gz
opensim-SC_OLD-f3e177814a30ee91a2fdd27f2a1aebf06a39cd15.tar.bz2
opensim-SC_OLD-f3e177814a30ee91a2fdd27f2a1aebf06a39cd15.tar.xz
Add regression test for http inventory fetch.
Involved some restructuring to allow regression tests to dequeue inventory requests and perform poll responses synchronously rather than async
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs158
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs43
-rw-r--r--OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs4
3 files changed, 198 insertions, 7 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs
new file mode 100644
index 0000000..edc5016
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/Tests/WebFetchInvDescModuleTests.cs
@@ -0,0 +1,158 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Net;
33using System.Text;
34using HttpServer;
35using log4net.Config;
36using Nini.Config;
37using NUnit.Framework;
38using OpenMetaverse;
39using OpenMetaverse.Packets;
40using OpenMetaverse.StructuredData;
41using OpenSim.Framework;
42using OpenSim.Framework.Capabilities;
43using OpenSim.Framework.Servers;
44using OpenSim.Framework.Servers.HttpServer;
45using OpenSim.Region.ClientStack.Linden;
46using OpenSim.Region.CoreModules.Framework;
47using OpenSim.Region.Framework.Scenes;
48using OpenSim.Services.Interfaces;
49using OpenSim.Tests.Common;
50using OpenSim.Tests.Common.Mock;
51using OSDArray = OpenMetaverse.StructuredData.OSDArray;
52using OSDMap = OpenMetaverse.StructuredData.OSDMap;
53
54namespace OpenSim.Region.ClientStack.Linden.Caps.Tests
55{
56 [TestFixture]
57 public class WebFetchInvDescModuleTests : OpenSimTestCase
58 {
59 [TestFixtureSetUp]
60 public void TestFixtureSetUp()
61 {
62 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
63 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
64 }
65
66 [TestFixtureTearDown]
67 public void TestFixureTearDown()
68 {
69 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
70 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
71 // tests really shouldn't).
72 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
73 }
74
75 [SetUp]
76 public override void SetUp()
77 {
78 base.SetUp();
79
80 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
81 // variables and the VM is not restarted between tests.
82 uint port = 9999;
83 MainServer.RemoveHttpServer(port);
84
85 BaseHttpServer server = new BaseHttpServer(port, false, 0, "");
86 MainServer.AddHttpServer(server);
87 MainServer.Instance = server;
88
89 server.Start(false);
90 }
91
92 [Test]
93 public void TestInventoryDescendentsFetch()
94 {
95 TestHelpers.InMethod();
96 TestHelpers.EnableLogging();
97
98 BaseHttpServer httpServer = MainServer.Instance;
99 Scene scene = new SceneHelpers().SetupScene();
100
101 CapabilitiesModule capsModule = new CapabilitiesModule();
102 WebFetchInvDescModule wfidModule = new WebFetchInvDescModule(false);
103
104 IConfigSource config = new IniConfigSource();
105 config.AddConfig("ClientStack.LindenCaps");
106 config.Configs["ClientStack.LindenCaps"].Set("Cap_FetchInventoryDescendents2", "localhost");
107
108 SceneHelpers.SetupSceneModules(scene, config, capsModule, wfidModule);
109
110 UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
111
112 // We need a user present to have any capabilities set up
113 SceneHelpers.AddScenePresence(scene, ua.PrincipalID);
114
115 TestHttpRequest req = new TestHttpRequest();
116 OpenSim.Framework.Capabilities.Caps userCaps = capsModule.GetCapsForUser(ua.PrincipalID);
117 PollServiceEventArgs pseArgs;
118 userCaps.TryGetPollHandler("FetchInventoryDescendents2", out pseArgs);
119 req.UriPath = pseArgs.Url;
120 req.Uri = new Uri(req.UriPath);
121
122 // Retrieve root folder details directly so that we can request
123 InventoryFolderBase folder = scene.InventoryService.GetRootFolder(ua.PrincipalID);
124
125 OSDMap osdFolder = new OSDMap();
126 osdFolder["folder_id"] = folder.ID;
127 osdFolder["owner_id"] = ua.PrincipalID;
128 osdFolder["fetch_folders"] = true;
129 osdFolder["fetch_items"] = true;
130 osdFolder["sort_order"] = 0;
131
132 OSDArray osdFoldersArray = new OSDArray();
133 osdFoldersArray.Add(osdFolder);
134
135 OSDMap osdReqMap = new OSDMap();
136 osdReqMap["folders"] = osdFoldersArray;
137
138 req.Body = new MemoryStream(OSDParser.SerializeLLSDXmlBytes(osdReqMap));
139
140 TestHttpClientContext context = new TestHttpClientContext(false);
141 MainServer.Instance.OnRequest(context, new RequestEventArgs(req));
142
143 // Drive processing of the queued inventory request synchronously.
144 wfidModule.WaitProcessQueuedInventoryRequest();
145 MainServer.Instance.PollServiceRequestManager.WaitPerformResponse();
146
147// System.Threading.Thread.Sleep(10000);
148
149 OSDMap responseOsd = (OSDMap)OSDParser.DeserializeLLSDXml(context.ResponseBody);
150 OSDArray foldersOsd = (OSDArray)responseOsd["folders"];
151 OSDMap folderOsd = (OSDMap)foldersOsd[0];
152
153 // A sanity check that the response has the expected number of descendents for a default inventory
154 // TODO: Need a more thorough check.
155 Assert.That((int)folderOsd["descendents"], Is.EqualTo(14));
156 }
157 }
158} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
index 340d2e7..f0dccda 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
@@ -65,6 +65,15 @@ namespace OpenSim.Region.ClientStack.Linden
65 65
66 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 66 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
67 67
68
69 /// <summary>
70 /// Control whether requests will be processed asynchronously.
71 /// </summary>
72 /// <remarks>
73 /// Defaults to true. Can currently not be changed once a region has been added to the module.
74 /// </remarks>
75 public bool ProcessQueuedRequestsAsync { get; private set; }
76
68 private Scene m_scene; 77 private Scene m_scene;
69 78
70 private IInventoryService m_InventoryService; 79 private IInventoryService m_InventoryService;
@@ -84,6 +93,13 @@ namespace OpenSim.Region.ClientStack.Linden
84 93
85 #region ISharedRegionModule Members 94 #region ISharedRegionModule Members
86 95
96 public WebFetchInvDescModule() : this(true) {}
97
98 public WebFetchInvDescModule(bool processQueuedResultsAsync)
99 {
100 ProcessQueuedRequestsAsync = processQueuedResultsAsync;
101 }
102
87 public void Initialise(IConfigSource source) 103 public void Initialise(IConfigSource source)
88 { 104 {
89 IConfig config = source.Configs["ClientStack.LindenCaps"]; 105 IConfig config = source.Configs["ClientStack.LindenCaps"];
@@ -114,8 +130,16 @@ namespace OpenSim.Region.ClientStack.Linden
114 130
115 m_scene.EventManager.OnRegisterCaps -= RegisterCaps; 131 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
116 132
117 foreach (Thread t in m_workerThreads) 133 if (ProcessQueuedRequestsAsync)
118 Watchdog.AbortThread(t.ManagedThreadId); 134 {
135 if (m_workerThreads != null)
136 {
137 foreach (Thread t in m_workerThreads)
138 Watchdog.AbortThread(t.ManagedThreadId);
139
140 m_workerThreads = null;
141 }
142 }
119 143
120 m_scene = null; 144 m_scene = null;
121 } 145 }
@@ -133,7 +157,7 @@ namespace OpenSim.Region.ClientStack.Linden
133 157
134 m_scene.EventManager.OnRegisterCaps += RegisterCaps; 158 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
135 159
136 if (m_workerThreads == null) 160 if (ProcessQueuedRequestsAsync && m_workerThreads == null)
137 { 161 {
138 m_workerThreads = new Thread[2]; 162 m_workerThreads = new Thread[2];
139 163
@@ -358,11 +382,16 @@ namespace OpenSim.Region.ClientStack.Linden
358 { 382 {
359 Watchdog.UpdateThread(); 383 Watchdog.UpdateThread();
360 384
361 aPollRequest poolreq = m_queue.Dequeue(); 385 WaitProcessQueuedInventoryRequest();
362
363 if (poolreq != null && poolreq.thepoll != null)
364 poolreq.thepoll.Process(poolreq);
365 } 386 }
366 } 387 }
388
389 public void WaitProcessQueuedInventoryRequest()
390 {
391 aPollRequest poolreq = m_queue.Dequeue();
392
393 if (poolreq != null && poolreq.thepoll != null)
394 poolreq.thepoll.Process(poolreq);
395 }
367 } 396 }
368} 397}
diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
index 13cc99a..817ef85 100644
--- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -137,6 +137,10 @@ namespace OpenSim.Region.CoreModules.Framework
137 // agentId, m_scene.RegionInfo.RegionName, oldCaps.CapsObjectPath, capsObjectPath); 137 // agentId, m_scene.RegionInfo.RegionName, oldCaps.CapsObjectPath, capsObjectPath);
138 } 138 }
139 139
140// m_log.DebugFormat(
141// "[CAPS]: Adding capabilities for agent {0} in {1} with path {2}",
142// agentId, m_scene.RegionInfo.RegionName, capsObjectPath);
143
140 caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName, 144 caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
141 (MainServer.Instance == null) ? 0: MainServer.Instance.Port, 145 (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
142 capsObjectPath, agentId, m_scene.RegionInfo.RegionName); 146 capsObjectPath, agentId, m_scene.RegionInfo.RegionName);