From 8fc01feb902ae8a0d02d0b1137142f1877c02639 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 09:50:34 +0400 Subject: [PATCH 1/2] test cache affinity --- pool_dynamics_test.go | 46 ++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 8294112..16a29b7 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -221,7 +221,7 @@ func TestPoolAffinity(t *testing.T) { ctx := context.Background() cidList := generateRandomCIDs(20) - t.Run("selected nodes remain consistent for same cid reqs", func(t *testing.T) { + t.Run("select same nodes for same content", func(t *testing.T) { ch, controlGroup := getHarnessAndControlGroup(t, nodesSize, nodesSize/2) _, _ = ch.Caboose.Get(ctx, cidList[0]) @@ -257,46 +257,38 @@ func TestPoolAffinity(t *testing.T) { } ch.CaboosePool.DoRefresh() - // Introduce new nodes by sendng same stats to those nodes. - for i := 0; i < poolRefreshNo/2; i++ { + orig := make(map[string]string) + + for _, c := range cidList { + aff := ch.Caboose.GetAffinity(ctx) + if aff == "" { + aff = fmt.Sprintf(blockPathPattern, c) + } + nodes, _ := ch.CabooseActiveNodes.GetNodes(aff, ch.Config.MaxRetrievalAttempts) + orig[c.String()] = nodes[0].URL + } + + // change stats for control group nodes + for i := 0; i < poolRefreshNo; i++ { baseStats := util.NodeStats{ Start: time.Now().Add(-time.Second * 2), - Latency: float64(baseStatLatency) / float64(10), + Latency: float64(baseStatLatency) / float64(2), 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) - + ch.RecordSuccesses(t, goodNodes, baseStats, 1000) ch.CaboosePool.DoRefresh() } - // 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] + // same nodes get selected + 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]) + assert.EqualValues(t, orig[c.String()], nodes[0].URL) } - }) } From 3fa73c2d01aac23f9569c6eba44cef9196f656ff Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 19 Sep 2023 10:03:31 +0400 Subject: [PATCH 2/2] fix go check --- pool_dynamics_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pool_dynamics_test.go b/pool_dynamics_test.go index 16a29b7..c110ba8 100644 --- a/pool_dynamics_test.go +++ b/pool_dynamics_test.go @@ -207,9 +207,7 @@ func TestPoolDynamics(t *testing.T) { for n := range controlGroup { assert.Contains(t, ch.CabooseActiveNodes.Nodes, n) } - }) - } func TestPoolAffinity(t *testing.T) { @@ -226,14 +224,11 @@ func TestPoolAffinity(t *testing.T) { _, _ = ch.Caboose.Get(ctx, cidList[0]) goodNodes := make([]*caboose.Node, 0) - badNodes := make([]*caboose.Node, 0) for _, n := range ch.CabooseAllNodes.Nodes { _, ok := controlGroup[n.URL] if ok { goodNodes = append(goodNodes, n) - } else { - badNodes = append(badNodes, n) } }