Skip to content

Commit

Permalink
Fix to #8617 - Query/Test: introduce client-side ordering to QueryTes…
Browse files Browse the repository at this point in the history
…ts without explicit orderby, rather than using contains in the result verification

This PR includes:
- applying client side ordering to QueryTests (rather than doing O(n^2) result comparisons for queries without order by,
- adding entry count verification (we had it in some places and not in others),
- DRYing some of the commonly used asserters

As a result, time to run those tests is cut down in half (40s to 20s). For now the helper methods are duplicated with the ones used in complex navs - will unify them in next checkin.
  • Loading branch information
maumar committed Jun 27, 2017
1 parent e6cd7e6 commit 455e206
Show file tree
Hide file tree
Showing 7 changed files with 1,644 additions and 1,341 deletions.
54 changes: 20 additions & 34 deletions src/EFCore.Specification.Tests/Query/QueryTestBase.Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public virtual void String_Compare_simple_one()
entryCount: 90);

AssertQuery<Customer>(
cs => cs.Where(c => -1 == string.Compare(c.CustomerID, "ALFKI")),
entryCount: 0);
cs => cs.Where(c => -1 == string.Compare(c.CustomerID, "ALFKI")));

AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI") < 1),
Expand Down Expand Up @@ -192,8 +191,7 @@ public virtual void String_compare_with_parameter()
entryCount: 90);

AssertQuery<Customer>(
cs => cs.Where(c => -1 == string.Compare(c.CustomerID, customer.CustomerID)),
entryCount: 0);
cs => cs.Where(c => -1 == string.Compare(c.CustomerID, customer.CustomerID)));

AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, customer.CustomerID) < 1),
Expand All @@ -216,12 +214,10 @@ public virtual void String_compare_with_parameter()
public virtual void String_Compare_simple_client()
{
AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI") == 42),
entryCount: 0);
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI") == 42));

AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI") > 42),
entryCount: 0);
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI") > 42));

AssertQuery<Customer>(
cs => cs.Where(c => 42 > string.Compare(c.CustomerID, "ALFKI")),
Expand All @@ -232,24 +228,20 @@ public virtual void String_Compare_simple_client()
public virtual void String_Compare_nested()
{
AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "M" + c.CustomerID) == 0),
entryCount: 0);
cs => cs.Where(c => string.Compare(c.CustomerID, "M" + c.CustomerID) == 0));

AssertQuery<Customer>(
cs => cs.Where(c => 0 != string.Compare(c.CustomerID, c.CustomerID.ToUpper())),
entryCount: 0);
cs => cs.Where(c => 0 != string.Compare(c.CustomerID, c.CustomerID.ToUpper())));

AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) > 0),
entryCount: 0);
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) > 0));

AssertQuery<Customer>(
cs => cs.Where(c => 0 >= string.Compare(c.CustomerID, "M" + c.CustomerID)),
entryCount: 51);

AssertQuery<Customer>(
cs => cs.Where(c => 1 == string.Compare(c.CustomerID, c.CustomerID.ToUpper())),
entryCount: 0);
cs => cs.Where(c => 1 == string.Compare(c.CustomerID, c.CustomerID.ToUpper())));

AssertQuery<Customer>(
cs => cs.Where(c => string.Compare(c.CustomerID, "ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) == -1),
Expand Down Expand Up @@ -304,8 +296,7 @@ public virtual void String_Compare_to_simple_one()
entryCount: 90);

AssertQuery<Customer>(
cs => cs.Where(c => -1 == c.CustomerID.CompareTo("ALFKI")),
entryCount: 0);
cs => cs.Where(c => -1 == c.CustomerID.CompareTo("ALFKI")));

AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI") < 1),
Expand Down Expand Up @@ -340,8 +331,7 @@ public virtual void String_compare_to_with_parameter()
entryCount: 90);

AssertQuery<Customer>(
cs => cs.Where(c => -1 == c.CustomerID.CompareTo(customer.CustomerID)),
entryCount: 0);
cs => cs.Where(c => -1 == c.CustomerID.CompareTo(customer.CustomerID)));

AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo(customer.CustomerID) < 1),
Expand All @@ -364,12 +354,10 @@ public virtual void String_compare_to_with_parameter()
public virtual void String_Compare_to_simple_client()
{
AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI") == 42),
entryCount: 0);
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI") == 42));

AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI") > 42),
entryCount: 0);
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI") > 42));

AssertQuery<Customer>(
cs => cs.Where(c => 42 > c.CustomerID.CompareTo("ALFKI")),
Expand All @@ -380,24 +368,20 @@ public virtual void String_Compare_to_simple_client()
public virtual void String_Compare_to_nested()
{
AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("M" + c.CustomerID) == 0),
entryCount: 0);
cs => cs.Where(c => c.CustomerID.CompareTo("M" + c.CustomerID) == 0));

AssertQuery<Customer>(
cs => cs.Where(c => 0 != c.CustomerID.CompareTo(c.CustomerID.ToUpper())),
entryCount: 0);
cs => cs.Where(c => 0 != c.CustomerID.CompareTo(c.CustomerID.ToUpper())));

AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) > 0),
entryCount: 0);
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) > 0));

AssertQuery<Customer>(
cs => cs.Where(c => 0 >= c.CustomerID.CompareTo("M" + c.CustomerID)),
entryCount: 51);

AssertQuery<Customer>(
cs => cs.Where(c => 1 == c.CustomerID.CompareTo(c.CustomerID.ToUpper())),
entryCount: 0);
cs => cs.Where(c => 1 == c.CustomerID.CompareTo(c.CustomerID.ToUpper())));

AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.CompareTo("ALFKI".Replace("ALF".ToUpper(), c.CustomerID)) == -1),
Expand Down Expand Up @@ -502,14 +486,16 @@ public virtual void Where_math_round()
public virtual void Select_math_round_int()
{
AssertQuery<Order>(
os => os.Where(o => o.OrderID < 10250).Select(o => new { A = Math.Round((double)o.OrderID) }));
os => os.Where(o => o.OrderID < 10250).Select(o => new { A = Math.Round((double)o.OrderID) }),
e => e.A);
}

[ConditionalFact]
public virtual void Select_math_truncate_int()
{
AssertQuery<Order>(
os => os.Where(o => o.OrderID < 10250).Select(o => new { A = Math.Truncate((double)o.OrderID) }));
os => os.Where(o => o.OrderID < 10250).Select(o => new { A = Math.Truncate((double)o.OrderID) }),
e => e.A);
}

[ConditionalFact]
Expand Down
Loading

0 comments on commit 455e206

Please sign in to comment.