Skip to content

Commit

Permalink
#46 Complete the schedule test
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Jan 14, 2024
1 parent 2e3ee63 commit 1659277
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion pkg/routers/routing/least_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func NewLeastLatencyRouting(models []providers.Model) *LeastLatencyRouting {
}

return &LeastLatencyRouting{
warmupIdx: atomic.Uint32{},
schedules: schedules,
}
}
Expand Down
28 changes: 19 additions & 9 deletions pkg/routers/routing/least_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,47 @@ func TestLeastLatencyRouting_Routing(t *testing.T) {
[]Model{
{"first", true, 100.0, time.Now().Add(30 * time.Second)},
{"second", true, 80.0, time.Now().Add(30 * time.Second)},
{"third", true, 101.0, time.Now().Add(-time.Duration(30) * time.Second)},
{"third", true, 101.0, time.Now().Add(-30 * time.Second)},
},
[]string{"third", "second", "second"},
},
"two expired models": {
[]Model{
{"first", true, 100.0, time.Now().Add(-time.Duration(60) * time.Second)},
{"first", true, 100.0, time.Now().Add(-60 * time.Second)},
{"second", true, 80.0, time.Now().Add(30 * time.Second)},
{"third", true, 101.0, time.Now().Add(-time.Duration(30) * time.Second)},
{"third", true, 101.0, time.Now().Add(-30 * time.Second)},
},
[]string{"first", "third", "second"},
},
"all expired models": {
[]Model{
{"first", true, 100.0, time.Now().Add(-time.Duration(30) * time.Second)},
{"second", true, 80.0, time.Now().Add(-time.Duration(20) * time.Second)},
{"third", true, 101.0, time.Now().Add(-time.Duration(60) * time.Second)},
{"first", true, 100.0, time.Now().Add(-30 * time.Second)},
{"second", true, 80.0, time.Now().Add(-20 * time.Second)},
{"third", true, 101.0, time.Now().Add(-60 * time.Second)},
},
[]string{"third", "first", "second"},
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
models := make([]providers.Model, 0, len(tc.models))
schedules := make([]*ModelSchedule, 0, len(tc.models))

for _, model := range tc.models {
models = append(models, providers.NewLangModelMock(model.modelID, model.healthy, model.latency))
schedules = append(schedules, &ModelSchedule{
model: providers.NewLangModelMock(
model.modelID,
model.healthy,
model.latency,
),
expireAt: model.expireAt,
})
}

routing := LeastLatencyRouting{
schedules: schedules,
}

routing := NewLeastLatencyRouting(models)
iterator := routing.Iterator()

// loop three times over the whole pool to check if we return back to the begging of the list
Expand Down

0 comments on commit 1659277

Please sign in to comment.