From 78f3490c747dd58b7c5f1189a98ffdee43edf67f Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 14:39:10 +0400 Subject: [PATCH 1/5] test cache affinity --- pool_dynamics_test.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 8294112..79de9f3 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -222,7 +222,9 @@ func TestPoolAffinity(t *testing.T) { cidList := generateRandomCIDs(20) t.Run("selected nodes remain consistent for same cid reqs", func(t *testing.T) { - ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) + // 80 nodes will be in the good pool. 20 will be added later with the same stats + // so 20% of the nodes in the pool will eventually be "new nodes" that will be added later. + ch, controlGroup := getHarnessAndControlGroup(t, 100, 80) _, _ = ch.Caboose.Get(ctx, cidList[0]) goodNodes := make([]*caboose.Node, 0) @@ -277,26 +279,31 @@ func TestPoolAffinity(t *testing.T) { ch.CaboosePool.DoRefresh() } + rerouteCount := 0 + // for _, i := range ch.CabooseAllNodes.Nodes { // fmt.Println(i.URL, i.Priority(), i.PredictedLatency) // } - // Get the candidate nodes for a few cids from our formed cid list using - // the affinity of each cid. - for i := 0; i < 10; i++ { - rand.New(rand.NewSource(time.Now().Unix())) - idx := rand.Intn(len(cidList)) - c := cidList[idx] + // Get the candidate nodes for each cid in the cid list to see + for _, c := range cidList { aff := ch.Caboose.GetAffinity(ctx) if aff == "" { aff = fmt.Sprintf(blockPathPattern, c) } nodes, _ := ch.CabooseActiveNodes.GetNodes(aff, ch.Config.MaxRetrievalAttempts) - // We expect that the candidate nodes are part of the "good nodes" list. assert.Contains(t, goodNodes, nodes[0]) + for _, n := range badNodes { + n := n + if n.URL == nodes[0].URL { + rerouteCount++ + } + } } + // no more than 5 cids from the cid list of 20 should get re-routed (25%) + assert.LessOrEqual(t, rerouteCount, 4) }) } From 5e02c7fd640c248e93169469e9c3fbd37ba3cdca Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 14:42:05 +0400 Subject: [PATCH 2/5] test cache affinity --- pool_dynamics_test.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 79de9f3..8d5f21c 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -222,8 +222,8 @@ func TestPoolAffinity(t *testing.T) { cidList := generateRandomCIDs(20) t.Run("selected nodes remain consistent for same cid reqs", func(t *testing.T) { - // 80 nodes will be in the good pool. 20 will be added later with the same stats - // so 20% of the nodes in the pool will eventually be "new nodes" that will be added later. + // 80 nodes will be in the good pool. 20 will be added later with the same stats. + // So, 20% of the nodes in the pool will eventually be "new nodes" that have been added later. ch, controlGroup := getHarnessAndControlGroup(t, 100, 80) _, _ = ch.Caboose.Get(ctx, cidList[0]) @@ -267,12 +267,6 @@ func TestPoolAffinity(t *testing.T) { Size: float64(baseStatSize) * float64(10), } - // variedStats := util.NodeStats{ - // Start: time.Now().Add(-time.Second * 2), - // Latency: float64(baseStatLatency) / (float64(10) + (1 + statVarianceFactor)), - // Size: float64(baseStatSize) * float64(10) * (1 + statVarianceFactor), - // } - ch.RecordSuccesses(t, goodNodes, baseStats, 100) ch.RecordSuccesses(t, badNodes, baseStats, 10) @@ -281,11 +275,7 @@ func TestPoolAffinity(t *testing.T) { rerouteCount := 0 - // for _, i := range ch.CabooseAllNodes.Nodes { - // fmt.Println(i.URL, i.Priority(), i.PredictedLatency) - // } - - // Get the candidate nodes for each cid in the cid list to see + // Get the candidate nodes for each cid in the cid list to see if it's been rerouted to a new node. for _, c := range cidList { aff := ch.Caboose.GetAffinity(ctx) if aff == "" { From d8ae01e1b773e271e42ba072685ad73a381be21c Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 14:50:11 +0400 Subject: [PATCH 3/5] remove assert --- pool_dynamics_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 8d5f21c..2c53218 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -283,7 +283,6 @@ func TestPoolAffinity(t *testing.T) { } nodes, _ := ch.CabooseActiveNodes.GetNodes(aff, ch.Config.MaxRetrievalAttempts) - assert.Contains(t, goodNodes, nodes[0]) for _, n := range badNodes { n := n if n.URL == nodes[0].URL { From b647fab2f03a99f100cded188af0b4adfd4a6727 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 16:21:01 +0400 Subject: [PATCH 4/5] fix test --- pool_dynamics_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 2c53218..ddd0806 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -292,7 +292,7 @@ func TestPoolAffinity(t *testing.T) { } // no more than 5 cids from the cid list of 20 should get re-routed (25%) - assert.LessOrEqual(t, rerouteCount, 4) + assert.LessOrEqual(t, rerouteCount, 5) }) } From 0cf6c943f8c9e94d8ce308340777afb1cfa8d368 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 16:22:24 +0400 Subject: [PATCH 5/5] address review --- pool_dynamics_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index ddd0806..dc2d4a9 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -227,15 +227,15 @@ func TestPoolAffinity(t *testing.T) { ch, controlGroup := getHarnessAndControlGroup(t, 100, 80) _, _ = ch.Caboose.Get(ctx, cidList[0]) - goodNodes := make([]*caboose.Node, 0) - badNodes := make([]*caboose.Node, 0) + existingNodes := make([]*caboose.Node, 0) + newNodes := make([]*caboose.Node, 0) for _, n := range ch.CabooseAllNodes.Nodes { _, ok := controlGroup[n.URL] if ok { - goodNodes = append(goodNodes, n) + existingNodes = append(existingNodes, n) } else { - badNodes = append(badNodes, n) + newNodes = append(newNodes, n) } } @@ -247,7 +247,7 @@ func TestPoolAffinity(t *testing.T) { Size: float64(baseStatSize) * float64(10), } - ch.RecordSuccesses(t, goodNodes, baseStats, 1000) + ch.RecordSuccesses(t, existingNodes, baseStats, 1000) ch.CaboosePool.DoRefresh() } @@ -267,8 +267,8 @@ func TestPoolAffinity(t *testing.T) { Size: float64(baseStatSize) * float64(10), } - ch.RecordSuccesses(t, goodNodes, baseStats, 100) - ch.RecordSuccesses(t, badNodes, baseStats, 10) + ch.RecordSuccesses(t, existingNodes, baseStats, 100) + ch.RecordSuccesses(t, newNodes, baseStats, 10) ch.CaboosePool.DoRefresh() } @@ -283,7 +283,7 @@ func TestPoolAffinity(t *testing.T) { } nodes, _ := ch.CabooseActiveNodes.GetNodes(aff, ch.Config.MaxRetrievalAttempts) - for _, n := range badNodes { + for _, n := range newNodes { n := n if n.URL == nodes[0].URL { rerouteCount++