Ejemplo n.º 1
0
        public void ServerRecievesObjects <T>(int clients, T obj)
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer(clients);

            S.StartServer();

            Client[] Clients = TestDefaults.GetClientList(() =>
            {
                Client c = new Client();
                c.Connect(IPAddress.Loopback, 9090);
                return(c);
            }, clients);

            foreach (Client c in Clients)
            {
                c.SendObject(obj);
            }

            bool b = TestDefaults.TimeOut(() =>
            {
                for (int i = 0; i < clients; i++)
                {
                    S.WaitForPullFromClient <T>((ushort)i);
                }
            }, 6000);

            Assert.True(b);

            S.Close();
        }
Ejemplo n.º 2
0
        public async void ServerRecievesObjectsAsync <T>(int clients, T obj)
        {
            TestDefaults.SetGlobalDefaults();

            Server S = TestDefaults.GetServer(clients);

            S.StartServer();

            Client[] Clients = TestDefaults.GetClientList(() =>
            {
                Client c = new Client();
                c.Connect(IPAddress.Loopback, 9090);
                return(c);
            }, clients);

            List <Task> tasks = new List <Task>();

            foreach (Client c in Clients)
            {
                tasks.Add(c.SendObjectAsync(obj));
            }

            foreach (Task t in tasks)
            {
                await t;
            }

            List <Task <T> > tasks2 = new List <Task <T> >();

            for (int i = 0; i < clients; i++)
            {
                tasks.Add(S.PullFromClientAsync <T>((ushort)i));
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            bool b = true;

            foreach (Task <T> t in tasks2)
            {
                while (sw.ElapsedMilliseconds < 3000 && !t.IsCompleted)
                {
                    ;
                }
                if (!t.Result.Equals(obj))
                {
                    b = false;
                }
            }

            Assert.True(b);

            S.Close();
        }