Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
test cache affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Sep 19, 2023
1 parent 1975f49 commit 8fc01fe
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions pool_dynamics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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)
}

})
}

Expand Down

0 comments on commit 8fc01fe

Please sign in to comment.