aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-12-10 00:25:27 +0000
committerJustin Clark-Casey (justincc)2014-12-10 00:25:27 +0000
commit2b9f0647de513f6a916d9d58d4e7883d30b804d3 (patch)
tree6a41a0a0c88eb6b6c1ce1d19d64de3837b89c293 /OpenSim/Region/ScriptEngine/XEngine
parentAvoid a possible race condition where the XEngine script compile thread could... (diff)
downloadopensim-SC_OLD-2b9f0647de513f6a916d9d58d4e7883d30b804d3.zip
opensim-SC_OLD-2b9f0647de513f6a916d9d58d4e7883d30b804d3.tar.gz
opensim-SC_OLD-2b9f0647de513f6a916d9d58d4e7883d30b804d3.tar.bz2
opensim-SC_OLD-2b9f0647de513f6a916d9d58d4e7883d30b804d3.tar.xz
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
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineCrossingTests.cs195
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs51
3 files changed, 220 insertions, 30 deletions
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;
40namespace OpenSim.Region.ScriptEngine.XEngine.Tests 40namespace OpenSim.Region.ScriptEngine.XEngine.Tests
41{ 41{
42 /// <summary> 42 /// <summary>
43 /// XEngine tests. 43 /// Basic XEngine tests.
44 /// </summary> 44 /// </summary>
45 [TestFixture] 45 [TestFixture]
46 public class XEngineTest : OpenSimTestCase 46 public class XEngineBasicTests : OpenSimTestCase
47 { 47 {
48 private TestScene m_scene; 48 private TestScene m_scene;
49 private XEngine m_xEngine; 49 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 @@
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.Threading;
30using Nini.Config;
31using NUnit.Framework;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.CoreModules.Framework.EntityTransfer;
35using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Tests.Common;
39
40namespace OpenSim.Region.ScriptEngine.XEngine.Tests
41{
42 /// <summary>
43 /// XEngine tests connected with crossing scripts between regions.
44 /// </summary>
45 [TestFixture]
46 public class XEngineCrossingTests : OpenSimTestCase
47 {
48 [TestFixtureSetUp]
49 public void FixtureInit()
50 {
51 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
52 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
53 }
54
55 [TestFixtureTearDown]
56 public void TearDown()
57 {
58 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
59 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
60 // tests really shouldn't).
61 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
62 }
63
64 /// <summary>
65 /// Test script state preservation when a script crosses between regions on the same simulator.
66 /// </summary>
67 [Test]
68 public void TestScriptCrossOnSameSimulator()
69 {
70 TestHelpers.InMethod();
71// TestHelpers.EnableLogging();
72
73 UUID userId = TestHelpers.ParseTail(0x1);
74 int sceneObjectIdTail = 0x2;
75
76 EntityTransferModule etmA = new EntityTransferModule();
77 EntityTransferModule etmB = new EntityTransferModule();
78 LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
79 XEngine xEngineA = new XEngine();
80 XEngine xEngineB = new XEngine();
81 xEngineA.DebugLevel = 1;
82 xEngineB.DebugLevel = 1;
83
84 IConfigSource configSource = new IniConfigSource();
85
86 IConfig startupConfig = configSource.AddConfig("Startup");
87 startupConfig.Set("DefaultScriptEngine", "XEngine");
88
89 IConfig xEngineConfig = configSource.AddConfig("XEngine");
90 xEngineConfig.Set("Enabled", "true");
91 xEngineConfig.Set("StartDelay", "0");
92
93 // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
94 // to AssemblyResolver.OnAssemblyResolve fails.
95 xEngineConfig.Set("AppDomainLoading", "false");
96
97 IConfig modulesConfig = configSource.AddConfig("Modules");
98 modulesConfig.Set("EntityTransferModule", etmA.Name);
99 modulesConfig.Set("SimulationServices", lscm.Name);
100
101 SceneHelpers sh = new SceneHelpers();
102 TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
103 TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);
104
105 SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
106 SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
107 SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
108 sceneA.StartScripts();
109 sceneB.StartScripts();
110
111 SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
112 soSceneA.AbsolutePosition = new Vector3(128, 10, 20);
113
114 // CREATE SCRIPT TODO
115 InventoryItemBase scriptItemSceneA = new InventoryItemBase();
116 // itemTemplate.ID = itemId;
117 scriptItemSceneA.Name = "script1";
118 scriptItemSceneA.Folder = soSceneA.UUID;
119 scriptItemSceneA.InvType = (int)InventoryType.LSL;
120
121 AutoResetEvent chatEvent = new AutoResetEvent(false);
122 OSChatMessage messageReceived = null;
123 sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
124
125 sceneA.RezNewScript(userId, scriptItemSceneA,
126@"integer c = 0;
127
128default
129{
130 state_entry()
131 {
132 llSay(0, ""Script running"");
133 }
134
135 changed(integer change)
136 {
137 llSay(0, ""Changed"");
138 }
139
140 touch_start(integer n)
141 {
142 c = c + 1;
143 llSay(0, (string)c);
144 }
145}");
146
147 chatEvent.WaitOne(60000);
148
149 Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
150 Assert.That(messageReceived.Message, Is.EqualTo("Script running"));
151
152 {
153 // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
154 DetectParams[] det = new DetectParams[1];
155 det[0] = new DetectParams();
156 det[0].Key = userId;
157 det[0].Populate(sceneA);
158
159 EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
160
161 xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
162 chatEvent.WaitOne(60000);
163
164 Assert.That(messageReceived.Message, Is.EqualTo("1"));
165 }
166
167 sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
168
169 // Cross with a negative value
170 soSceneA.AbsolutePosition = new Vector3(128, -10, 20);
171
172 chatEvent.WaitOne(60000);
173 Assert.That(messageReceived.Message, Is.EqualTo("Changed"));
174
175 // TEST sending event to moved prim and output
176 {
177 SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneA.Name);
178 TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneA.Name);
179
180 // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
181 DetectParams[] det = new DetectParams[1];
182 det[0] = new DetectParams();
183 det[0].Key = userId;
184 det[0].Populate(sceneB);
185
186 EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
187
188 xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
189 chatEvent.WaitOne(60000);
190
191 Assert.That(messageReceived.Message, Is.EqualTo("2"));
192 }
193 }
194 }
195} \ 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
716 { 716 {
717 // Force a final state save 717 // Force a final state save
718 // 718 //
719 if (m_Assemblies.ContainsKey(instance.AssetID)) 719 try
720 { 720 {
721 string assembly = m_Assemblies[instance.AssetID]; 721 instance.SaveState();
722 722 }
723 try 723 catch (Exception e)
724 { 724 {
725 instance.SaveState(assembly); 725 m_log.Error(
726 } 726 string.Format(
727 catch (Exception e) 727 "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
728 { 728 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
729 m_log.Error( 729 , e);
730 string.Format(
731 "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
732 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
733 , e);
734 }
735 } 730 }
736 731
737 // Clear the event queue and abort the instance thread 732 // Clear the event queue and abort the instance thread
@@ -840,18 +835,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
840 835
841 foreach (IScriptInstance i in instances) 836 foreach (IScriptInstance i in instances)
842 { 837 {
843 string assembly = String.Empty;
844
845 lock (m_Scripts)
846 {
847 if (!m_Assemblies.ContainsKey(i.AssetID))
848 continue;
849 assembly = m_Assemblies[i.AssetID];
850 }
851
852 try 838 try
853 { 839 {
854 i.SaveState(assembly); 840 i.SaveState();
855 } 841 }
856 catch (Exception e) 842 catch (Exception e)
857 { 843 {
@@ -1180,7 +1166,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1180 lock (m_AddingAssemblies) 1166 lock (m_AddingAssemblies)
1181 { 1167 {
1182 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assemblyPath, out linemap); 1168 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assemblyPath, out linemap);
1183 1169
1170// m_log.DebugFormat(
1171// "[XENGINE]: Found assembly path {0} onrez {1} in {2}",
1172// assemblyPath, item.ItemID, World.Name);
1173
1184 if (!m_AddingAssemblies.ContainsKey(assemblyPath)) { 1174 if (!m_AddingAssemblies.ContainsKey(assemblyPath)) {
1185 m_AddingAssemblies[assemblyPath] = 1; 1175 m_AddingAssemblies[assemblyPath] = 1;
1186 } else { 1176 } else {
@@ -1373,7 +1363,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1373 startParam, postOnRez, 1363 startParam, postOnRez,
1374 m_MaxScriptQueue); 1364 m_MaxScriptQueue);
1375 1365
1376 if (!instance.Load(m_AppDomains[appDomain], scriptAssembly, stateSource)) 1366 if (!instance.Load(
1367 m_AppDomains[appDomain], scriptAssembly,
1368 Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource))
1377 return false; 1369 return false;
1378 1370
1379// if (DebugLevel >= 1) 1371// if (DebugLevel >= 1)
@@ -1604,7 +1596,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1604 1596
1605 IScriptInstance instance = (ScriptInstance) parms; 1597 IScriptInstance instance = (ScriptInstance) parms;
1606 1598
1607 //m_log.DebugFormat("[XEngine]: Processing event for {0}", instance); 1599// m_log.DebugFormat("[XEngine]: Processing event for {0}", instance);
1608 1600
1609 return instance.EventProcessor(); 1601 return instance.EventProcessor();
1610 } 1602 }
@@ -2200,6 +2192,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2200 m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message); 2192 m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message);
2201 } 2193 }
2202 2194
2195// m_log.DebugFormat(
2196// "[XEngine]: Wrote state for script item with ID {0} at {1} in {2}", itemID, statepath, m_Scene.Name);
2197
2203 return true; 2198 return true;
2204 } 2199 }
2205 2200