-
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 the priority routing by tests & fixed issues in logic and…
… related tests
- Loading branch information
1 parent
9ebd281
commit d55634b
Showing
4 changed files
with
79 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package routing | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"glide/pkg/providers" | ||
) | ||
|
||
func TestPriorityRouting_PickModelsInOrder(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", "first", "first"}}, | ||
"first unhealthy": {[]Model{{"first", false}, {"second", true}, {"third", true}}, []string{"second", "second", "second"}}, | ||
"first two unhealthy": {[]Model{{"first", false}, {"second", false}, {"third", true}}, []string{"third", "third", "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 := NewPriorityRouting(models) | ||
iterator := routing.Iterator() | ||
|
||
// 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 TestPriorityRouting_NoHealthyModels(t *testing.T) { | ||
models := []providers.Model{ | ||
providers.NewLangModelMock("first", false), | ||
providers.NewLangModelMock("second", false), | ||
providers.NewLangModelMock("third", false), | ||
} | ||
|
||
routing := NewPriorityRouting(models) | ||
iterator := routing.Iterator() | ||
|
||
_, err := iterator.Next() | ||
require.Error(t, err) | ||
} |