Skip to content

Commit

Permalink
Merge branch 'main' into multi-simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
imamiya-masaki committed Dec 4, 2024
2 parents c32ada7 + 0e2c11e commit 434ebe7
Show file tree
Hide file tree
Showing 81 changed files with 911 additions and 900 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ jobs:
runs-on: codebuild-problem-github-actions-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- uses: actions/checkout@v4
- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: "frontend/pnpm-lock.yaml"
- name: Build frontend
working-directory: ./bench
run: |
task gen-frontend
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions bench/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ Temporary Items
.apdisk

bench

benchrun/frontend_hashes.json
6 changes: 3 additions & 3 deletions bench/benchmarker/scenario/prevalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func validateFrontendFiles(ctx context.Context, clientConfig webapp.ClientConfig
indexHtmlHash := frontendHashes["index.html"]

{
actualHash, err := client.StaticGetFileHash(ctx, "/")
actualHash, err := client.StaticGetFileHash(ctx, "/client")
if err != nil {
return err
}
Expand All @@ -76,12 +76,12 @@ func validateFrontendFiles(ctx context.Context, clientConfig webapp.ClientConfig

// check index.html for other paths
{
actualHash, err := client.StaticGetFileHash(ctx, "/client")
actualHash, err := client.StaticGetFileHash(ctx, "/owner")
if err != nil {
return err
}
if actualHash != indexHtmlHash {
return errors.New("/clientの内容が正しくありません")
return errors.New("/ownerの内容が正しくありません")
}
}

Expand Down
6 changes: 3 additions & 3 deletions bench/benchmarker/scenario/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewScenario(target, addr, paymentURL string, logger *slog.Logger, reporter
TargetBaseURL: target,
TargetAddr: addr,
ClientIdleConnTimeout: 10 * time.Second,
})
}, skipStaticFileSanityCheck)
w := world.NewWorld(30*time.Millisecond, completedRequestChan, worldClient, logger)

worldCtx := world.NewContext(w)
Expand Down Expand Up @@ -283,7 +283,7 @@ func (s *Scenario) Score(final bool) int64 {
score := lo.SumBy(s.world.OwnerDB.ToSlice(), func(p *world.Owner) int64 { return p.SubScore.Load() }) / 100
if final {
score += lo.SumBy(s.world.RequestDB.ToSlice(), func(r *world.Request) int64 {
if r.Evaluated {
if r.Evaluated.Load() {
return 0
}
return int64(r.PartialScore())
Expand All @@ -295,7 +295,7 @@ func (s *Scenario) Score(final bool) int64 {

func (s *Scenario) TotalDiscount() int64 {
return lo.SumBy(s.world.RequestDB.ToSlice(), func(r *world.Request) int64 {
if r.Evaluated {
if r.Evaluated.Load() {
return int64(r.ActualDiscount())
} else {
return 0
Expand Down
4 changes: 4 additions & 0 deletions bench/benchmarker/scenario/worldclient/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const (
ErrorCodeFailedToPostRidesEstimatedFare
// ErrorCodeFailedToGetNearbyChairs 近くの椅子情報の取得に失敗したエラー
ErrorCodeFailedToGetNearbyChairs
// ErrorCodeFailedToGetStaticFile 静的ファイルの取得に失敗したエラー
ErrorCodeFailedToGetStaticFile
// ErrorCodeInvalidContent 静的ファイルの内容が一致しないエラー
ErrorCodeInvalidContent
)

type codeError struct {
Expand Down
108 changes: 87 additions & 21 deletions bench/benchmarker/scenario/worldclient/worldclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ import (
"github.com/isucon/isucon14/bench/benchmarker/webapp"
"github.com/isucon/isucon14/bench/benchmarker/webapp/api"
"github.com/isucon/isucon14/bench/benchmarker/world"
"github.com/isucon/isucon14/bench/benchrun"
)

type userClient struct {
ctx context.Context
client *webapp.Client
ctx context.Context
client *webapp.Client
skipStaticFileSanityCheck bool
}

type ownerClient struct {
ctx context.Context
client *webapp.Client
webappClientConfig webapp.ClientConfig
ctx context.Context
client *webapp.Client
webappClientConfig webapp.ClientConfig
skipStaticFileSanityCheck bool
}

type chairClient struct {
Expand All @@ -31,22 +34,34 @@ type chairClient struct {
}

type WorldClient struct {
ctx context.Context
webappClientConfig webapp.ClientConfig
ctx context.Context
webappClientConfig webapp.ClientConfig
skipStaticFileSanityCheck bool
}

func NewWorldClient(ctx context.Context, webappClientConfig webapp.ClientConfig) *WorldClient {
func NewWorldClient(ctx context.Context, webappClientConfig webapp.ClientConfig, skipStaticFileSanityCheck bool) *WorldClient {
return &WorldClient{
ctx: ctx,
webappClientConfig: webappClientConfig,
ctx: ctx,
webappClientConfig: webappClientConfig,
skipStaticFileSanityCheck: skipStaticFileSanityCheck,
}
}

func (c *WorldClient) RegisterUser(ctx *world.Context, data *world.RegisterUserRequest) (*world.RegisterUserResponse, error) {
func (c *WorldClient) RegisterUser(ctx *world.Context, data *world.RegisterUserRequest, beforeRequest func(client world.UserClient) error) (*world.RegisterUserResponse, error) {
client, err := webapp.NewClient(c.webappClientConfig)
if err != nil {
return nil, WrapCodeError(ErrorCodeFailedToCreateWebappClient, err)
}
userClient := &userClient{
ctx: c.ctx,
client: client,
skipStaticFileSanityCheck: c.skipStaticFileSanityCheck,
}

err = beforeRequest(userClient)
if err != nil {
return nil, err
}

response, err := client.AppPostRegister(c.ctx, &api.AppPostUsersReq{
Username: data.UserName,
Expand All @@ -62,18 +77,26 @@ func (c *WorldClient) RegisterUser(ctx *world.Context, data *world.RegisterUserR
return &world.RegisterUserResponse{
ServerUserID: response.ID,
InvitationCode: response.InvitationCode,
Client: &userClient{
ctx: c.ctx,
client: client,
},
Client: userClient,
}, nil
}

func (c *WorldClient) RegisterOwner(ctx *world.Context, data *world.RegisterOwnerRequest) (*world.RegisterOwnerResponse, error) {
func (c *WorldClient) RegisterOwner(ctx *world.Context, data *world.RegisterOwnerRequest, beforeRequest func(client world.OwnerClient) error) (*world.RegisterOwnerResponse, error) {
client, err := webapp.NewClient(c.webappClientConfig)
if err != nil {
return nil, WrapCodeError(ErrorCodeFailedToCreateWebappClient, err)
}
ownerClient := &ownerClient{
ctx: c.ctx,
client: client,
webappClientConfig: c.webappClientConfig,
skipStaticFileSanityCheck: c.skipStaticFileSanityCheck,
}

err = beforeRequest(ownerClient)
if err != nil {
return nil, err
}

response, err := client.OwnerPostRegister(c.ctx, &api.OwnerPostOwnersReq{
Name: data.Name,
Expand All @@ -85,11 +108,7 @@ func (c *WorldClient) RegisterOwner(ctx *world.Context, data *world.RegisterOwne
return &world.RegisterOwnerResponse{
ServerOwnerID: response.ID,
ChairRegisteredToken: response.ChairRegisterToken,
Client: &ownerClient{
ctx: c.ctx,
client: client,
webappClientConfig: c.webappClientConfig,
},
Client: ownerClient,
}, nil
}

Expand Down Expand Up @@ -169,6 +188,13 @@ func (c *ownerClient) GetOwnerChairs(ctx *world.Context, args *world.GetOwnerCha
})}, nil
}

func (c *ownerClient) BrowserAccess(ctx *world.Context, scenario benchrun.FrontendPathScenario) error {
if c.skipStaticFileSanityCheck {
return nil
}
return browserAccess(c.ctx, c.client, scenario)
}

func (c *chairClient) SendChairCoordinate(ctx *world.Context, chair *world.Chair) (*world.SendChairCoordinateResponse, error) {
response, err := c.client.ChairPostCoordinate(c.ctx, &api.Coordinate{
Latitude: chair.Location.Current().X,
Expand Down Expand Up @@ -267,6 +293,10 @@ func (c *chairClient) ConnectChairNotificationStream(ctx *world.Context, chair *
}, nil
}

func (c *userClient) getInternalClient() *webapp.Client {
return c.client
}

func (c *userClient) SendEvaluation(ctx *world.Context, req *world.Request, score int) (*world.SendEvaluationResponse, error) {
res, err := c.client.AppPostRequestEvaluate(c.ctx, req.ServerID, &api.AppPostRideEvaluationReq{
Evaluation: score,
Expand Down Expand Up @@ -446,3 +476,39 @@ type notificationConnectionImpl struct {
func (c *notificationConnectionImpl) Close() {
c.close()
}

func (c *userClient) BrowserAccess(ctx *world.Context, scenario benchrun.FrontendPathScenario) error {
if c.skipStaticFileSanityCheck {
return nil
}
return browserAccess(c.ctx, c.client, scenario)
}

func browserAccess(ctx context.Context, client *webapp.Client, scenario benchrun.FrontendPathScenario) error {
paths := benchrun.FRONTEND_PATH_SCENARIOS[scenario]
path := paths[len(paths)-1]

// ハードナビゲーション
if len(paths) == 1 {
hash, err := client.StaticGetFileHash(ctx, path)
if err != nil {
return WrapCodeError(ErrorCodeFailedToGetStaticFile, err)
}
if hash != benchrun.FrontendHashesMap["index.html"] {
return WrapCodeError(ErrorCodeInvalidContent, errors.New("invalid content for "+path))
}
}

filePaths := benchrun.FrontendPathScenarioFiles[scenario]
for _, filePath := range filePaths {
hash, err := client.StaticGetFileHash(ctx, filePath)
if err != nil {
return WrapCodeError(ErrorCodeFailedToGetStaticFile, err)
}
if hash != benchrun.FrontendHashesMap[filePath[1:]] {
return WrapCodeError(ErrorCodeInvalidContent, errors.New("invalid content for "+filePath))
}
}

return nil
}
2 changes: 1 addition & 1 deletion bench/benchmarker/webapp/api/generate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package api

//go:generate go run github.com/ogen-go/ogen/cmd/ogen --target . --clean ../../../../openapi/openapi.yaml
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --target . --clean ../../../../webapp/openapi.yaml
46 changes: 44 additions & 2 deletions bench/benchmarker/webapp/api/oas_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions bench/benchmarker/webapp/api/oas_json_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions bench/benchmarker/webapp/api/oas_response_decoders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 434ebe7

Please sign in to comment.