private void TestStop(string script) { // In these tests we're only interested in the first message to confirm that the script has started. m_chatMessagesThreshold = 1; UUID userId = TestHelpers.ParseTail(0x1); // UUID objectId = TestHelpers.ParseTail(0x100); // UUID itemId = TestHelpers.ParseTail(0x3); string itemName = "TestStop"; SceneObjectPart partWhereRezzed = CreateScript(script, itemName, userId); TaskInventoryItem rezzedItem = partWhereRezzed.Inventory.GetInventoryItem(itemName); // Wait for the script to start the event before we try stopping it. m_chatEvent.WaitOne(60000); if (m_osChatMessageReceived != null) { Console.WriteLine("Script started with message [{0}]", m_osChatMessageReceived.Message); } else { Assert.Fail("Script did not start"); } // 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 next statement 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); }