/// <summary> /// PERFORM FTP GATHER /// </summary> /// <param name="camera"></param> /// <returns></returns> public List <GatherResult> PerformFtpGather(EntityServer server) { var task = Task.Run(() => { Thread.Sleep(server.FtpDemoWaitMs); }); bool isCompletedSuccessfully = task.Wait(TimeSpan.FromMilliseconds(server.FtpGatherTimeoutMs)); if (isCompletedSuccessfully) { //return task.Result; //DEBUG var result = new List <GatherResult>(); foreach (var camera in server.Cameras) { result.Add(new GatherResult { ServerName = server.Name, RawImageName = camera.Name, Camera = camera, ThreadNumber = Thread.CurrentThread.ManagedThreadId }); } return(result); } else { throw new TimeoutException("PerformFtpGather Timeout: " + server.Name + " (thread " + Thread.CurrentThread.ManagedThreadId.ToString() + ")"); } }
private void EntitiesAreSynchronized() { // Initialization RailClientRoom clientRoom = client.StartRoom(); RailServerRoom serverRoom = server.StartRoom(); EntityServer entityServerSide = serverRoom.AddNewEntity <EntityServer>(); server.AddClient(peerServerSide.Object, ""); client.SetPeer(peerClientSide.Object); // Nothing has been sent or received yet peerClientSide.Verify( c => c.SendPayload(It.IsAny <ArraySegment <byte> >()), Times.Never()); peerServerSide.Verify( c => c.SendPayload(It.IsAny <ArraySegment <byte> >()), Times.Never()); Assert.Empty(clientRoom.Entities); Assert.Single(serverRoom.Entities); // Let the server send its update to the client for (int i = 0; i < RailConfig.SERVER_SEND_RATE + RailConfig.CLIENT_SEND_RATE + 1; ++i) { peerServerSide.Object.PollEvents(); server.Update(); peerClientSide.Object.PollEvents(); client.Update(); } // The client has received the server entity. Assert.Single(clientRoom.Entities); Assert.Single(serverRoom.Entities); // Clients representation of the entity is identical to the server RailEntityBase entityProxy = clientRoom.Entities.First(); Assert.IsType <EntityClient>(entityProxy); EntityClient entityClientSide = entityProxy as EntityClient; Assert.NotNull(entityClientSide); Assert.Equal(entityServerSide.Id, entityProxy.Id); Assert.Equal(entityClientSide.State.PosX, entityServerSide.State.PosX); Assert.Equal(entityClientSide.State.PosY, entityServerSide.State.PosY); // Change the entity on the server side and sync it to the client float fExpectedPosX = 42; float fExpectedPosY = 106; entityServerSide.State.PosX = fExpectedPosX; entityServerSide.State.PosY = fExpectedPosY; // Let the server detect the change and send the packet server.Update(); bool bWasSendTick = serverRoom.Tick.IsSendTick(RailConfig.SERVER_SEND_RATE); while (!bWasSendTick) { server.Update(); bWasSendTick = serverRoom.Tick.IsSendTick(RailConfig.SERVER_SEND_RATE); } // Let the client receive & process the packet. We need to bring the client up to the same tick as the server to see the result. while (clientRoom.Tick < serverRoom.Tick) { peerClientSide.Object.PollEvents(); client.Update(); } Assert.Equal(fExpectedPosX, entityClientSide.State.PosX); Assert.Equal(fExpectedPosY, entityClientSide.State.PosY); Assert.Equal(fExpectedPosX, entityServerSide.State.PosX); Assert.Equal(fExpectedPosY, entityServerSide.State.PosY); }