Add regression test TestStopOnLongForLoop()
parent
5ac0447e0f
commit
3024d0e61c
|
@ -146,6 +146,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance.Tests
|
||||||
Assert.That(running, Is.False);
|
Assert.That(running, Is.False);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestStopOnLongForLoop()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
UUID userId = TestHelpers.ParseTail(0x1);
|
||||||
|
// UUID objectId = TestHelpers.ParseTail(0x100);
|
||||||
|
// UUID itemId = TestHelpers.ParseTail(0x3);
|
||||||
|
string itemName = "TestStopOnLongForLoop() Item";
|
||||||
|
|
||||||
|
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStopOnLongForLoop", 0x100);
|
||||||
|
m_scene.AddNewSceneObject(so, true);
|
||||||
|
|
||||||
|
InventoryItemBase itemTemplate = new InventoryItemBase();
|
||||||
|
// itemTemplate.ID = itemId;
|
||||||
|
itemTemplate.Name = itemName;
|
||||||
|
itemTemplate.Folder = so.UUID;
|
||||||
|
itemTemplate.InvType = (int)InventoryType.LSL;
|
||||||
|
|
||||||
|
m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
|
||||||
|
|
||||||
|
SceneObjectPart partWhereRezzed = m_scene.RezNewScript(userId, itemTemplate,
|
||||||
|
@"default
|
||||||
|
{
|
||||||
|
state_entry()
|
||||||
|
{
|
||||||
|
llSay(0, ""Thin Lizzy"");
|
||||||
|
integer i = 0;
|
||||||
|
for (i = 0; i < 2147483647; i++)
|
||||||
|
llSay(0, ""Iter "" + (string)i);
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
TaskInventoryItem rezzedItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
|
||||||
|
|
||||||
|
// Wait for the script to start the event before we try stopping it.
|
||||||
|
m_chatEvent.WaitOne(60000);
|
||||||
|
|
||||||
|
Console.WriteLine("Script started with message [{0}]", m_osChatMessageReceived.Message);
|
||||||
|
|
||||||
|
// FIXME: This is a very poor way of trying to avoid a low-probability race condition where the script
|
||||||
|
// executes llSay() but has not started the sleep before we try to stop it.
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
// We need a way of carrying on if StopScript() fail, since it won't return if the script isn't actually
|
||||||
|
// stopped. This kind of multi-threading is far from ideal in a regression test.
|
||||||
|
new Thread(() => { m_xEngine.StopScript(rezzedItem.ItemID); m_stoppedEvent.Set(); }).Start();
|
||||||
|
|
||||||
|
if (!m_stoppedEvent.WaitOne(30000))
|
||||||
|
Assert.Fail("Script did not co-operatively stop.");
|
||||||
|
|
||||||
|
bool running;
|
||||||
|
TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
|
||||||
|
Assert.That(
|
||||||
|
SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True);
|
||||||
|
Assert.That(running, Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnChatFromWorld(object sender, OSChatMessage oscm)
|
private void OnChatFromWorld(object sender, OSChatMessage oscm)
|
||||||
{
|
{
|
||||||
// Console.WriteLine("Got chat [{0}]", oscm.Message);
|
// Console.WriteLine("Got chat [{0}]", oscm.Message);
|
||||||
|
|
Loading…
Reference in New Issue