Fix evaluator not running in mmf matchid collision test
@@ -77,9 +77,9 @@ func TestHappyPath(t *testing.T) {
}
// TestMatchFunctionMatchCollision covers two matches with the same id coming
-// from the same MMF generates an error to the fetch matches call.
+// from the same MMF generates an error to the fetch matches call. Also ensures
+// another function running in the same cycle does not experience an error.
func TestMatchFunctionMatchCollision(t *testing.T) {
- // TODO: another MMF in same cycle doesn't get error?
ctx := context.Background()
om := newOM(t)
@@ -89,7 +89,16 @@ func TestMatchFunctionMatchCollision(t *testing.T) {
t2, err := om.Frontend().CreateTicket(ctx, &pb.CreateTicketRequest{Ticket: &pb.Ticket{}})
require.Nil(t, err)
+ // Both mmf runs wait for the other to start before sending results, to
+ // ensure they run in the same cycle.
+ errorMMFStarted := make(chan struct{})
+ successMMFStarted := make(chan struct{})
+
om.SetMMF(func(ctx context.Context, profile *pb.MatchProfile, out chan<- *pb.Match) error {
+ switch profile.Name {
+ case "error":
+ close(errorMMFStarted)
+ <-successMMFStarted
out <- &pb.Match{
MatchId: "1",
Tickets: []*pb.Ticket{t1},
@@ -98,24 +107,59 @@ func TestMatchFunctionMatchCollision(t *testing.T) {
MatchId: "1",
Tickets: []*pb.Ticket{t2},
}
+ case "success":
+ close(successMMFStarted)
+ <-errorMMFStarted
+ out <- &pb.Match{
+ MatchId: "3",
+ Tickets: []*pb.Ticket{t2},
+ }
+ default:
+ panic("Unknown profile!")
+ }
return nil
})
om.SetEvaluator(func(ctx context.Context, in <-chan *pb.Match, out chan<- string) error {
- for range in {
+ for m := range in {
+ if m.MatchId == "3" {
+ out <- "3"
+ }
}
return nil
})
- stream, err := om.Backend().FetchMatches(ctx, &pb.FetchMatchesRequest{
+ startTime := time.Now()
+
+ sError, err := om.Backend().FetchMatches(ctx, &pb.FetchMatchesRequest{
Config: om.MMFConfigGRPC(),
- Profile: &pb.MatchProfile{},
+ Profile: &pb.MatchProfile{
+ Name: "error",
+ },
})
require.Nil(t, err)
- resp, err := stream.Recv()
+ sSuccess, err := om.Backend().FetchMatches(ctx, &pb.FetchMatchesRequest{
+ Config: om.MMFConfigGRPC(),
+ Profile: &pb.MatchProfile{
+ Name: "success",
+ },
+ })
+ require.Nil(t, err)
+
+ resp, err := sError.Recv()
require.Contains(t, err.Error(), "MatchMakingFunction returned same match_id twice: \"1\"")
require.Nil(t, resp)
+
+ resp, err = sSuccess.Recv()
+ require.Nil(t, err)
+ require.True(t, proto.Equal(t2, resp.Match.Tickets[0]))
+
+ require.True(t, time.Since(startTime) < registrationIntervalMs, "%s", time.Since(startTime))
+
+ resp, err = sSuccess.Recv()
+ require.Equal(t, err, io.EOF)
+ require.Nil(t, resp)
}
// TestSynchronizerMatchCollision covers two different MMFs generating matches
