Beispiel #1
0
        public void ReceiveWithoutATimeout_GivenThereIsEventuallyASender_WillReceiveSuccessfully()
        {
            // Arrange
            const int sentMessage          = 3;
            var       receivedSuccessfully = false;
            var       receivedMessage      = default(int);
            var       thread = new Thread(() =>
            {
                receivedMessage      = simpleOutlet.Receive();
                receivedSuccessfully = true;
            });

            // Act
            thread.Start();
            Thread.Sleep(500);

            // Assert
            receivedSuccessfully.Should().BeFalse();

            // Act
            inlet.Send(sentMessage);
            Thread.Sleep(500);

            // Assert
            receivedMessage.Should().Be(sentMessage);
            receivedSuccessfully.Should().BeTrue();
        }
Beispiel #2
0
        public void TestBarrier()
        {
            foreach (var workerThread in workerThreads)
            {
                workerThread.Start();
            }

            for (var i = 0; i < 100; i++)
            {
                barrierInlet.Send(0);
                sharedMemory.All(s => s == i).Should().BeTrue();
                barrierInlet.Send(0);
            }
        }
Beispiel #3
0
        public void WhenThereIsOnlyAnExternalSender_TheMessageCanBeReceived()
        {
            // Arrange
            const int message = 14;

            RunInThread(() => externalSenderInlet.Send(message));

            // Act
            prepareSendInlet.Send(1);
            var result = resultOutlet.Receive();

            // Assert
            result.IsRight.Should().BeTrue(); // I read the message
            result.GetRight().Should().Be(message);
        }
Beispiel #4
0
 public ReceiveOrSendResult <TReceive, TSend> ReceiveOrSend(TSend message)
 {
     preparationInlet.Send(message);
     return(TryButFlushOnException(() => resultOutlet.Receive()));
 }