From e10012a7a6a047287c193c4beb1afdcd62922e3e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 12 Feb 2014 23:16:42 +0000 Subject: [PATCH] If a caller tries to queue a CAPs message to a scene presence that has no event queue (e.g. an NPC), only warn if event queue debugging is greater than zero. Removes the spurious log warnings if groups are active when NPCs are used. Adds more regression tests associated with adding messages to the event queue --- .../Caps/EventQueue/EventQueueGetModule.cs | 16 ++-- .../Caps/EventQueue/Tests/EventQueueTests.cs | 90 ++++++++++++++++++- prebuild.xml | 2 + 3 files changed, 101 insertions(+), 7 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index 0dbdbaf456..0447bc4769 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -228,12 +228,18 @@ namespace OpenSim.Region.ClientStack.Linden lock (queue) queue.Enqueue(ev); } - else + else if (DebugLevel > 0) { - OSDMap evMap = (OSDMap)ev; - m_log.WarnFormat( - "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} when placing message {1} in region {2}", - avatarID, evMap["message"], m_scene.Name); + ScenePresence sp = m_scene.GetScenePresence(avatarID); + + // This assumes that an NPC should never have a queue. + if (sp != null && sp.PresenceType != PresenceType.Npc) + { + OSDMap evMap = (OSDMap)ev; + m_log.WarnFormat( + "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} {1} when placing message {2} in region {3}", + sp.Name, sp.UUID, evMap["message"], m_scene.Name); + } } } catch (NullReferenceException e) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs index 9e24bcef15..fb24f586e2 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/Tests/EventQueueTests.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Net; using log4net.Config; @@ -33,11 +34,14 @@ using Nini.Config; using NUnit.Framework; using OpenMetaverse; using OpenMetaverse.Packets; +using OpenMetaverse.StructuredData; using OpenSim.Framework; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Region.ClientStack.Linden; using OpenSim.Region.CoreModules.Framework; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.OptionalModules.World.NPC; using OpenSim.Tests.Common; using OpenSim.Tests.Common.Mock; @@ -47,6 +51,8 @@ namespace OpenSim.Region.ClientStack.Linden.Tests public class EventQueueTests : OpenSimTestCase { private TestScene m_scene; + private EventQueueGetModule m_eqgMod; + private NPCModule m_npcMod; [SetUp] public override void SetUp() @@ -69,10 +75,15 @@ namespace OpenSim.Region.ClientStack.Linden.Tests config.Configs["Startup"].Set("EventQueue", "true"); CapabilitiesModule capsModule = new CapabilitiesModule(); - EventQueueGetModule eqgModule = new EventQueueGetModule(); + m_eqgMod = new EventQueueGetModule(); + + // For NPC test support + config.AddConfig("NPC"); + config.Configs["NPC"].Set("Enabled", "true"); + m_npcMod = new NPCModule(); m_scene = new SceneHelpers().SetupScene(); - SceneHelpers.SetupSceneModules(m_scene, config, capsModule, eqgModule); + SceneHelpers.SetupSceneModules(m_scene, config, capsModule, m_eqgMod, m_npcMod); } [Test] @@ -101,5 +112,80 @@ namespace OpenSim.Region.ClientStack.Linden.Tests // TODO: Add more assertions for the other aspects of event queues Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0)); } + + [Test] + public void TestEnqueueMessage() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + string messageName = "TestMessage"; + + m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), sp.UUID); + + Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID); + + Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK)); + +// Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]); + + OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]); + OSDArray eventsOsd = (OSDArray)rawOsd["events"]; + + bool foundUpdate = false; + foreach (OSD osd in eventsOsd) + { + OSDMap eventOsd = (OSDMap)osd; + + if (eventOsd["message"] == messageName) + foundUpdate = true; + } + + Assert.That(foundUpdate, Is.True, string.Format("Did not find {0} in response", messageName)); + } + + /// + /// Test an attempt to put a message on the queue of a user that is not in the region. + /// + [Test] + public void TestEnqueueMessageNoUser() + { + TestHelpers.InMethod(); + TestHelpers.EnableLogging(); + + string messageName = "TestMessage"; + + m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), TestHelpers.ParseTail(0x1)); + + Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, TestHelpers.ParseTail(0x1)); + + Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); + } + + /// + /// NPCs do not currently have an event queue but a caller may try to send a message anyway, so check behaviour. + /// + [Test] + public void TestEnqueueMessageToNpc() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + UUID npcId + = m_npcMod.CreateNPC( + "John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, new AvatarAppearance()); + + ScenePresence npc = m_scene.GetScenePresence(npcId); + + string messageName = "TestMessage"; + + m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), npc.UUID); + + Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, npc.UUID); + + Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway)); + } } } \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index 5b18195f60..dfb30dc813 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -3325,6 +3325,7 @@ + @@ -3334,6 +3335,7 @@ +