Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix WithTestServerListenAddr does not work #39

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading