Ejemplo n.º 1
0
 public void AllPassed(ChanBase<int> chan) {
   Func<Task> a = async () => {
     for (int i = 0; i < 1000; ++i)
       await chan.SendAsync(i);
     await chan.Close();
   };
   var x1 = AllPassedAsyncSum(chan, 10000 / 4);
   var x2 = AllPassedAsyncSum(chan, 10000 / 4);
   var x3 = AllPassedAsyncSum(chan, 10000 / 4);
   var x4 = AllPassedAsyncSum(chan, 10000 / 4);
   int rslt = 0;
   Action k = async () => rslt = await x1 + await x2 + await x3 + await x4;
   k();
   Task.WaitAll(a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), x1, x2, x3, x4);
   Assert.AreEqual(4995000, rslt);
 }
Ejemplo n.º 2
0
    public void OrderWithSingleInAndOut(ChanBase<int> chan) {
      //this is needed: tests work correctly otherwise... this initialzes thread pool or something...
      Parallel.Invoke(Task.Delay(4).Wait, Task.Delay(3).Wait, Task.Delay(5).Wait);

      Func<Task> af = async () => {
        for (int i = -500; i < 50000; ++i)
          await chan.SendAsync(i);
        DebugCounter.Incg("test.order", "all sent");
        await chan.Close();
      };
      Func<Task> bf = async () => {
        int prev;
        int cur = int.MinValue;
        try {
          while (true) {
            prev = cur;
            cur = await chan.ReceiveAsync();
            if (cur < prev)
              Assert.GreaterOrEqual(cur, prev);
          }
        } catch (TaskCanceledException) {
          DebugCounter.Incg("test.order", "cancelled");
        }
      };

      Task.WaitAll(af(), bf());
    }