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

Test cache affinity #162

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 19 additions & 32 deletions pool_dynamics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -221,19 +219,16 @@ 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])

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)
}
}

Expand All @@ -257,46 +252,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)
}
Comment on lines +258 to +261
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should only be doing one of these, so shouldn't need this complexity?

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