public async Task Restarts_CanCancel_Restarts() { // We need a custom setup. _testHost.Dispose(); int buildCalls = 0; var testHost = new TestFunctionHost(TestScriptPath, TestLogPath, configureWebHostServices: services => { services.Configure <LoggerFilterOptions>(o => { o.MinLevel = LogLevel.Debug; }); services.AddSingleton <IEnvironment>(_mockEnvironment.Object); services.AddSingleton <IConfigureBuilder <IWebJobsBuilder> >(new DelegatedConfigureBuilder <IWebJobsBuilder>(b => { b.Services.Configure <ScriptJobHostOptions>(o => o.Functions = new string[0]); b.Services.Configure <LoggerFilterOptions>(o => { o.MinLevel = LogLevel.Debug; }); })); services.AddSingleton <IScriptHostBuilder>(s => { var appHostOptions = s.GetService <IOptionsMonitor <ScriptApplicationHostOptions> >(); var rootServiceScopeFactory = s.GetService <IServiceScopeFactory>(); IHost Intercept(IScriptHostBuilder builder, bool skipHostStartup, bool skipHostConfigurationParsing) { // We want the the repro to be: // 1. Succeeds, running. // 2. Restart, this host fails while starting. // 3. Restart, this host succeeds. // 4+. All fail, meaning the restart from #2 never succeeds. buildCalls++; if (buildCalls == 2 || buildCalls >= 4) { var mockHost = new Mock <IHost>(); mockHost .Setup(p => p.StartAsync(It.IsAny <CancellationToken>())) .Throws(new HostInitializationException()); return(mockHost.Object); } return(builder.BuildHost(skipHostStartup, skipHostConfigurationParsing)); } return(new InterceptingScriptHostBuilder(appHostOptions, s, rootServiceScopeFactory, Intercept)); }); }); var scriptHostService = testHost.WebHostServices.GetService <IScriptHostManager>() as WebJobsScriptHostService; List <Task> restarts = new List <Task>(); restarts.Add(testHost.RestartAsync(CancellationToken.None)); restarts.Add(testHost.RestartAsync(CancellationToken.None)); await Task.WhenAll(restarts); await TestHelpers.Await(() => scriptHostService.State == ScriptHostState.Running, userMessageCallback : testHost.GetLog); }
public void Test() { FakeQueueClient client = new FakeQueueClient(); var host = TestHelpers.NewJobHost <Functions>(client); var p7 = Invoke(host, client, "SendDirectClient"); Assert.Equal(1, p7.Length); Assert.Equal("abc", p7[0].Message); Assert.Equal("def", p7[0].ExtraPropertery); var p8 = Invoke(host, client, "SendOneDerivedNative"); Assert.Equal(1, p8.Length); DerivedFakeQueueData pd8 = (DerivedFakeQueueData)p8[0]; Assert.Equal("Bonus!", pd8.Bonus); // verify derived prop that wouldn't serialize. var p9 = Invoke(host, client, "SendOneOtherNative"); Assert.Equal(1, p9.Length); Assert.Equal("direct", p9[0].ExtraPropertery); // Set by the DirectFakeQueueData.ToEvent // Single items var p1 = InvokeJson <Payload>(host, client, "SendOnePoco"); Assert.Equal(1, p1.Length); Assert.Equal(123, p1[0].val1); var p2 = Invoke(host, client, "SendOneNative"); Assert.Equal(1, p2.Length); Assert.Equal("message", p2[0].Message); Assert.Equal("extra", p2[0].ExtraPropertery); var p3 = Invoke(host, client, "SendOneString"); Assert.Equal(1, p3.Length); Assert.Equal("stringvalue", p3[0].Message); foreach (string methodName in new string[] { "SendDontQueue", "SendArrayNull", "SendArrayLen0" }) { var p6 = Invoke(host, client, methodName); Assert.Equal(0, p6.Length); } // batching foreach (string methodName in new string[] { "SendSyncCollectorBytes", "SendArrayString", "SendSyncCollectorString", "SendAsyncCollectorString", "SendCollectorNative" }) { var p4 = Invoke(host, client, methodName); Assert.Equal(2, p4.Length); Assert.Equal("first", p4[0].Message); Assert.Equal("second", p4[1].Message); } foreach (string methodName in new string[] { "SendCollectorPoco", "SendArrayPoco" }) { var p5 = InvokeJson <Payload>(host, client, methodName); Assert.Equal(2, p5.Length); Assert.Equal(100, p5[0].val1); Assert.Equal(200, p5[1].val1); } }
public GenericStringTestModelBuilder(TestHelpers testHelpers, Action<ModelConfigurationBuilder>? configure) : base(testHelpers, configure) { }
public void Handle(Reply message) { TestHelpers.DumpHeadersFromCurrentMessageContext(); Data.GotTheReply = true; }
public async Task FixUsings_ReturnsAmbiguousResult() { const string fileContents = @" namespace nsA { public class classX{} } namespace nsB { public class classX{} } namespace OmniSharp { public class class1 { public method1() { var c1 = new $classX(); } } }"; var classLineColumn = TestHelpers.GetLineAndColumnFromDollar(TestHelpers.RemovePercentMarker(fileContents)); var fileContentNoDollarMarker = TestHelpers.RemoveDollarMarker(fileContents); var expectedUnresolved = new List <QuickFix>(); expectedUnresolved.Add(new QuickFix() { Line = classLineColumn.Line, Column = classLineColumn.Column, FileName = fileName, Text = "`classX` is ambiguous" }); await AssertUnresolvedReferences(fileContentNoDollarMarker, expectedUnresolved); }
protected override TestModelBuilder CreateTestModelBuilder( TestHelpers testHelpers, Action<ModelConfigurationBuilder>? configure) => new GenericStringTestModelBuilder(testHelpers, configure);
protected virtual ModelBuilder CreateConventionModelBuilder() { return(TestHelpers.CreateConventionBuilder()); }
public void TestRezAttachmentFromInventory() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); Scene scene = CreateTestScene(); UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); { scene.AttachmentsModule.RezSingleAttachmentFromInventory( sp, attItem.ID, (uint)AttachmentPoint.Chest); // Check scene presence status Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attItem.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); Assert.IsFalse(attSo.Backup); // Check appearance status Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); } // Test attaching an already attached attachment { scene.AttachmentsModule.RezSingleAttachmentFromInventory( sp, attItem.ID, (uint)AttachmentPoint.Chest); // Check scene presence status Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attItem.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); // Check appearance status Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); } }
protected override TestModelBuilder CreateTestModelBuilder(TestHelpers testHelpers) => new GenericTypeTestModelBuilder(testHelpers);
public GenericTypeTestModelBuilder(TestHelpers testHelpers) : base(testHelpers) { }
public void TestSameSimulatorNeighbouringRegionsTeleportV2() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); BaseHttpServer httpServer = new BaseHttpServer(99999); MainServer.AddHttpServer(httpServer); MainServer.Instance = httpServer; AttachmentsModule attModA = new AttachmentsModule(); AttachmentsModule attModB = new AttachmentsModule(); 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); modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule"); SceneHelpers sh = new SceneHelpers(); TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000); SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); SceneHelpers.SetupSceneModules( sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule()); SceneHelpers.SetupSceneModules( sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule()); UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1); AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID); TestClient tc = new TestClient(acd, sceneA); List <TestClient> destinationTestClients = new List <TestClient>(); EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32); Assert.That(destinationTestClients.Count, Is.EqualTo(1)); Assert.That(destinationTestClients[0], Is.Not.Null); InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20); sceneA.AttachmentsModule.RezSingleAttachmentFromInventory( beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest); Vector3 teleportPosition = new Vector3(10, 11, 12); Vector3 teleportLookAt = new Vector3(20, 21, 22); // Here, we need to make clientA's receipt of SendRegionTeleport trigger clientB's CompleteMovement(). This // is to operate the teleport V2 mechanism where the EntityTransferModule will first request the client to // CompleteMovement to the region and then call UpdateAgent to the destination region to confirm the receipt // Both these operations will occur on different threads and will wait for each other. // We have to do this via ThreadPool directly since FireAndForget has been switched to sync for the V1 // test protocol, where we are trying to avoid unpredictable async operations in regression tests. tc.OnTestClientSendRegionTeleport += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL) => ThreadPool.UnsafeQueueUserWorkItem(o => destinationTestClients[0].CompleteMovement(), null); m_numberOfAttachEventsFired = 0; sceneA.RequestTeleportLocation( beforeTeleportSp.ControllingClient, sceneB.RegionInfo.RegionHandle, teleportPosition, teleportLookAt, (uint)TeleportFlags.ViaLocation); // Check attachments have made it into sceneB ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID); // This is appearance data, as opposed to actually rezzed attachments List <AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments(); Assert.That(sceneBAttachments.Count, Is.EqualTo(1)); Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest)); Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID)); Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID)); Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); // This is the actual attachment List <SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments(); Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1)); SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0]; Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name)); Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest)); Assert.IsFalse(actualSceneBAtt.Backup); Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check attachments have been removed from sceneA ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID); // Since this is appearance data, it is still present on the child avatar! List <AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments(); Assert.That(sceneAAttachments.Count, Is.EqualTo(1)); Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); // This is the actual attachment, which should no longer exist List <SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments(); Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0)); Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0)); }
public void TestSameSimulatorNeighbouringRegionsTeleportV1() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); BaseHttpServer httpServer = new BaseHttpServer(99999); MainServer.AddHttpServer(httpServer); MainServer.Instance = httpServer; AttachmentsModule attModA = new AttachmentsModule(); AttachmentsModule attModB = new AttachmentsModule(); 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); modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule"); SceneHelpers sh = new SceneHelpers(); TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000); SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); SceneHelpers.SetupSceneModules( sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule()); SceneHelpers.SetupSceneModules( sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule()); // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour lscm.ServiceVersion = "SIMULATION/0.1"; UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1); AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID); TestClient tc = new TestClient(acd, sceneA); List <TestClient> destinationTestClients = new List <TestClient>(); EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients); ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd); beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32); InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20); sceneA.AttachmentsModule.RezSingleAttachmentFromInventory( beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest); Vector3 teleportPosition = new Vector3(10, 11, 12); Vector3 teleportLookAt = new Vector3(20, 21, 22); m_numberOfAttachEventsFired = 0; sceneA.RequestTeleportLocation( beforeTeleportSp.ControllingClient, sceneB.RegionInfo.RegionHandle, teleportPosition, teleportLookAt, (uint)TeleportFlags.ViaLocation); destinationTestClients[0].CompleteMovement(); // Check attachments have made it into sceneB ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID); // This is appearance data, as opposed to actually rezzed attachments List <AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments(); Assert.That(sceneBAttachments.Count, Is.EqualTo(1)); Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest)); Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID)); Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID)); Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); // This is the actual attachment List <SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments(); Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1)); SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0]; Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name)); Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest)); Assert.IsFalse(actualSceneBAtt.Backup); Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check attachments have been removed from sceneA ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID); // Since this is appearance data, it is still present on the child avatar! List <AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments(); Assert.That(sceneAAttachments.Count, Is.EqualTo(1)); Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); // This is the actual attachment, which should no longer exist List <SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments(); Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0)); Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0)); }
public void TestWearAttachmentFromInventory() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); Scene scene = CreateTestScene(); UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); InventoryItemBase attItem1 = CreateAttachmentItem(scene, ua1.PrincipalID, "att1", 0x10, 0x20); InventoryItemBase attItem2 = CreateAttachmentItem(scene, ua1.PrincipalID, "att2", 0x11, 0x21); { m_numberOfAttachEventsFired = 0; scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem1.ID, (uint)AttachmentPoint.Default); // default attachment point is currently the left hand. Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attItem1.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); // Check appearance status Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); Assert.That(sp.Appearance.GetAttachpoint(attItem1.ID), Is.EqualTo((int)AttachmentPoint.LeftHand)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); } // Test wearing a second attachment at the same position // Until multiple attachments at one point is implemented, this will remove the first attachment // This test relies on both attachments having the same default attachment point (in this case LeftHand // since none other has been set). { scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default); // default attachment point is currently the left hand. Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attItem2.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); // Check appearance status Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3)); } // Test wearing an already attached attachment { scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default); // default attachment point is currently the left hand. Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(attItem2.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); // Check appearance status Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3)); } }
public void TestMove() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); Vector3 startPos = new Vector3(128, 128, 30); UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); ScenePresence npc = m_scene.GetScenePresence(npcId); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); // For now, we'll make the scene presence fly to simplify this test, but this needs to change. npc.Flying = true; m_scene.Update(1); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); Vector3 targetPos = startPos + new Vector3(0, 10, 0); m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); m_scene.Update(1); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); m_scene.Update(10); double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE)); // Try a second movement startPos = npc.AbsolutePosition; targetPos = startPos + new Vector3(10, 0, 0); m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); Assert.That( npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); m_scene.Update(1); // We should really check the exact figure. Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X)); Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X)); Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); m_scene.Update(10); distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); }
public void TestRegisterRegion() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); // Create 4 regions GridRegion r1 = new GridRegion(); r1.RegionName = "Test Region 1"; r1.RegionID = new UUID(1); r1.RegionLocX = 1000 * (int)Constants.RegionSize; r1.RegionLocY = 1000 * (int)Constants.RegionSize; r1.ExternalHostName = "127.0.0.1"; r1.HttpPort = 9001; r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); Scene s = new Scene(new RegionInfo()); s.RegionInfo.RegionID = r1.RegionID; m_LocalConnector.AddRegion(s); GridRegion r2 = new GridRegion(); r2.RegionName = "Test Region 2"; r2.RegionID = new UUID(2); r2.RegionLocX = 1001 * (int)Constants.RegionSize; r2.RegionLocY = 1000 * (int)Constants.RegionSize; r2.ExternalHostName = "127.0.0.1"; r2.HttpPort = 9002; r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); s = new Scene(new RegionInfo()); s.RegionInfo.RegionID = r2.RegionID; m_LocalConnector.AddRegion(s); GridRegion r3 = new GridRegion(); r3.RegionName = "Test Region 3"; r3.RegionID = new UUID(3); r3.RegionLocX = 1005 * (int)Constants.RegionSize; r3.RegionLocY = 1000 * (int)Constants.RegionSize; r3.ExternalHostName = "127.0.0.1"; r3.HttpPort = 9003; r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); s = new Scene(new RegionInfo()); s.RegionInfo.RegionID = r3.RegionID; m_LocalConnector.AddRegion(s); GridRegion r4 = new GridRegion(); r4.RegionName = "Other Region 4"; r4.RegionID = new UUID(4); r4.RegionLocX = 1004 * (int)Constants.RegionSize; r4.RegionLocY = 1002 * (int)Constants.RegionSize; r4.ExternalHostName = "127.0.0.1"; r4.HttpPort = 9004; r4.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); s = new Scene(new RegionInfo()); s.RegionInfo.RegionID = r4.RegionID; m_LocalConnector.AddRegion(s); m_LocalConnector.RegisterRegion(UUID.Zero, r1); GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test"); Assert.IsNull(result, "Retrieved GetRegionByName \"Test\" is not null"); result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test Region 1"); Assert.IsNotNull(result, "Retrieved GetRegionByName is null"); Assert.That(result.RegionName, Is.EqualTo("Test Region 1"), "Retrieved region's name does not match"); m_LocalConnector.RegisterRegion(UUID.Zero, r2); m_LocalConnector.RegisterRegion(UUID.Zero, r3); m_LocalConnector.RegisterRegion(UUID.Zero, r4); result = m_LocalConnector.GetRegionByUUID(UUID.Zero, new UUID(1)); Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null"); Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match"); result = m_LocalConnector.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000)); Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null"); Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match"); List <GridRegion> results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1)); Assert.IsNotNull(results, "Retrieved neighbours list is null"); Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved region's UUID does not match"); results = m_LocalConnector.GetRegionsByName(UUID.Zero, "Test", 10); Assert.IsNotNull(results, "Retrieved GetRegionsByName collection is null"); Assert.That(results.Count, Is.EqualTo(3), "Retrieved neighbour collection is less than expected"); results = m_LocalConnector.GetRegionRange(UUID.Zero, 900 * (int)Constants.RegionSize, 1002 * (int)Constants.RegionSize, 900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize); Assert.IsNotNull(results, "Retrieved GetRegionRange collection is null"); Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected"); results = m_LocalConnector.GetDefaultRegions(UUID.Zero); Assert.IsNotNull(results, "Retrieved GetDefaultRegions collection is null"); Assert.That(results.Count, Is.EqualTo(1), "Retrieved default regions collection has not the expected size"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(1)), "Retrieved default region's UUID does not match"); results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r1.RegionLocX, r1.RegionLocY); Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 1 is null"); Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 1 has not the expected size"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions for default region are not in the expected order 2-4-3"); Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions for default region are not in the expected order 2-4-3"); Assert.That(results[2].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions for default region are not in the expected order 2-4-3"); results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r2.RegionLocX, r2.RegionLocY); Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 2 is null"); Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 2 has not the expected size"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 2-4-3"); Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 2-4-3"); Assert.That(results[2].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 2-4-3"); results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r3.RegionLocX, r3.RegionLocY); Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 3 is null"); Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 3 has not the expected size"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 3-4-2"); Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 3-4-2"); Assert.That(results[2].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 3-4-2"); results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r4.RegionLocX, r4.RegionLocY); Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 4 is null"); Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 4 has not the expected size"); Assert.That(results[0].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 4-3-2"); Assert.That(results[1].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 4-3-2"); Assert.That(results[2].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 4-3-2"); results = m_LocalConnector.GetHyperlinks(UUID.Zero); Assert.IsNotNull(results, "Retrieved GetHyperlinks list is null"); Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected"); }
public async Task Active_UnaryCall_MultipleStreams_UnavailableAddress_FallbackToWorkingAddress() { // Ignore errors SetExpectedErrorsFilter(writeContext => { return(true); }); var tcs = new TaskCompletionSource <object?>(TaskCreationOptions.RunContinuationsAsynchronously); string?host = null; async Task <HelloReply> UnaryMethod(HelloRequest request, ServerCallContext context) { var protocol = context.GetHttpContext().Request.Protocol; Logger.LogInformation("Received protocol: " + protocol); await tcs.Task; host = context.Host; return(new HelloReply { Message = request.Name }); } // Arrange using var endpoint1 = BalancerHelpers.CreateGrpcEndpoint <HelloRequest, HelloReply>(50051, UnaryMethod, nameof(UnaryMethod), HttpProtocols.Http1AndHttp2, isHttps: true); using var endpoint2 = BalancerHelpers.CreateGrpcEndpoint <HelloRequest, HelloReply>(50052, UnaryMethod, nameof(UnaryMethod), HttpProtocols.Http1AndHttp2, isHttps: true); var services = new ServiceCollection(); services.AddSingleton <ResolverFactory>(new StaticResolverFactory(_ => new[] { new BalancerAddress(endpoint1.Address.Host, endpoint1.Address.Port), new BalancerAddress(endpoint2.Address.Host, endpoint2.Address.Port) })); var socketsHttpHandler = new SocketsHttpHandler { EnableMultipleHttp2Connections = true, SslOptions = new System.Net.Security.SslClientAuthenticationOptions() { RemoteCertificateValidationCallback = (_, __, ___, ____) => true } }; var grpcWebHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new RequestVersionHandler(socketsHttpHandler)); var channel = GrpcChannel.ForAddress("static:///localhost", new GrpcChannelOptions { LoggerFactory = LoggerFactory, HttpHandler = grpcWebHandler, ServiceProvider = services.BuildServiceProvider(), Credentials = new SslCredentials() }); var client = TestClientFactory.Create(channel, endpoint1.Method); // Act grpcWebHandler.HttpVersion = new Version(1, 1); var http11CallTasks = new List <Task <HelloReply> >(); for (int i = 0; i < 10; i++) { Logger.LogInformation($"Sending gRPC call {i}"); http11CallTasks.Add(client.UnaryCall(new HelloRequest { Name = "Balancer" }).ResponseAsync); } Logger.LogInformation($"Done sending gRPC calls"); var balancer = BalancerHelpers.GetInnerLoadBalancer <PickFirstBalancer>(channel) !; var subchannel = balancer._subchannel !; var transport = (SocketConnectivitySubchannelTransport)subchannel.Transport; var activeStreams = transport.GetActiveStreams(); // Assert Assert.AreEqual(HttpHandlerType.SocketsHttpHandler, channel.HttpHandlerType); await TestHelpers.AssertIsTrueRetryAsync(() => { activeStreams = transport.GetActiveStreams(); return(activeStreams.Count == 10); }, "Wait for connections to start."); foreach (var t in activeStreams) { Assert.AreEqual(new DnsEndPoint("127.0.0.1", 50051), t.Address.EndPoint); } // Act grpcWebHandler.HttpVersion = new Version(2, 0); var http2CallTasks = new List <Task <HelloReply> >(); for (int i = 0; i < 10; i++) { Logger.LogInformation($"Sending gRPC call {i}"); http2CallTasks.Add(client.UnaryCall(new HelloRequest { Name = "Balancer" }).ResponseAsync); } Logger.LogInformation($"Done sending gRPC calls"); // Assert await TestHelpers.AssertIsTrueRetryAsync(() => { activeStreams = transport.GetActiveStreams(); return(activeStreams.Count == 11); }, "Wait for connections to start."); Assert.AreEqual(new DnsEndPoint("127.0.0.1", 50051), activeStreams[activeStreams.Count - 1].Address.EndPoint); tcs.SetResult(null); await Task.WhenAll(http11CallTasks).DefaultTimeout(); await Task.WhenAll(http2CallTasks).DefaultTimeout(); Assert.AreEqual(ConnectivityState.Ready, channel.State); Logger.LogInformation($"Closing {endpoint1}"); endpoint1.Dispose(); // There are still be 10 HTTP/1.1 connections because they aren't immediately removed // when the server is shutdown and connectivity is lost. await TestHelpers.AssertIsTrueRetryAsync(() => { activeStreams = transport.GetActiveStreams(); return(activeStreams.Count == 10); }, "Wait for HTTP/2 connection to end."); grpcWebHandler.HttpVersion = new Version(1, 1); await Task.Delay(1000); Logger.LogInformation($"Starting failed call"); var ex = await ExceptionAssert.ThrowsAsync <RpcException>(() => client.UnaryCall(new HelloRequest { Name = "Balancer" }).ResponseAsync).DefaultTimeout(); Assert.AreEqual(StatusCode.Unavailable, ex.StatusCode); // Removed by failed call. activeStreams = transport.GetActiveStreams(); Assert.AreEqual(0, activeStreams.Count); Assert.AreEqual(ConnectivityState.Idle, channel.State); Logger.LogInformation($"Next call goes to fallback address."); var reply = await client.UnaryCall(new HelloRequest { Name = "Balancer" }).ResponseAsync.TimeoutAfter(TimeSpan.FromSeconds(20)); Assert.AreEqual("Balancer", reply.Message); Assert.AreEqual("127.0.0.1:50052", host); activeStreams = transport.GetActiveStreams(); Assert.AreEqual(1, activeStreams.Count); Assert.AreEqual(new DnsEndPoint("127.0.0.1", 50052), activeStreams[0].Address.EndPoint); }
public void TestWearAttachmentFromGround() { TestHelpers.InMethod(); // TestHelpers.EnableLogging(); Scene scene = CreateTestScene(); UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); SceneObjectGroup so2 = SceneHelpers.AddSceneObject(scene, "att2", sp.UUID); { SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "att1", sp.UUID); m_numberOfAttachEventsFired = 0; scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Default, false, true, false); // Check status on scene presence Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(so.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); // Check item status Assert.That( sp.Appearance.GetAttachpoint(attSo.FromItemID), Is.EqualTo((int)AttachmentPoint.LeftHand)); InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID)); Assert.That(attachmentItem, Is.Not.Null); Assert.That(attachmentItem.Name, Is.EqualTo(so.Name)); InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object); Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(2)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1)); } // Test wearing a different attachment from the ground. { scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false); // Check status on scene presence Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(so2.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); // Check item status Assert.That( sp.Appearance.GetAttachpoint(attSo.FromItemID), Is.EqualTo((int)AttachmentPoint.LeftHand)); InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID)); Assert.That(attachmentItem, Is.Not.Null); Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name)); InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object); Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3)); } // Test rewearing an already worn attachment from ground. Nothing should happen. { scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false); // Check status on scene presence Assert.That(sp.HasAttachments(), Is.True); List <SceneObjectGroup> attachments = sp.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; Assert.That(attSo.Name, Is.EqualTo(so2.Name)); Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand)); Assert.That(attSo.IsAttachment); Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.IsTemporary, Is.False); // Check item status Assert.That( sp.Appearance.GetAttachpoint(attSo.FromItemID), Is.EqualTo((int)AttachmentPoint.LeftHand)); InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID)); Assert.That(attachmentItem, Is.Not.Null); Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name)); InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object); Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID)); Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); // Check events Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3)); } }