-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44 Covered RR routing by tests & init routing based on config value …
…& created interfaces for Model & LanguageModels
- Loading branch information
1 parent
5136e35
commit 00499bf
Showing
9 changed files
with
169 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package routing | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"glide/pkg/providers" | ||
) | ||
|
||
func TestRoundRobinRouting_PickModelsSequentially(t *testing.T) { | ||
type Model struct { | ||
modelID string | ||
healthy bool | ||
} | ||
|
||
type TestCase struct { | ||
models []Model | ||
expectedModelIDs []string | ||
} | ||
|
||
tests := map[string]TestCase{ | ||
"all healthy": {[]Model{{"first", true}, {"second", true}, {"third", true}}, []string{"first", "second", "third"}}, | ||
"unhealthy in the middle": {[]Model{{"first", true}, {"second", false}, {"third", true}}, []string{"first", "third"}}, | ||
"two unhealthy": {[]Model{{"first", true}, {"second", false}, {"third", false}}, []string{"first"}}, | ||
"first unhealthy": {[]Model{{"first", false}, {"second", true}, {"third", true}}, []string{"second", "third"}}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
models := make([]providers.Model, 0, len(tc.models)) | ||
|
||
for _, model := range tc.models { | ||
models = append(models, providers.NewLangModelMock(model.modelID, model.healthy)) | ||
} | ||
|
||
routing := NewRoundRobinRouting(models) | ||
iterator := routing.Iterator() | ||
|
||
for i := 0; i < 3; i++ { | ||
// loop three times over the whole pool to check if we return back to the begging of the list | ||
for _, modelID := range tc.expectedModelIDs { | ||
model, err := iterator.Next() | ||
require.NoError(t, err) | ||
require.Equal(t, modelID, model.ID()) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestRoundRobinRouting_NoHealthyModels(t *testing.T) { | ||
models := []providers.Model{ | ||
providers.NewLangModelMock("first", false), | ||
providers.NewLangModelMock("second", false), | ||
providers.NewLangModelMock("third", false), | ||
} | ||
|
||
routing := NewRoundRobinRouting(models) | ||
iterator := routing.Iterator() | ||
|
||
_, err := iterator.Next() | ||
require.Error(t, err) | ||
} |
Oops, something went wrong.