public void TestExchangeResponseSentBlockedBefore() { //given var penalizer = new Penalizer(_samplePenalties); var sentMessage = new Message <ExchangeInformationResponse>( new ExchangeInformationResponse { }); //when penalizer.PenalizeOnSend(sentMessage); //then Assert.IsTrue(penalizer.UnderPenalty); }
public void TestClearRemovesPenalty() { //given var penalizer = new Penalizer(_samplePenalties); var discoveryRequest = new Message <DiscoveryRequest>( new DiscoveryRequest()); //when penalizer.PenalizeOnSend(discoveryRequest); penalizer.ClearPenalty(); //then Assert.IsFalse(penalizer.UnderPenalty); }
public void TestBlockedAfterStandardRequest() { //given var penalizer = new Penalizer(_samplePenalties); var discoveryRequest = new Message <DiscoveryRequest>( new DiscoveryRequest()); int waitTime = Int32.Parse(_samplePenalties.Discovery); //when penalizer.PenalizeOnSend(discoveryRequest); //then Thread.Sleep(waitTime); Assert.IsTrue(penalizer.UnderPenalty); }
public void TestExchangeResponseSentFreeAfter() { //given var penalizer = new Penalizer(_samplePenalties); var sentMessage = new Message <ExchangeInformationResponse>( new ExchangeInformationResponse { }); int waitTime = Int32.Parse(_samplePenalties.InformationExchange); //when penalizer.PenalizeOnSend(sentMessage); //then Thread.Sleep(waitTime); Assert.IsFalse(penalizer.UnderPenalty); }
public void TestFreeAfterStandardRequestResponseAndTimeout() { //given var penalizer = new Penalizer(_samplePenalties); var discoveryRequest = new Message <DiscoveryRequest>( new DiscoveryRequest()); var discoveryResponse = new Message <DiscoveryResponse>( new DiscoveryResponse()); int waitTime = Int32.Parse(_samplePenalties.Discovery); //when penalizer.PenalizeOnSend(discoveryRequest); Thread.Sleep(waitTime); penalizer.PenalizeOnReceive(discoveryResponse); //then Thread.Sleep(waitTime); Assert.IsFalse(penalizer.UnderPenalty); }
public void TestSendAndReceiveStillBlockedAfterSmaller() { //given var penalizer = new Penalizer(_samplePenalties); var exchangeRequest = new Message <ExchangeInformationRequest>( new ExchangeInformationRequest()); int exchangeWaitTime = Int32.Parse(_samplePenalties.InformationExchange); var moveMessage = new Message <MoveResponse>( new MoveResponse()); int moveWaitTime = Int32.Parse(_samplePenalties.Move); int waitTime = Math.Min(moveWaitTime, exchangeWaitTime); //when penalizer.PenalizeOnSend(exchangeRequest); penalizer.PenalizeOnReceive(moveMessage); //then Thread.Sleep(waitTime); Assert.IsTrue(penalizer.UnderPenalty); }