Skip to content

Commit f2665b6

Browse files
committed
add test scenario
1 parent b3acf1c commit f2665b6

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

Diff for: server/client/request.go

+20
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ func WatchDirect(ctx context.Context, grpccon *grpc.ClientConn, wshost, appid, r
145145
return connectToRoom(ctx, accinfo, res, warn)
146146
}
147147

148+
// WatchByNumber : 部屋番号で観戦入室
149+
func WatchByNumber(ctx context.Context, accinfo *AccessInfo, number int32, query *Query, warn func(error)) (*Room, *Connection, error) {
150+
var q []lobby.PropQueries
151+
if query != nil {
152+
q = []lobby.PropQueries(*query)
153+
}
154+
param := lobby.JoinParam{
155+
Queries: q,
156+
ClientInfo: &pb.ClientInfo{Id: accinfo.UserId},
157+
EncMACKey: accinfo.EncMACKey,
158+
}
159+
160+
res, err := lobbyRequest(ctx, accinfo, fmt.Sprintf("/rooms/watch/number/%d", number), param)
161+
if err != nil {
162+
return nil, nil, xerrors.Errorf("lobbyRequest: %w", err)
163+
}
164+
165+
return connectToRoom(ctx, accinfo, res.Room, warn)
166+
}
167+
148168
// Search : 部屋を検索する
149169
func Search(ctx context.Context, accinfo *AccessInfo, param *lobby.SearchParam) ([]*pb.RoomInfo, error) {
150170
res, err := lobbyRequest(ctx, accinfo, "/rooms/search", param)

Diff for: server/cmd/wsnet2-bot/cmd/root.go

+30
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ func joinRoom(ctx context.Context, player, roomId string, query *client.Query) (
174174
return client.Join(ctx, accinfo, roomId, query, cinfo, nil)
175175
}
176176

177+
// joinByNumber joins the player to a room specified by the number
178+
func joinByNumber(ctx context.Context, player string, number int32, query *client.Query) (*client.Room, *client.Connection, error) {
179+
accinfo, err := client.GenAccessInfo(lobbyURL, appId, appKey, player)
180+
if err != nil {
181+
return nil, nil, err
182+
}
183+
184+
if query == nil {
185+
query = client.NewQuery()
186+
}
187+
188+
cinfo := &pb.ClientInfo{Id: player}
189+
190+
return client.JoinByNumber(ctx, accinfo, number, query, cinfo, nil)
191+
}
192+
177193
// joinRandom joins the player to a room randomly
178194
func joinRandom(ctx context.Context, player string, group uint32, query *client.Query) (*client.Room, *client.Connection, error) {
179195
accinfo, err := client.GenAccessInfo(lobbyURL, appId, appKey, player)
@@ -200,6 +216,20 @@ func watchRoom(ctx context.Context, watcher, roomId string, query *client.Query)
200216
return client.Watch(ctx, accinfo, roomId, query, nil)
201217
}
202218

219+
// watchByNumber joins the watcher to a room specified by the number
220+
func watchByNumber(ctx context.Context, watcher string, number int32, query *client.Query) (*client.Room, *client.Connection, error) {
221+
accinfo, err := client.GenAccessInfo(lobbyURL, appId, appKey, watcher)
222+
if err != nil {
223+
return nil, nil, err
224+
}
225+
226+
if query == nil {
227+
query = client.NewQuery()
228+
}
229+
230+
return client.WatchByNumber(ctx, accinfo, number, query, nil)
231+
}
232+
203233
// searchCurrent search current rooms
204234
func searchCurrent(ctx context.Context, cid string) ([]*pb.RoomInfo, error) {
205235
accinfo, err := client.GenAccessInfo(lobbyURL, appId, appKey, cid)

Diff for: server/cmd/wsnet2-bot/cmd/scenario.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func scenarioJoinRoom(ctx context.Context) error {
257257
clearEventBuffer(conn)
258258

259259
// 正常入室
260-
_, p2, err := joinRoom(ctx, "joinroom_player2", room.Id, nil)
260+
_, p2, err := joinByNumber(ctx, "joinroom_player2", *room.Number, nil)
261261
if err != nil {
262262
return fmt.Errorf("join-room: player2: %w", err)
263263
}
@@ -286,6 +286,14 @@ func scenarioJoinRoom(ctx context.Context) error {
286286
discardEvents(w1)
287287
defer cleanupConn(ctx, w1)
288288

289+
_, w2, err := watchByNumber(ctx, "joinroom_watcher2", *room.Number, nil)
290+
if err != nil {
291+
return fmt.Errorf("join-room: watcher2: %w", err)
292+
}
293+
logger.Infof("join-room: watcher2 ok")
294+
discardEvents(w2)
295+
defer cleanupConn(ctx, w2)
296+
289297
clearEventBuffer(conn)
290298

291299
// MaxPlayerを+2増やしwatchable=falseに
@@ -310,12 +318,12 @@ func scenarioJoinRoom(ctx context.Context) error {
310318
defer cleanupConn(ctx, p4)
311319

312320
// 観戦はエラー
313-
_, w2, err := watchRoom(ctx, "joinroom_watcher2", room.Id, nil)
321+
_, w3, err := watchRoom(ctx, "joinroom_watcher3", room.Id, nil)
314322
if !errors.Is(err, client.ErrNoRoomFound) {
315-
cleanupConn(ctx, w2)
316-
return fmt.Errorf("join-room: watcher2 wants NoRoomFound: %v", err)
323+
cleanupConn(ctx, w3)
324+
return fmt.Errorf("join-room: watcher3 wants NoRoomFound: %v", err)
317325
}
318-
logger.Infof("join-room: watcher2 ok (no room found)")
326+
logger.Infof("join-room: watcher3 ok (no room found)")
319327

320328
clearEventBuffer(conn)
321329

0 commit comments

Comments
 (0)