// I'm commenting this test because it does not represent // crossings. The Thread.Sleep's in here are not meaningful mocks, // and they sometimes fail in panda. // We need to talk in order to develop a test // that really tests region crossings. There are 3 async components, // but things are synchronous among them. So there should be // 3 threads in here. //[Test] public void T021_TestCrossToNewRegion() { TestHelper.InMethod(); scene.RegisterRegionWithGrid(); scene2.RegisterRegionWithGrid(); // Adding child agent to region 1001 string reason; scene2.NewUserConnection(acd1, 0, out reason); scene2.AddNewClient(testclient); ScenePresence presence = scene.GetScenePresence(agent1); presence.MakeRootAgent(new Vector3(0, unchecked (Constants.RegionSize - 1), 0), true); ScenePresence presence2 = scene2.GetScenePresence(agent1); // Adding neighbour region caps info to presence2 string cap = presence.ControllingClient.RequestClientInfo().CapsPath; presence2.AddNeighbourRegion(region1, cap); Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region."); Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region."); // Cross to x+1 presence.AbsolutePosition = new Vector3(Constants.RegionSize + 1, 3, 100); presence.Update(); EventWaitHandle wh = new EventWaitHandle(false, EventResetMode.AutoReset, "Crossing"); // Mimicking communication between client and server, by waiting OK from client // sent by TestClient.CrossRegion call. Originally, this is network comm. if (!wh.WaitOne(5000, false)) { presence.Update(); if (!wh.WaitOne(8000, false)) { throw new ArgumentException("1 - Timeout waiting for signal/variable."); } } // This is a TestClient specific method that fires OnCompleteMovementToRegion event, which // would normally be fired after receiving the reply packet from comm. done on the last line. testclient.CompleteMovement(); // Crossings are asynchronous int timer = 10; // Make sure cross hasn't already finished if (!presence.IsInTransit && !presence.IsChildAgent) { // If not and not in transit yet, give it some more time Thread.Sleep(5000); } // Enough time, should at least be in transit by now. while (presence.IsInTransit && timer > 0) { Thread.Sleep(1000); timer -= 1; } Assert.That(timer, Is.GreaterThan(0), "Timed out waiting to cross 2->1."); Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected."); Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent."); // Cross Back presence2.AbsolutePosition = new Vector3(-10, 3, 100); presence2.Update(); if (!wh.WaitOne(5000, false)) { presence2.Update(); if (!wh.WaitOne(8000, false)) { throw new ArgumentException("2 - Timeout waiting for signal/variable."); } } testclient.CompleteMovement(); if (!presence2.IsInTransit && !presence2.IsChildAgent) { // If not and not in transit yet, give it some more time Thread.Sleep(5000); } // Enough time, should at least be in transit by now. while (presence2.IsInTransit && timer > 0) { Thread.Sleep(1000); timer -= 1; } Assert.That(timer, Is.GreaterThan(0), "Timed out waiting to cross 1->2."); Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected."); Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again."); }
/// <summary> /// Set up correct handling of the InformClientOfNeighbour call from the source region that triggers the /// viewer to setup a connection with the destination region. /// </summary> /// <param name='tc'></param> /// <param name='neighbourTcs'> /// A list that will be populated with any TestClients set up in response to /// being informed about a destination region. /// </param> public static void SetupSendRegionTeleportTriggersDestinationClientCreateAndCompleteMovement( TestClient client, List<TestClient> destinationClients) { client.OnTestClientSendRegionTeleport += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) => { uint x, y; Utils.LongToUInts(regionHandle, out x, out y); x /= Constants.RegionSize; y /= Constants.RegionSize; m_log.DebugFormat( "[TEST CLIENT]: Processing send region teleport for destination at {0},{1} at {2}", x, y, regionExternalEndPoint); AgentCircuitData newAgent = client.RequestClientInfo(); Scene destinationScene; SceneManager.Instance.TryGetScene(x, y, out destinationScene); TestClient destinationClient = new TestClient(newAgent, destinationScene); destinationClients.Add(destinationClient); destinationScene.AddNewAgent(destinationClient, PresenceType.User); ThreadPool.UnsafeQueueUserWorkItem(o => destinationClient.CompleteMovement(), null); }; }
public void TestCrossOnSameSimulatorNoRootDestPerm() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); UUID userId = TestHelpers.ParseTail(0x1); EntityTransferModule etmA = new EntityTransferModule(); EntityTransferModule etmB = new EntityTransferModule(); LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); IConfigSource config = new IniConfigSource(); IConfig modulesConfig = config.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); TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); // We need to set up the permisions module on scene B so that our later use of agent limit to deny // QueryAccess won't succeed anyway because administrators are always allowed in and the default // IsAdministrator if no permissions module is present is true. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB); AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); TestClient tc = new TestClient(acd, sceneA); List <TestClient> destinationTestClients = new List <TestClient>(); EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); // Make sure sceneB will not accept this avatar. sceneB.RegionInfo.EstateSettings.PublicAccess = false; ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); originalSp.AbsolutePosition = new Vector3(128, 32, 10); AgentUpdateArgs moveArgs = new AgentUpdateArgs(); //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero); moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2))); moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; moveArgs.SessionID = acd.SessionID; originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs); sceneA.Update(1); // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition); // FIXME: This is a sufficient number of updates to for the presence to reach the northern border. // But really we want to do this in a more robust way. for (int i = 0; i < 100; i++) { sceneA.Update(1); // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition); } // sceneA agent should still be root ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID); Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False); ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID); // sceneB agent should also still be root Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); // sceneB should ignore unauthorized attempt to upgrade agent to root TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient); int agentMovementCompleteReceived = 0; sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++; sceneBTc.CompleteMovement(); Assert.That(agentMovementCompleteReceived, Is.EqualTo(0)); Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); }
public void TestCrossOnSameSimulator() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); UUID userId = TestHelpers.ParseTail(0x1); // TestEventQueueGetModule eqmA = new TestEventQueueGetModule(); EntityTransferModule etmA = new EntityTransferModule(); EntityTransferModule etmB = new EntityTransferModule(); LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); IConfigSource config = new IniConfigSource(); IConfig modulesConfig = config.AddConfig("Modules"); modulesConfig.Set("EntityTransferModule", etmA.Name); modulesConfig.Set("SimulationServices", lscm.Name); // IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); // In order to run a single threaded regression test we do not want the entity transfer module waiting // for a callback from the destination scene before removing its avatar data. // entityTransferConfig.Set("wait_for_callback", false); SceneHelpers sh = new SceneHelpers(); TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA); SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); TestClient tc = new TestClient(acd, sceneA); List <TestClient> destinationTestClients = new List <TestClient>(); EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); originalSp.AbsolutePosition = new Vector3(128, 32, 10); // originalSp.Flying = true; // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition); // eqmA.ClearEvents(); AgentUpdateArgs moveArgs = new AgentUpdateArgs(); //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero); moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2))); moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; moveArgs.SessionID = acd.SessionID; originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs); sceneA.Update(1); // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition); // FIXME: This is a sufficient number of updates to for the presence to reach the northern border. // But really we want to do this in a more robust way. for (int i = 0; i < 100; i++) { sceneA.Update(1); // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition); } // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm // messages // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events; // // Assert.That(eqmEvents.Count, Is.EqualTo(1)); // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True); // // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID]; // // Assert.That(spEqmEvents.Count, Is.EqualTo(1)); // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion")); // sceneA should now only have a child agent ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID); Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True); ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID); // Agent remains a child until the client triggers complete movement Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient); int agentMovementCompleteReceived = 0; sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++; sceneBTc.CompleteMovement(); Assert.That(agentMovementCompleteReceived, Is.EqualTo(1)); Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False); }
public void TestCrossOnSameSimulatorWithSittingAvatar() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); UUID userId = TestHelpers.ParseTail(0x1); int sceneObjectIdTail = 0x2; Vector3 so1StartPos = new Vector3(128, 10, 20); EntityTransferModule etmA = new EntityTransferModule(); EntityTransferModule etmB = new EntityTransferModule(); LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); IConfigSource config = new IniConfigSource(); IConfig modulesConfig = config.AddConfig("Modules"); modulesConfig.Set("EntityTransferModule", etmA.Name); modulesConfig.Set("SimulationServices", lscm.Name); IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); // In order to run a single threaded regression test we do not want the entity transfer module waiting // for a callback from the destination scene before removing its avatar data. entityTransferConfig.Set("wait_for_callback", false); SceneHelpers sh = new SceneHelpers(); TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail); UUID so1Id = so1.UUID; so1.AbsolutePosition = so1StartPos; AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); TestClient tc = new TestClient(acd, sceneA); List <TestClient> destinationTestClients = new List <TestClient>(); EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); ScenePresence sp1SceneA = SceneHelpers.AddScenePresence(sceneA, tc, acd); sp1SceneA.AbsolutePosition = so1StartPos; sp1SceneA.HandleAgentRequestSit(sp1SceneA.ControllingClient, sp1SceneA.UUID, so1.UUID, Vector3.Zero); // Cross sceneA.SceneGraph.UpdatePrimGroupPosition( so1.LocalId, new Vector3(so1StartPos.X, so1StartPos.Y - 20, so1StartPos.Z), userId); SceneObjectGroup so1PostCross; { ScenePresence sp1SceneAPostCross = sceneA.GetScenePresence(userId); Assert.IsTrue(sp1SceneAPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly false"); ScenePresence sp1SceneBPostCross = sceneB.GetScenePresence(userId); TestClient sceneBTc = ((TestClient)sp1SceneBPostCross.ControllingClient); sceneBTc.CompleteMovement(); Assert.IsFalse(sp1SceneBPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true"); Assert.IsTrue(sp1SceneBPostCross.IsSatOnObject); Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id), "uck"); so1PostCross = sceneB.GetSceneObjectGroup(so1Id); Assert.NotNull(so1PostCross); Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount()); } Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition; // Console.WriteLine("CRISSCROSS"); // Recross sceneB.SceneGraph.UpdatePrimGroupPosition( so1PostCross.LocalId, new Vector3(so1PostCrossPos.X, so1PostCrossPos.Y + 20, so1PostCrossPos.Z), userId); { ScenePresence sp1SceneBPostReCross = sceneB.GetScenePresence(userId); Assert.IsTrue(sp1SceneBPostReCross.IsChildAgent, "sp1SceneBPostReCross.IsChildAgent unexpectedly false"); ScenePresence sp1SceneAPostReCross = sceneA.GetScenePresence(userId); TestClient sceneATc = ((TestClient)sp1SceneAPostReCross.ControllingClient); sceneATc.CompleteMovement(); Assert.IsFalse(sp1SceneAPostReCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true"); Assert.IsTrue(sp1SceneAPostReCross.IsSatOnObject); Assert.IsNull(sceneB.GetSceneObjectGroup(so1Id), "uck2"); SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id); Assert.NotNull(so1PostReCross); Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount()); } }