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

Commit

Permalink
Merge pull request #163 from filecoin-saturn/feat/cache-aff-test
Browse files Browse the repository at this point in the history
Test cache affinity
  • Loading branch information
aarshkshah1992 authored Sep 19, 2023
2 parents 1975f49 + 0cf6c94 commit 552ea1b
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions pool_dynamics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,20 @@ 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 have been added later.
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)
}
}

Expand All @@ -245,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()
}

Expand All @@ -265,38 +267,32 @@ 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)
ch.RecordSuccesses(t, existingNodes, baseStats, 100)
ch.RecordSuccesses(t, newNodes, baseStats, 10)

ch.CaboosePool.DoRefresh()
}

// for _, i := range ch.CabooseAllNodes.Nodes {
// fmt.Println(i.URL, i.Priority(), i.PredictedLatency)
// }
rerouteCount := 0

// 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 if it's been rerouted to a new node.
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 newNodes {
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, 5)
})
}

Expand Down

0 comments on commit 552ea1b

Please sign in to comment.