Skip to content

Commit

Permalink
use traits.encode for expected priorities in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Jul 13, 2023
1 parent 3024155 commit 7709eaa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
5 changes: 3 additions & 2 deletions internal/dataplane/parser/translators/httproute_atc.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,10 @@ func AssignRoutePriorityToSplitHTTPRoutes(
Priority: priority + relativeOrderBits,
})
}
// log the
// Just in case, log a very unlikely scenario where we have more than 2^18 routes with the same base
// priority and we have no bit space for them to be deterministically ordered.
if len(routes) > (1 << 18) {
logger.Info("Too many HTTPRoutes are distinguished by relative orders", "httproute_number", len(routes))
logger.V(util.WarnLevel).Info("Too many HTTPRoutes to be deterministically ordered", "httproute_number", len(routes))
}
}

Expand Down
65 changes: 56 additions & 9 deletions internal/dataplane/parser/translators/httproute_atc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
matchIndex int
}
now := time.Now()
const maxRelativeOrderPriorityBits = (1 << 18) - 1

testCases := []struct {
name string
splitHTTPRoutes []*gatewayv1beta1.HTTPRoute
Expand Down Expand Up @@ -890,14 +892,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("foo.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
{
namespace: "default",
name: "httproute-2",
hostname: "*.bar.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (9 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: false,
HostnameLength: len("*.bar.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/bar"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
},
},
{
Expand Down Expand Up @@ -953,14 +965,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("foo.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
{
namespace: "default",
name: "httproute-2",
hostname: "bar.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("bar.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
},
},
{
Expand Down Expand Up @@ -1016,14 +1038,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("foo.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
{
namespace: "default",
name: "httproute-2",
hostname: "bar.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("bar.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
},
},
{
Expand Down Expand Up @@ -1079,14 +1111,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("foo.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
{
namespace: "default",
name: "httproute-1",
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 1,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("bar.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
},
},
{
Expand Down Expand Up @@ -1158,7 +1200,12 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
hostname: "foo.com",
ruleIndex: 0,
matchIndex: 0,
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
}: HTTPRoutePriorityTraits{
PreciseHostname: true,
HostnameLength: len("foo.com"),
PathType: gatewayv1beta1.PathMatchExact,
PathLength: len("/foo"),
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
},
},
}
Expand Down

0 comments on commit 7709eaa

Please sign in to comment.