Skip to content

Commit 33a0bba

Browse files
authored
Merge pull request #39 from castaneai/fix-withtestserverlistenaddr
fix WithTestServerListenAddr does not work
2 parents 86de02a + 00f4281 commit 33a0bba

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

testing.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func NewTestFrontendServer(t *testing.T, store statestore.FrontendStore, addr st
101101
mux := http.NewServeMux()
102102
mux.Handle(openmatchconnect.NewFrontendServiceHandler(NewFrontendService(store, opts...)))
103103
sv := httptest.NewUnstartedServer(h2c.NewHandler(mux, &http2.Server{}))
104+
lis, err := newLocalListener(addr)
105+
if err != nil {
106+
t.Fatalf("failed to listen TCP addr: %+v", err)
107+
}
108+
sv.Listener = lis
104109
sv.EnableHTTP2 = true
105110
ts := &TestFrontendServer{
106111
sv: sv,
@@ -109,6 +114,10 @@ func NewTestFrontendServer(t *testing.T, store statestore.FrontendStore, addr st
109114
return ts
110115
}
111116

117+
func newLocalListener(addr string) (net.Listener, error) {
118+
return net.Listen("tcp", addr)
119+
}
120+
112121
// RunTestServer helps with integration tests using Open Match.
113122
// It provides an Open Match Frontend equivalent API in the Go process using a random port.
114123
func RunTestServer(t *testing.T, matchFunctions map[*pb.MatchProfile]MatchFunction, assigner Assigner, opts ...TestServerOption) *TestServer {

tests/intergration_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ func TestAssignerError(t *testing.T) {
295295
assert.Equal(t, as1.Connection, as2.Connection)
296296
}
297297

298+
func TestTestServer(t *testing.T) {
299+
addr := "127.0.0.1:34543"
300+
ts := minimatch.RunTestServer(t, map[*pb.MatchProfile]minimatch.MatchFunction{
301+
anyProfile: minimatch.MatchFunctionSimple1vs1}, minimatch.AssignerFunc(dummyAssign), minimatch.WithTestServerListenAddr(addr))
302+
assert.Equal(t, addr, ts.FrontendAddr())
303+
}
304+
298305
func mustCreateTicket(ctx context.Context, t *testing.T, c openmatchconnect.FrontendServiceClient, ticket *pb.Ticket) *pb.Ticket {
299306
t.Helper()
300307
resp, err := c.CreateTicket(ctx, connect.NewRequest(&pb.CreateTicketRequest{Ticket: ticket}))

0 commit comments

Comments
 (0)