Exemplo n.º 1
0
        public async void FlushAsync_ShouldNotCallSendAsyncWhenTheBufferIsEmpty()
        {
            var sender = new TestingSender
            {
                SendAsyncDelegate = Substitute.For <Func <List <JaegerSpan>, CancellationToken, Task <int> > >()
            };
            var process = new JaegerProcess("testingService");
            var cts     = new CancellationTokenSource();
            var token   = cts.Token;


            var sent = await sender.FlushAsync(process, token);

            Assert.Equal(0, sent);
            Assert.Empty(sender.Buffer);
            await sender.SendAsyncDelegate.Received(0)(Arg.Any <List <JaegerSpan> >(), Arg.Any <CancellationToken>());
        }
Exemplo n.º 2
0
        public async void FlushAsync_ShouldCallSendAsyncAndReturnCountOfSpansSent()
        {
            var sender = new TestingSender
            {
                SendAsyncDelegate = Substitute.For <Func <List <JaegerSpan>, CancellationToken, Task <int> > >()
            };
            var item    = new JaegerSpan();
            var process = new JaegerProcess("testingService");
            var cts     = new CancellationTokenSource();
            var token   = cts.Token;

            sender.BufferItem(item);
            sender.BufferItem(item);
            sender.BufferItem(item);
            sender.BufferItem(item);

            sender.SendAsyncDelegate(Arg.Is <List <JaegerSpan> >(js => js.Count == 4), Arg.Is(token)).Returns(4);

            var sent = await sender.FlushAsync(process, token);

            Assert.Equal(4, sent);
            Assert.Empty(sender.Buffer);
            await sender.SendAsyncDelegate.Received(1)(Arg.Is <List <JaegerSpan> >(js => js.Count == 4), Arg.Is(token));
        }
Exemplo n.º 3
0
        public async void FlushAsync_ShouldThrowWhenProcessIsNull()
        {
            var sender = new TestingSender();

            await Assert.ThrowsAsync <ArgumentNullException>(() => sender.FlushAsync(null, CancellationToken.None));
        }