public static void GetEnumerator_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            IEnumerator <int> enumerator = operation.Item(DefaultStart, DefaultSize, source.Item).GetEnumerator();

            // Spin until concat hits
            // Union-Left needs to spin more than once rarely.
            if (operation.ToString().StartsWith("Concat") || operation.ToString().StartsWith("Union-Left:ParallelEnumerable"))
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => { while (enumerator.MoveNext())
                                                                       {
                                                                           ;
                                                                       }
                                                               });
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => enumerator.MoveNext());
            }

            if (operation.ToString().StartsWith("OrderBy") || operation.ToString().StartsWith("ThenBy"))
            {
                Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
            }
            else
            {
                Assert.False(enumerator.MoveNext());
            }
        }
Esempio n. 2
0
 public static void Average_Long_Overflow()
 {
     AssertThrows.Wrapped <OverflowException>(() => UnorderedSources.Default(2).Select(x => x == 0 ? 1 : long.MaxValue).Average());
     AssertThrows.Wrapped <OverflowException>(() => UnorderedSources.Default(2).Select(x => x == 0 ? (long?)1 : long.MaxValue).Average());
     AssertThrows.Wrapped <OverflowException>(() => UnorderedSources.Default(2).Average(x => x == 0 ? -1 : long.MinValue));
     AssertThrows.Wrapped <OverflowException>(() => UnorderedSources.Default(2).Average(x => x == 0 ? (long?)-1 : long.MinValue));
 }
        public static void First_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            if (operation.ToString().Contains("Concat-Left"))
            {
                // The vast majority of the time, the operation returns a result instead of failing.
                // Sufficient cores on a test machine may make the optimizer start enumerating the results.
                int?result    = null;
                var exception = Record.Exception(() => { result = operation.Item(DefaultStart, DefaultSize, source.Item).First(); });
                if (result.HasValue)
                {
                    Assert.Null(exception);
                    Assert.InRange(result.Value, DefaultStart, DefaultStart + DefaultSize);
                }
                else
                {
                    Assert.NotNull(exception);
                    var ae = Assert.IsType <AggregateException>(exception);
                    Assert.All(ae.InnerExceptions, e => Assert.IsType <DeliberateTestException>(e));
                }
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First());
            }

            AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First(x => false));
        }
Esempio n. 4
0
        public static void Zip_AsOrdered_ThreadedDeadlock(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int degree)
        {
            _ = leftCount;
            _ = rightCount;
            ParallelQuery <int> query = left.Item.WithDegreeOfParallelism(degree).Zip <int, int, int>(right.Item, (a, b) => { throw new DeliberateTestException(); });

            AssertThrows.Wrapped <DeliberateTestException>(() => query.ToArray());
        }
Esempio n. 5
0
        public static void SequenceEqual_DisposeException(Labeled <ParallelQuery <int> > left, Labeled <ParallelQuery <int> > right, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;

            AssertThrows.Wrapped <TestDisposeException>(() => leftQuery.SequenceEqual(new DisposeExceptionEnumerable <int>(rightQuery).AsParallel()));
            AssertThrows.Wrapped <TestDisposeException>(() => new DisposeExceptionEnumerable <int>(leftQuery).AsParallel().SequenceEqual(rightQuery));
        }
 public static void Aggregate_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate((x, y) => x));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y, r => r));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (a, x) => a + x, (l, r) => l + r, r => r));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(() => 0, (a, x) => a + x, (l, r) => l + r, r => r));
 }
Esempio n. 7
0
        public static void Max_AggregateException_NotComparable()
        {
            ArgumentException e = AssertThrows.Wrapped <ArgumentException>(() => ParallelEnumerable.Repeat(new NotComparable(0), 2).Max());

            Assert.Null(e.ParamName);

            e = AssertThrows.Wrapped <ArgumentException>(() => ParallelEnumerable.Range(0, 2).Max(x => new NotComparable(x)));
            Assert.Null(e.ParamName);
        }
Esempio n. 8
0
        public static void WithCancellation_ODEIssue(Labeled <ParallelQuery <int> > labeled, int count)
        {
            //the failure was an ODE coming out due to an ephemeral disposed merged cancellation token source.
            ParallelQuery <int> left  = labeled.Item.AsUnordered().WithExecutionMode(ParallelExecutionMode.ForceParallelism);
            ParallelQuery <int> right = Enumerable.Range(0, 1024).Select(x => x).AsParallel().AsUnordered();

            AssertThrows.Wrapped <OperationCanceledException>(() => left.GroupJoin(right, x => { throw new OperationCanceledException(); }, y => y, (x, e) => x).ForAll(x => { }));
            AssertThrows.Wrapped <OperationCanceledException>(() => left.Join(right, x => { throw new OperationCanceledException(); }, y => y, (x, e) => x).ForAll(x => { }));
            AssertThrows.Wrapped <OperationCanceledException>(() => left.Zip <int, int, int>(right, (x, y) => { throw new OperationCanceledException(); }).ForAll(x => { }));
        }
Esempio n. 9
0
 public static void Sum_Long_Overflow()
 {
     AssertThrows.Wrapped <OverflowException>(() => new[] { long.MaxValue, 1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (long?)long.MaxValue, 1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { long.MinValue, -1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (long?)long.MinValue, -1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? long.MaxValue : x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? long.MaxValue : (long?)x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? long.MinValue : -x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? long.MinValue : -(long?)x));
 }
Esempio n. 10
0
 public static void Sum_Decimal_Overflow()
 {
     AssertThrows.Wrapped <OverflowException>(() => new[] { decimal.MaxValue, 1M }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (decimal?)decimal.MaxValue, 1M }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { decimal.MinValue, -1M }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (decimal?)decimal.MinValue, -1M }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? decimal.MaxValue : x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? decimal.MaxValue : (decimal?)x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? decimal.MinValue : -x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? decimal.MinValue : -(decimal?)x));
 }
Esempio n. 11
0
 public static void Sum_Int_Overflow()
 {
     AssertThrows.Wrapped <OverflowException>(() => new[] { int.MaxValue, 1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (int?)int.MaxValue, 1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { int.MinValue, -1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => new[] { (int?)int.MinValue, -1 }.AsParallel().Sum());
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? int.MaxValue : x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? int.MaxValue : (int?)x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? int.MinValue : -x));
     AssertThrows.Wrapped <OverflowException>(() => ParallelEnumerable.Range(0, 2).Sum(x => x == 0 ? int.MinValue : -(int?)x));
 }
Esempio n. 12
0
        public static void GetEnumerator_MoveNextAfterQueryOpeningFailsIsIllegal(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item.Select <int, int>(x => { throw new DeliberateTestException(); }).OrderBy(x => x);

            IEnumerator <int> enumerator = query.GetEnumerator();

            //moveNext will cause queryOpening to fail (no element generated)
            AssertThrows.Wrapped <DeliberateTestException>(() => enumerator.MoveNext());

            //moveNext after queryOpening failed
            Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
        }
Esempio n. 13
0
        public static void ToLookup_AggregateException(Labeled <ParallelQuery <int> > labeled, int count)
        {
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup((Func <int, int>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup((Func <int, int>)(x => { throw new DeliberateTestException(); }), y => y));
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup(x => x, (Func <int, int>)(y => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup((Func <int, int>)(x => { throw new DeliberateTestException(); }), EqualityComparer <int> .Default));
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup((Func <int, int>)(x => { throw new DeliberateTestException(); }), y => y, EqualityComparer <int> .Default));
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup(x => x, (Func <int, int>)(y => { throw new DeliberateTestException(); }), EqualityComparer <int> .Default));

            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup(x => x, new FailingEqualityComparer <int>()));
            AssertThrows.Wrapped <DeliberateTestException>(() => labeled.Item.ToLookup(x => x, y => y, new FailingEqualityComparer <int>()));
        }
        public static void First_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            // Concat seems able to return the first element when the left query does not fail ("first" query).
            // This test might be flaky in the case that it decides to run the right query too...
            if (operation.ToString().Contains("Concat-Left"))
            {
                Assert.InRange(operation.Item(DefaultStart, DefaultSize, source.Item).First(), DefaultStart, DefaultStart + DefaultSize);
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First());
            }

            AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First(x => false));
        }
Esempio n. 15
0
        public static void Sum_AggregateException()
        {
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, int>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, int?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, long>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, long?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, float>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, float?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, double>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, double?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, decimal>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 2).Sum((Func <int, decimal?>)(x => { throw new DeliberateTestException(); })));
        }
Esempio n. 16
0
 public static void Aggregate_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate((i, j) => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(0, (i, j) => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(0, (i, j) => { throw new DeliberateTestException(); }, i => i));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate <int, int, int>(0, (i, j) => i, i => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(0, (i, j) => { throw new DeliberateTestException(); }, (i, j) => i, i => i));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate <int, int, int>(0, (i, j) => i, (i, j) => i, i => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate <int, int, int>(() => { throw new DeliberateTestException(); }, (i, j) => i, (i, j) => i, i => i));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(() => 0, (i, j) => { throw new DeliberateTestException(); }, (i, j) => i, i => i));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate <int, int, int>(() => 0, (i, j) => i, (i, j) => i, i => { throw new DeliberateTestException(); }));
     if (Environment.ProcessorCount >= 2)
     {
         AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(0, (i, j) => i, (i, j) => { throw new DeliberateTestException(); }, i => i));
         AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(2).Aggregate(() => 0, (i, j) => i, (i, j) => { throw new DeliberateTestException(); }, i => i));
     }
 }
Esempio n. 17
0
        public static void Average_AggregateException()
        {
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, int>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, int?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, long>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, long?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, float>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, float?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, double>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, double?>)(x => { throw new DeliberateTestException(); })));

            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, decimal>)(x => { throw new DeliberateTestException(); })));
            AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Average((Func <int, decimal?>)(x => { throw new DeliberateTestException(); })));
        }
Esempio n. 18
0
 public static void ToDictionary_ElementSelector_UniqueKeys_CustomComparator(int count)
 {
     if (count > 2)
     {
         AssertThrows.Wrapped <ArgumentException>(() => UnorderedSources.Default(count).ToDictionary(x => x, y => y, new ModularCongruenceComparer(2)));
     }
     else if (count == 1 || count == 2)
     {
         IntegerRangeSet seen = new IntegerRangeSet(0, count);
         foreach (KeyValuePair <int, int> entry in UnorderedSources.Default(count).ToDictionary(x => x, y => y, new ModularCongruenceComparer(2)))
         {
             seen.Add(entry.Key);
             Assert.Equal(entry.Key, entry.Value);
         }
         seen.AssertComplete();
     }
     else
     {
         Assert.Empty(UnorderedSources.Default(count).ToDictionary(x => x, y => y, new ModularCongruenceComparer(2)));
     }
 }
Esempio n. 19
0
 public static void Cast_Unordered_Assignable_InvalidCastException(int count)
 {
     AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Select(x => (Int32)x).Cast <Castable>().ForAll(x => {; }));
     AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Select(x => (Int32)x).Cast <Castable>().ToList());
 }
Esempio n. 20
0
 public static void Any_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Any(x => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Select((Func <int, int>)(x => { throw new DeliberateTestException(); })).Any());
 }
Esempio n. 21
0
 public static void All_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).All(x => { throw new DeliberateTestException(); }));
 }
Esempio n. 22
0
 public static void Cast_InvalidCastException(Labeled <ParallelQuery <int> > labeled, int count)
 {
     AssertThrows.Wrapped <InvalidCastException>(() => labeled.Item.Cast <double>().ForAll(x => {; }));
     AssertThrows.Wrapped <InvalidCastException>(() => labeled.Item.Cast <double>().ToList());
 }
Esempio n. 23
0
 public static void SequenceEqual_AggregateException(Labeled <ParallelQuery <int> > left, Labeled <ParallelQuery <int> > right, int count)
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => left.Item.SequenceEqual(right.Item, new FailingEqualityComparer <int>()));
 }
Esempio n. 24
0
 public static void CountLongCount_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).Count(x => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).LongCount(x => { throw new DeliberateTestException(); }));
 }
Esempio n. 25
0
 public static void ForAll_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).ForAll(x => { throw new DeliberateTestException(); }));
     AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).Select((Func <int, int>)(x => { throw new DeliberateTestException(); })).ForAll(x => { }));
 }
Esempio n. 26
0
 public static void ToDictionary_DuplicateKeys_ElementSelector()
 {
     AssertThrows.Wrapped <ArgumentException>(() => ParallelEnumerable.Repeat(0, 2).ToDictionary(x => x, y => y));
 }
Esempio n. 27
0
 public static void Cast_Unordered_InvalidCastException(int count)
 {
     AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Cast <double>().ForAll(x => {; }));
     AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Cast <double>().ToList());
 }
Esempio n. 28
0
 public static void ToDictionary_DuplicateKeys_ElementSelector_CustomComparator()
 {
     AssertThrows.Wrapped <ArgumentException>(() => ParallelEnumerable.Repeat(0, 2).ToDictionary(x => x, y => y, new ModularCongruenceComparer(2)));
 }
Esempio n. 29
0
 public static void Contains_AggregateException()
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).Contains(1, new FailingEqualityComparer <int>()));
 }
Esempio n. 30
0
 public static void Cast_Assignable_InvalidCastException(Labeled <ParallelQuery <int> > labeled, int count)
 {
     _ = count;
     AssertThrows.Wrapped <InvalidCastException>(() => labeled.Item.Select(x => (Int32)x).Cast <Castable>().ForAll(x => {; }));
     AssertThrows.Wrapped <InvalidCastException>(() => labeled.Item.Select(x => (Int32)x).Cast <Castable>().ToList());
 }