Added a new sorter test case, `HierarchicalIterationOrder`. This behavior is covered by existing test cases to an extent, but some additional test coverage seems warranted.
Review: https://reviews.apache.org/r/59482/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/89e7bf54 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/89e7bf54 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/89e7bf54 Branch: refs/heads/master Commit: 89e7bf548c87c53a3e49fb6d930ed0d49d08affc Parents: 7533901 Author: Neil Conway <neil.con...@gmail.com> Authored: Tue May 23 10:36:13 2017 -0700 Committer: Neil Conway <neil.con...@gmail.com> Committed: Wed May 24 14:40:08 2017 -0700 ---------------------------------------------------------------------- src/tests/sorter_tests.cpp | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/89e7bf54/src/tests/sorter_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp index ed66b9a..6ca724d 100644 --- a/src/tests/sorter_tests.cpp +++ b/src/tests/sorter_tests.cpp @@ -605,6 +605,54 @@ TEST(SorterTest, HierarchicalAllocation) } +// This test checks that the sorted list of clients returned by the +// sorter iterates over the client tree in the correct order. +TEST(SorterTest, HierarchicalIterationOrder) +{ + DRFSorter sorter; + + SlaveID slaveId; + slaveId.set_value("agentId"); + + Resources totalResources = Resources::parse("cpus:100;mem:100").get(); + sorter.add(slaveId, totalResources); + + sorter.add("a/b"); + sorter.add("c"); + sorter.add("d"); + sorter.add("d/e"); + + sorter.activate("a/b"); + sorter.activate("c"); + sorter.activate("d"); + sorter.activate("d/e"); + + // Shares: a/b = 0, c = 0, d = 0, d/e = 0 + EXPECT_EQ(vector<string>({"a/b", "c", "d", "d/e"}), sorter.sort()); + + Resources cResources = Resources::parse("cpus:8;mem:8").get(); + sorter.allocated("c", slaveId, cResources); + + // Shares: a/b = 0, d = 0, d/e = 0, c = 0.08. + EXPECT_EQ(vector<string>({"a/b", "d", "d/e", "c"}), sorter.sort()); + + Resources dResources = Resources::parse("cpus:3;mem:3").get(); + sorter.allocated("d", slaveId, dResources); + + Resources deResources = Resources::parse("cpus:2;mem:2").get(); + sorter.allocated("d/e", slaveId, deResources); + + // Shares: a/b = 0, d/e = 0.02, d = 0.03, c = 0.08. + EXPECT_EQ(vector<string>({"a/b", "d/e", "d", "c"}), sorter.sort()); + + Resources abResources = Resources::parse("cpus:6;mem:6").get(); + sorter.allocated("a/b", slaveId, abResources); + + // Shares: d/e = 0.02, d = 0.03, a/b = 0.06, c = 0.08. + EXPECT_EQ(vector<string>({"d/e", "d", "a/b", "c"}), sorter.sort()); +} + + // This test checks what happens when a new sorter client is added as // a child of what was previously a leaf node. TEST(SorterTest, AddChildToLeaf)