public void TestDestroyPieceResponseReceiveBlockedDuring() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <DestroyPieceResponse>( new DestroyPieceResponse()); //when penalizer.PenalizeOnReceive(receivedMessage); //then Assert.IsTrue(penalizer.UnderPenalty); }
public void TestTwoMessageReceiveStillBlockedAfterSmaller() { //given var penalizer = new Penalizer(_samplePenalties); var penaltyNotWaitedMessage = new Message <PenaltyNotWaitedError>( new PenaltyNotWaitedError { WaitFor = 30 }); int penaltyNotWaitedWaitTime = penaltyNotWaitedMessage.MessagePayload.WaitFor; var moveMessage = new Message <MoveResponse>( new MoveResponse()); int moveWaitTime = Int32.Parse(_samplePenalties.Move); int waitTime = Math.Min(moveWaitTime, penaltyNotWaitedWaitTime); //when penalizer.PenalizeOnReceive(penaltyNotWaitedMessage); penalizer.PenalizeOnReceive(moveMessage); //then Thread.Sleep(waitTime); Assert.IsTrue(penalizer.UnderPenalty); }
public void TestDiscoveryResponseReceiveFreeAfter() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <DiscoveryResponse>( new DiscoveryResponse()); int waitTime = Int32.Parse(_samplePenalties.Discovery); //when penalizer.PenalizeOnReceive(receivedMessage); //then Thread.Sleep(waitTime); Assert.IsFalse(penalizer.UnderPenalty); }
public void TestCheckPieceResponseReceiveFreeAfter() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <CheckHoldedPieceResponse>( new CheckHoldedPieceResponse()); int waitTime = Int32.Parse(_samplePenalties.CheckForSham); //when penalizer.PenalizeOnReceive(receivedMessage); //then Thread.Sleep(waitTime); Assert.IsFalse(penalizer.UnderPenalty); }
public void TestPenaltyNotWaitedReceiveBlockedBefore() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <PenaltyNotWaitedError>( new PenaltyNotWaitedError { WaitFor = 100 }); int waitTime = receivedMessage.MessagePayload.WaitFor; //when penalizer.PenalizeOnReceive(receivedMessage); //then Thread.Sleep(waitTime / 2); Assert.IsTrue(penalizer.UnderPenalty); }
public void TestPenaltyNotWaitedReceiveFreeAfter() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <PenaltyNotWaitedError>( new PenaltyNotWaitedError { WaitFor = 30 }); int waitTime = receivedMessage.MessagePayload.WaitFor + 10;//precision (from documentation) //when penalizer.PenalizeOnReceive(receivedMessage); //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 TestPutPieceResponseReceiveBlockedDuring() { //given var penalizer = new Penalizer(_samplePenalties); var receivedMessage = new Message <PutPieceResponse>( new PutPieceResponse()); //checking after half of wait time only in one test because: //if penalty to wait is to slow then during the time it takes to execute //instructions before assert penalty could be over //longer penalty only in one test otherwise all tests would take too long int waitTime = Int32.Parse(_samplePenalties.PutPiece); //when penalizer.PenalizeOnReceive(receivedMessage); //then Thread.Sleep(waitTime / 2); Assert.IsTrue(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); }