-
Notifications
You must be signed in to change notification settings - Fork 3
/
backfill_test.go
104 lines (84 loc) · 3.59 KB
/
backfill_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package tests
import (
"context"
"testing"
"time"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/stretchr/testify/assert"
"open-match.dev/open-match/pkg/pb"
)
func TestCreateTicketWithBackfill(t *testing.T) {
ctx := context.Background()
frontend := newOMFrontendClient(t)
backend := newOMBackendClient(t)
profile := &pb.MatchProfile{Name: "test-profile", Pools: []*pb.Pool{
{Name: "test-pool", CreatedAfter: timestamppb.New(time.Now())},
}}
var allocatedGameServer *GameServer
var assignment *pb.Assignment
var currentBackfill *pb.Backfill
ticket1 := mustCreateTicket(t, frontend, &pb.Ticket{})
{
matches := fetchMatches(t, backend, profile)
assert.Len(t, matches, 1)
assert.Equal(t, true, matches[0].AllocateGameserver)
assert.Len(t, matches[0].Tickets, 1)
assert.Equal(t, ticket1.Id, matches[0].Tickets[0].Id)
assert.NotNil(t, matches[0].Backfill)
openSlots, err := getOpenSlots(matches[0].Backfill)
assert.NoError(t, err)
assert.Equal(t, int32(playersPerMatch), openSlots)
currentBackfill = matches[0].Backfill
allocatedGameServer = AllocateGameServer("test-gs", frontend)
mustAssignTickets(t, backend, matches[0], allocatedGameServer.ConnectionName())
assignment = mustAssignment(t, frontend, ticket1.Id, 3*time.Second)
allocatedGameServer.StartBackfillCreated(currentBackfill, assignment)
assert.NoError(t, allocatedGameServer.ConnectPlayer(ctx, ticket1.Id))
assert.Equal(t, string(allocatedGameServer.ConnectionName()), assignment.Connection)
}
ticket2 := mustCreateTicket(t, frontend, &pb.Ticket{})
{
matches := fetchMatches(t, backend, profile)
assert.Len(t, matches, 1)
assert.Equal(t, false, matches[0].AllocateGameserver)
assert.Len(t, matches[0].Tickets, 1)
assert.NotNil(t, matches[0].Backfill)
openSlots, err := getOpenSlots(matches[0].Backfill)
assert.NoError(t, err)
assert.Equal(t, int32(playersPerMatch-1), openSlots)
assignment := mustAssignment(t, frontend, ticket2.Id, 3*time.Second)
assert.Equal(t, string(allocatedGameServer.ConnectionName()), assignment.Connection)
assert.NoError(t, allocatedGameServer.ConnectPlayer(ctx, ticket2.Id))
}
ticket3 := mustCreateTicket(t, frontend, &pb.Ticket{})
{
matches := fetchMatches(t, backend, profile)
assert.Len(t, matches, 1)
assert.Equal(t, false, matches[0].AllocateGameserver)
assert.Len(t, matches[0].Tickets, 1)
assert.NotNil(t, matches[0].Backfill)
openSlots, err := getOpenSlots(matches[0].Backfill)
assert.NoError(t, err)
assert.Equal(t, int32(playersPerMatch-2), openSlots)
assignment := mustAssignment(t, frontend, ticket3.Id, 3*time.Second)
assert.Equal(t, string(allocatedGameServer.ConnectionName()), assignment.Connection)
assert.NoError(t, allocatedGameServer.ConnectPlayer(ctx, ticket3.Id))
}
assert.NoError(t, allocatedGameServer.StopBackfill(ctx, currentBackfill.Id))
assert.NoError(t, allocatedGameServer.DisconnectPlayer(ctx, ticket1.Id))
assert.NoError(t, allocatedGameServer.StartBackfill(ctx, assignment, 1))
ticket4 := mustCreateTicket(t, frontend, &pb.Ticket{})
{
matches := fetchMatches(t, backend, profile)
assert.Len(t, matches, 1)
assert.Equal(t, false, matches[0].AllocateGameserver)
assert.Len(t, matches[0].Tickets, 1)
assert.NotNil(t, matches[0].Backfill)
openSlots, err := getOpenSlots(matches[0].Backfill)
assert.NoError(t, err)
assert.Equal(t, int32(playersPerMatch-2), openSlots)
assignment := mustAssignment(t, frontend, ticket4.Id, 3*time.Second)
assert.Equal(t, string(allocatedGameServer.ConnectionName()), assignment.Connection)
assert.NoError(t, allocatedGameServer.ConnectPlayer(ctx, ticket4.Id))
}
}