예제 #1
0
        public void RespectsMaxSimultaneousConnections()
        {
            Acceptor.MaxSimultaneousConnections = 5;
            Acceptor.Start();

            for (int i = 0; i < Clients.Length; i++)
            {
                StartClientConnect(i);
            }

            WaitForConnections(5);
            Assert.Throws <InvalidOperationException>(() => WaitForConnections(6));       // no more than 5 are connected
            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1));            // no errors
            Assert.Throws <InvalidOperationException>(() => WaitForErrorsOnOtherSide(1)); // no errors on other side

            // simulate one of the connections closing
            Acceptor.ReleaseOpenConnectionSlot();

            WaitForConnections(6);
            Assert.Throws <InvalidOperationException>(() => WaitForConnections(7));       // no more than 5 are connected
            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1));            // no errors
            Assert.Throws <InvalidOperationException>(() => WaitForErrorsOnOtherSide(1)); // no errors on other side
        }