예제 #1
0
        public async Task TestSendAllThenReceive()
        {
            foreach (bool post in DataflowTestHelpers.BooleanValues)
            {
                foreach (bool sync in DataflowTestHelpers.BooleanValues)
                {
                    const int Iters = 10;
                    Func <TransformBlock <int, int> > func = sync ?
                                                             (Func <TransformBlock <int, int> >)(() => new TransformBlock <int, int>(i => i * 2)) :
                                                             (Func <TransformBlock <int, int> >)(() => new TransformBlock <int, int>(i => Task.Run(() => i * 2)));
                    var network = DataflowTestHelpers.Chain <TransformBlock <int, int>, int>(4, func);

                    if (post)
                    {
                        network.PostRange(0, Iters);
                    }
                    else
                    {
                        await Task.WhenAll(from i in Enumerable.Range(0, Iters) select network.SendAsync(i));
                    }

                    for (int i = 0; i < Iters; i++)
                    {
                        Assert.Equal(expected: i * 16, actual: await network.ReceiveAsync());
                    }
                }
            }
        }
예제 #2
0
 public async Task TestChainedSendReceive()
 {
     foreach (bool post in DataflowTestHelpers.BooleanValues)
     {
         foreach (bool sync in DataflowTestHelpers.BooleanValues)
         {
             const int Iters = 10;
             Func <TransformBlock <int, int> > func = sync ?
                                                      (Func <TransformBlock <int, int> >)(() => new TransformBlock <int, int>(i => i * 2)) :
                                                      (Func <TransformBlock <int, int> >)(() => new TransformBlock <int, int>(i => Task.Run(() => i * 2)));
             var network = DataflowTestHelpers.Chain <TransformBlock <int, int>, int>(4, func);
             for (int i = 0; i < Iters; i++)
             {
                 if (post)
                 {
                     network.Post(i);
                 }
                 else
                 {
                     await network.SendAsync(i);
                 }
                 Assert.Equal(expected: i * 16, actual: await network.ReceiveAsync());
             }
         }
     }
 }
예제 #3
0
 public async Task TestChainedSendReceive()
 {
     foreach (bool post in DataflowTestHelpers.BooleanValues)
     {
         const int Iters   = 10;
         var       network = DataflowTestHelpers.Chain <BufferBlock <int>, int>(4, () => new BufferBlock <int>());
         for (int i = 0; i < Iters; i++)
         {
             if (post)
             {
                 network.Post(i);
             }
             else
             {
                 await network.SendAsync(i);
             }
             Assert.Equal(expected: i, actual: await network.ReceiveAsync());
         }
     }
 }
예제 #4
0
        public async Task TestSendAllThenReceive()
        {
            foreach (bool post in DataflowTestHelpers.BooleanValues)
            {
                const int Iters   = 10;
                var       network = DataflowTestHelpers.Chain <BufferBlock <int>, int>(4, () => new BufferBlock <int>());

                if (post)
                {
                    network.PostRange(0, Iters);
                }
                else
                {
                    await Task.WhenAll(from i in Enumerable.Range(0, Iters) select network.SendAsync(i));
                }

                for (int i = 0; i < Iters; i++)
                {
                    Assert.Equal(expected: i, actual: await network.ReceiveAsync());
                }
            }
        }