Skip to content

Commit

Permalink
Merge pull request #39 from castaneai/fix-withtestserverlistenaddr
Browse files Browse the repository at this point in the history
fix WithTestServerListenAddr does not work
  • Loading branch information
castaneai authored Nov 22, 2024
2 parents 86de02a + 00f4281 commit 33a0bba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func NewTestFrontendServer(t *testing.T, store statestore.FrontendStore, addr st
mux := http.NewServeMux()
mux.Handle(openmatchconnect.NewFrontendServiceHandler(NewFrontendService(store, opts...)))
sv := httptest.NewUnstartedServer(h2c.NewHandler(mux, &http2.Server{}))
lis, err := newLocalListener(addr)
if err != nil {
t.Fatalf("failed to listen TCP addr: %+v", err)
}
sv.Listener = lis
sv.EnableHTTP2 = true
ts := &TestFrontendServer{
sv: sv,
Expand All @@ -109,6 +114,10 @@ func NewTestFrontendServer(t *testing.T, store statestore.FrontendStore, addr st
return ts
}

func newLocalListener(addr string) (net.Listener, error) {
return net.Listen("tcp", addr)
}

// RunTestServer helps with integration tests using Open Match.
// It provides an Open Match Frontend equivalent API in the Go process using a random port.
func RunTestServer(t *testing.T, matchFunctions map[*pb.MatchProfile]MatchFunction, assigner Assigner, opts ...TestServerOption) *TestServer {
Expand Down
7 changes: 7 additions & 0 deletions tests/intergration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ func TestAssignerError(t *testing.T) {
assert.Equal(t, as1.Connection, as2.Connection)
}

func TestTestServer(t *testing.T) {
addr := "127.0.0.1:34543"
ts := minimatch.RunTestServer(t, map[*pb.MatchProfile]minimatch.MatchFunction{
anyProfile: minimatch.MatchFunctionSimple1vs1}, minimatch.AssignerFunc(dummyAssign), minimatch.WithTestServerListenAddr(addr))
assert.Equal(t, addr, ts.FrontendAddr())
}

func mustCreateTicket(ctx context.Context, t *testing.T, c openmatchconnect.FrontendServiceClient, ticket *pb.Ticket) *pb.Ticket {
t.Helper()
resp, err := c.CreateTicket(ctx, connect.NewRequest(&pb.CreateTicketRequest{Ticket: ticket}))
Expand Down

0 comments on commit 33a0bba

Please sign in to comment.