From 2b9f0647de513f6a916d9d58d4e7883d30b804d3 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 10 Dec 2014 00:25:27 +0000
Subject: Fix a regression where objects crossing regions in the same simulator
(on their own or as attachments) with AppDomainLoading = false would create
the new state in the source region area rather than the dest.
This was beause the code was finding the script DLL compiled for the source region as everything is in the same appdomain and using this as the location for the destination script state, etc.
This resolves the regression by passing the proper destination separately from the DLL retrieved.
Probably a regression since commit d7b92604 (11 July 2014).
Added regression test for this case.
At least partly addresses http://opensimulator.org/mantis/view.php?id=7278
---
.../XEngine/Tests/XEngineBasicTests.cs | 4 +-
.../XEngine/Tests/XEngineCrossingTests.cs | 195 +++++++++++++++++++++
OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 51 +++---
3 files changed, 220 insertions(+), 30 deletions(-)
create mode 100644 OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs
(limited to 'OpenSim/Region/ScriptEngine/XEngine')
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs
index fe15157..878e571 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs
@@ -40,10 +40,10 @@ using OpenSim.Tests.Common;
namespace OpenSim.Region.ScriptEngine.XEngine.Tests
{
///
- /// XEngine tests.
+ /// Basic XEngine tests.
///
[TestFixture]
- public class XEngineTest : OpenSimTestCase
+ public class XEngineBasicTests : OpenSimTestCase
{
private TestScene m_scene;
private XEngine m_xEngine;
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs
new file mode 100644
index 0000000..587695f
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs
@@ -0,0 +1,195 @@
+/*
+ * 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 System.Threading;
+using Nini.Config;
+using NUnit.Framework;
+using OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.CoreModules.Framework.EntityTransfer;
+using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
+using OpenSim.Region.Framework.Scenes;
+using OpenSim.Region.ScriptEngine.Shared;
+using OpenSim.Tests.Common;
+
+namespace OpenSim.Region.ScriptEngine.XEngine.Tests
+{
+ ///
+ /// XEngine tests connected with crossing scripts between regions.
+ ///
+ [TestFixture]
+ public class XEngineCrossingTests : OpenSimTestCase
+ {
+ [TestFixtureSetUp]
+ public void FixtureInit()
+ {
+ // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
+ Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
+ }
+
+ [TestFixtureTearDown]
+ public void TearDown()
+ {
+ // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
+ // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
+ // tests really shouldn't).
+ Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
+ }
+
+ ///
+ /// Test script state preservation when a script crosses between regions on the same simulator.
+ ///
+ [Test]
+ public void TestScriptCrossOnSameSimulator()
+ {
+ TestHelpers.InMethod();
+// TestHelpers.EnableLogging();
+
+ UUID userId = TestHelpers.ParseTail(0x1);
+ int sceneObjectIdTail = 0x2;
+
+ EntityTransferModule etmA = new EntityTransferModule();
+ EntityTransferModule etmB = new EntityTransferModule();
+ LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
+ XEngine xEngineA = new XEngine();
+ XEngine xEngineB = new XEngine();
+ xEngineA.DebugLevel = 1;
+ xEngineB.DebugLevel = 1;
+
+ IConfigSource configSource = new IniConfigSource();
+
+ IConfig startupConfig = configSource.AddConfig("Startup");
+ startupConfig.Set("DefaultScriptEngine", "XEngine");
+
+ IConfig xEngineConfig = configSource.AddConfig("XEngine");
+ xEngineConfig.Set("Enabled", "true");
+ xEngineConfig.Set("StartDelay", "0");
+
+ // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
+ // to AssemblyResolver.OnAssemblyResolve fails.
+ xEngineConfig.Set("AppDomainLoading", "false");
+
+ IConfig modulesConfig = configSource.AddConfig("Modules");
+ modulesConfig.Set("EntityTransferModule", etmA.Name);
+ modulesConfig.Set("SimulationServices", lscm.Name);
+
+ SceneHelpers sh = new SceneHelpers();
+ TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
+ TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);
+
+ SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
+ SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
+ SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
+ sceneA.StartScripts();
+ sceneB.StartScripts();
+
+ SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
+ soSceneA.AbsolutePosition = new Vector3(128, 10, 20);
+
+ // CREATE SCRIPT TODO
+ InventoryItemBase scriptItemSceneA = new InventoryItemBase();
+ // itemTemplate.ID = itemId;
+ scriptItemSceneA.Name = "script1";
+ scriptItemSceneA.Folder = soSceneA.UUID;
+ scriptItemSceneA.InvType = (int)InventoryType.LSL;
+
+ AutoResetEvent chatEvent = new AutoResetEvent(false);
+ OSChatMessage messageReceived = null;
+ sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
+
+ sceneA.RezNewScript(userId, scriptItemSceneA,
+@"integer c = 0;
+
+default
+{
+ state_entry()
+ {
+ llSay(0, ""Script running"");
+ }
+
+ changed(integer change)
+ {
+ llSay(0, ""Changed"");
+ }
+
+ touch_start(integer n)
+ {
+ c = c + 1;
+ llSay(0, (string)c);
+ }
+}");
+
+ chatEvent.WaitOne(60000);
+
+ Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
+ Assert.That(messageReceived.Message, Is.EqualTo("Script running"));
+
+ {
+ // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
+ DetectParams[] det = new DetectParams[1];
+ det[0] = new DetectParams();
+ det[0].Key = userId;
+ det[0].Populate(sceneA);
+
+ EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
+
+ xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
+ chatEvent.WaitOne(60000);
+
+ Assert.That(messageReceived.Message, Is.EqualTo("1"));
+ }
+
+ sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
+
+ // Cross with a negative value
+ soSceneA.AbsolutePosition = new Vector3(128, -10, 20);
+
+ chatEvent.WaitOne(60000);
+ Assert.That(messageReceived.Message, Is.EqualTo("Changed"));
+
+ // TEST sending event to moved prim and output
+ {
+ SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneA.Name);
+ TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneA.Name);
+
+ // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
+ DetectParams[] det = new DetectParams[1];
+ det[0] = new DetectParams();
+ det[0].Key = userId;
+ det[0].Populate(sceneB);
+
+ EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
+
+ xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
+ chatEvent.WaitOne(60000);
+
+ Assert.That(messageReceived.Message, Is.EqualTo("2"));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index ccd5d99..71ed989 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -716,22 +716,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
{
// Force a final state save
//
- if (m_Assemblies.ContainsKey(instance.AssetID))
+ try
{
- string assembly = m_Assemblies[instance.AssetID];
-
- try
- {
- instance.SaveState(assembly);
- }
- catch (Exception e)
- {
- m_log.Error(
- string.Format(
- "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
- instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
- , e);
- }
+ instance.SaveState();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(
+ string.Format(
+ "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
+ instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
+ , e);
}
// Clear the event queue and abort the instance thread
@@ -840,18 +835,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
foreach (IScriptInstance i in instances)
{
- string assembly = String.Empty;
-
- lock (m_Scripts)
- {
- if (!m_Assemblies.ContainsKey(i.AssetID))
- continue;
- assembly = m_Assemblies[i.AssetID];
- }
-
try
{
- i.SaveState(assembly);
+ i.SaveState();
}
catch (Exception e)
{
@@ -1180,7 +1166,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
lock (m_AddingAssemblies)
{
m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assemblyPath, out linemap);
-
+
+// m_log.DebugFormat(
+// "[XENGINE]: Found assembly path {0} onrez {1} in {2}",
+// assemblyPath, item.ItemID, World.Name);
+
if (!m_AddingAssemblies.ContainsKey(assemblyPath)) {
m_AddingAssemblies[assemblyPath] = 1;
} else {
@@ -1373,7 +1363,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
startParam, postOnRez,
m_MaxScriptQueue);
- if (!instance.Load(m_AppDomains[appDomain], scriptAssembly, stateSource))
+ if (!instance.Load(
+ m_AppDomains[appDomain], scriptAssembly,
+ Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource))
return false;
// if (DebugLevel >= 1)
@@ -1604,7 +1596,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
IScriptInstance instance = (ScriptInstance) parms;
- //m_log.DebugFormat("[XEngine]: Processing event for {0}", instance);
+// m_log.DebugFormat("[XEngine]: Processing event for {0}", instance);
return instance.EventProcessor();
}
@@ -2200,6 +2192,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message);
}
+// m_log.DebugFormat(
+// "[XEngine]: Wrote state for script item with ID {0} at {1} in {2}", itemID, statepath, m_Scene.Name);
+
return true;
}
--
cgit v1.1