diff options
author | Justin Clark-Casey (justincc) | 2015-01-16 22:44:54 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2015-01-16 22:46:48 +0000 |
commit | 8d724e90de0fb3b406f82f4e06b6f5b79c5a538c (patch) | |
tree | 069eac2d8fa46b63267d4119795a6cabf218c97f /OpenSim/Region/ScriptEngine/XEngine | |
parent | minor: Suppress the log messages when user profiles data is requested for an ... (diff) | |
download | opensim-SC_OLD-8d724e90de0fb3b406f82f4e06b6f5b79c5a538c.zip opensim-SC_OLD-8d724e90de0fb3b406f82f4e06b6f5b79c5a538c.tar.gz opensim-SC_OLD-8d724e90de0fb3b406f82f4e06b6f5b79c5a538c.tar.bz2 opensim-SC_OLD-8d724e90de0fb3b406f82f4e06b6f5b79c5a538c.tar.xz |
For scripts in attachments, don't save .state files apart from the initial one as these are ignored since .state is saved in the attachment's asset.
This eliminates pointless work and exceptions when an appdomain is unloaded whilst an attachment script state is persisted.
Adds test for this case.
Relates to http://opensimulator.org/mantis/view.php?id=7407
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs | 152 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 18 |
2 files changed, 167 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs new file mode 100644 index 0000000..5b7e5f7 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEnginePersistenceTests.cs | |||
@@ -0,0 +1,152 @@ | |||
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.IO; | ||
31 | using System.Linq; | ||
32 | using System.Threading; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
38 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.ScriptEngine.XEngine; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Region.ScriptEngine.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class XEnginePersistenceTests : OpenSimTestCase | ||
48 | { | ||
49 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
50 | |||
51 | private void OnChatFromWorld(object sender, OSChatMessage oscm) | ||
52 | { | ||
53 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
54 | |||
55 | // m_osChatMessageReceived = oscm; | ||
56 | m_chatEvent.Set(); | ||
57 | } | ||
58 | |||
59 | private void AddCommonConfig(IConfigSource config, List<object> modules) | ||
60 | { | ||
61 | config.AddConfig("Modules"); | ||
62 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
63 | |||
64 | AttachmentsModule attMod = new AttachmentsModule(); | ||
65 | attMod.DebugLevel = 1; | ||
66 | modules.Add(attMod); | ||
67 | modules.Add(new BasicInventoryAccessModule()); | ||
68 | } | ||
69 | |||
70 | private void AddScriptingConfig(IConfigSource config, XEngine.XEngine xEngine, List<object> modules) | ||
71 | { | ||
72 | IConfig startupConfig = config.AddConfig("Startup"); | ||
73 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
74 | |||
75 | IConfig xEngineConfig = config.AddConfig("XEngine"); | ||
76 | xEngineConfig.Set("Enabled", "true"); | ||
77 | xEngineConfig.Set("StartDelay", "0"); | ||
78 | |||
79 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
80 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
81 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
82 | |||
83 | modules.Add(xEngine); | ||
84 | } | ||
85 | |||
86 | private Scene CreateScriptingEnabledTestScene(XEngine.XEngine xEngine) | ||
87 | { | ||
88 | IConfigSource config = new IniConfigSource(); | ||
89 | List<object> modules = new List<object>(); | ||
90 | |||
91 | AddCommonConfig(config, modules); | ||
92 | AddScriptingConfig(config, xEngine, modules); | ||
93 | |||
94 | Scene scene | ||
95 | = new SceneHelpers().SetupScene( | ||
96 | "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config); | ||
97 | SceneHelpers.SetupSceneModules(scene, config, modules.ToArray()); | ||
98 | |||
99 | scene.StartScripts(); | ||
100 | |||
101 | return scene; | ||
102 | } | ||
103 | |||
104 | [Test] | ||
105 | public void TestScriptedAttachmentPersistence() | ||
106 | { | ||
107 | TestHelpers.InMethod(); | ||
108 | // TestHelpers.EnableLogging(); | ||
109 | |||
110 | XEngine.XEngine xEngine = new XEngine.XEngine(); | ||
111 | Scene scene = CreateScriptingEnabledTestScene(xEngine); | ||
112 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); | ||
113 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); | ||
114 | |||
115 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10); | ||
116 | TaskInventoryHelpers.AddScript( | ||
117 | scene, | ||
118 | so.RootPart, | ||
119 | "scriptItem", | ||
120 | "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }"); | ||
121 | |||
122 | InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000); | ||
123 | |||
124 | // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running. | ||
125 | // In the future, we need to be able to do this programatically more predicably. | ||
126 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
127 | |||
128 | SceneObjectGroup rezzedSo | ||
129 | = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest); | ||
130 | TaskInventoryItem rezzedScriptItem = rezzedSo.RootPart.Inventory.GetInventoryItem("scriptItem"); | ||
131 | |||
132 | // Wait for chat to signal rezzed script has been started. | ||
133 | m_chatEvent.WaitOne(60000); | ||
134 | |||
135 | // Force save | ||
136 | xEngine.DoBackup(new Object[] { 0 }); | ||
137 | |||
138 | // Console.WriteLine("ItemID {0}", rezzedScriptItem.ItemID); | ||
139 | // | ||
140 | // foreach ( | ||
141 | // string s in Directory.EnumerateFileSystemEntries( | ||
142 | // string.Format("ScriptEngines/{0}", scene.RegionInfo.RegionID))) | ||
143 | // Console.WriteLine(s); | ||
144 | |||
145 | Assert.IsFalse( | ||
146 | File.Exists( | ||
147 | string.Format("ScriptEngines/{0}/{1}.state", scene.RegionInfo.RegionID, rezzedScriptItem.ItemID))); | ||
148 | |||
149 | scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo); | ||
150 | } | ||
151 | } | ||
152 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index f87d631..03fafed 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -718,7 +718,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
718 | // | 718 | // |
719 | try | 719 | try |
720 | { | 720 | { |
721 | instance.SaveState(); | 721 | if (instance.StatePersistedHere) |
722 | instance.SaveState(); | ||
722 | } | 723 | } |
723 | catch (Exception e) | 724 | catch (Exception e) |
724 | { | 725 | { |
@@ -830,7 +831,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
830 | lock (m_Scripts) | 831 | lock (m_Scripts) |
831 | { | 832 | { |
832 | foreach (IScriptInstance instance in m_Scripts.Values) | 833 | foreach (IScriptInstance instance in m_Scripts.Values) |
833 | instances.Add(instance); | 834 | { |
835 | if (instance.StatePersistedHere) | ||
836 | { | ||
837 | // m_log.DebugFormat( | ||
838 | // "[XEngine]: Adding script {0}.{1}, item UUID {2}, prim UUID {3} in {4} for state persistence", | ||
839 | // instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name); | ||
840 | |||
841 | instances.Add(instance); | ||
842 | } | ||
843 | } | ||
834 | } | 844 | } |
835 | 845 | ||
836 | foreach (IScriptInstance i in instances) | 846 | foreach (IScriptInstance i in instances) |
@@ -1457,7 +1467,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1457 | } | 1467 | } |
1458 | } | 1468 | } |
1459 | 1469 | ||
1460 | instance.RemoveState(); | 1470 | if (instance.StatePersistedHere) |
1471 | instance.RemoveState(); | ||
1472 | |||
1461 | instance.DestroyScriptInstance(); | 1473 | instance.DestroyScriptInstance(); |
1462 | 1474 | ||
1463 | m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); | 1475 | m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); |