Skip to content

Commit

Permalink
Merge pull request #136 from isucon/issue-130
Browse files Browse the repository at this point in the history
fix #130
  • Loading branch information
Drumato authored Oct 31, 2023
2 parents 1826bf5 + a7f1fdf commit d57ee74
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 215 deletions.
4 changes: 2 additions & 2 deletions bench/internal/scheduler/livecomment_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ var LivecommentScheduler = mustNewLivecommentScheduler()
// それ以外、通常に分類され、ユーザは通常配信者と視聴者になる

type Livecomment struct {
UserId int
LivestreamId int
UserID int
LivestreamID int
Comment string
Tip int
}
Expand Down
26 changes: 13 additions & 13 deletions bench/isupipe/client_livecomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Livecomment struct {
Id int `json:"id"`
ID int `json:"id"`
User User `json:"user"`
Livestream Livestream `json:"livestream"`
Comment string `json:"comment"`
Expand All @@ -24,7 +24,7 @@ type Livecomment struct {
}

type LivecommentReport struct {
Id int `json:"id"`
ID int `json:"id"`
Reporter User `json:"reporter"`
Livecomment Livecomment `json:"livecomment"`
CreatedAt int `json:"created_at"`
Expand All @@ -37,7 +37,7 @@ type (
Tip int `json:"tip"`
}
PostLivecommentResponse struct {
Id int `json:"id"`
ID int `json:"id"`
User User `json:"user"`
Livestream Livestream `json:"livestream"`
Comment string `json:"comment"`
Expand All @@ -51,13 +51,13 @@ type ModerateRequest struct {
NGWord string `json:"ng_word"`
}

func (c *Client) GetLivecomments(ctx context.Context, livestreamId int, opts ...ClientOption) ([]Livecomment, error) {
func (c *Client) GetLivecomments(ctx context.Context, livestreamID int, opts ...ClientOption) ([]Livecomment, error) {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/livecomment", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/livecomment", livestreamID)
req, err := c.agent.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down Expand Up @@ -87,13 +87,13 @@ func (c *Client) GetLivecomments(ctx context.Context, livestreamId int, opts ...
return livecomments, nil
}

func (c *Client) GetLivecommentReports(ctx context.Context, livestreamId int, opts ...ClientOption) ([]LivecommentReport, error) {
func (c *Client) GetLivecommentReports(ctx context.Context, livestreamID int, opts ...ClientOption) ([]LivecommentReport, error) {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/report", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/report", livestreamID)
req, err := c.agent.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down Expand Up @@ -123,7 +123,7 @@ func (c *Client) GetLivecommentReports(ctx context.Context, livestreamId int, op
return reports, nil
}

func (c *Client) PostLivecomment(ctx context.Context, livestreamId int, r *PostLivecommentRequest, opts ...ClientOption) (*PostLivecommentResponse, error) {
func (c *Client) PostLivecomment(ctx context.Context, livestreamID int, r *PostLivecommentRequest, opts ...ClientOption) (*PostLivecommentResponse, error) {
var (
defaultStatusCode = http.StatusCreated
o = newClientOptions(defaultStatusCode, opts...)
Expand All @@ -134,7 +134,7 @@ func (c *Client) PostLivecomment(ctx context.Context, livestreamId int, r *PostL
return nil, bencherror.NewInternalError(err)
}

urlPath := fmt.Sprintf("/api/livestream/%d/livecomment", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/livecomment", livestreamID)
req, err := c.agent.NewRequest(http.MethodPost, urlPath, bytes.NewReader(payload))
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down Expand Up @@ -168,13 +168,13 @@ func (c *Client) PostLivecomment(ctx context.Context, livestreamId int, r *PostL
return livecommentResponse, nil
}

func (c *Client) ReportLivecomment(ctx context.Context, livestreamId, livecommentId int, opts ...ClientOption) error {
func (c *Client) ReportLivecomment(ctx context.Context, livestreamID, livecommentID int, opts ...ClientOption) error {
var (
defaultStatusCode = http.StatusCreated
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/livecomment/%d/report", livestreamId, livecommentId)
urlPath := fmt.Sprintf("/api/livestream/%d/livecomment/%d/report", livestreamID, livecommentID)
req, err := c.agent.NewRequest(http.MethodPost, urlPath, nil)
if err != nil {
return bencherror.NewInternalError(err)
Expand All @@ -198,13 +198,13 @@ func (c *Client) ReportLivecomment(ctx context.Context, livestreamId, livecommen
return nil
}

func (c *Client) Moderate(ctx context.Context, livestreamId int, ngWord string, opts ...ClientOption) error {
func (c *Client) Moderate(ctx context.Context, livestreamID int, ngWord string, opts ...ClientOption) error {
var (
defaultStatusCode = http.StatusCreated
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/moderate", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/moderate", livestreamID)
payload, err := json.Marshal(&ModerateRequest{
NGWord: ngWord,
})
Expand Down
14 changes: 7 additions & 7 deletions bench/isupipe/client_livestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Livestream struct {
Id int `json:"id"`
ID int `json:"id"`
Owner User `json:"owner"`
Tags []Tag `json:"tags"`
Title string `json:"title"`
Expand All @@ -39,15 +39,15 @@ type (

func (c *Client) GetLivestream(
ctx context.Context,
livestreamId int,
livestreamID int,
opts ...ClientOption,
) error {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d", livestreamID)
req, err := c.agent.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
return bencherror.NewInternalError(err)
Expand Down Expand Up @@ -181,13 +181,13 @@ func (c *Client) ReserveLivestream(ctx context.Context, r *ReserveLivestreamRequ
return livestream, nil
}

func (c *Client) EnterLivestream(ctx context.Context, livestreamId int, opts ...ClientOption) error {
func (c *Client) EnterLivestream(ctx context.Context, livestreamID int, opts ...ClientOption) error {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/enter", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/enter", livestreamID)
req, err := c.agent.NewRequest(http.MethodPost, urlPath, nil)
if err != nil {
return bencherror.NewInternalError(err)
Expand All @@ -211,13 +211,13 @@ func (c *Client) EnterLivestream(ctx context.Context, livestreamId int, opts ...
return nil
}

func (c *Client) LeaveLivestream(ctx context.Context, livestreamId int, opts ...ClientOption) error {
func (c *Client) LeaveLivestream(ctx context.Context, livestreamID int, opts ...ClientOption) error {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/enter", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/enter", livestreamID)
req, err := c.agent.NewRequest(http.MethodDelete, urlPath, nil)
if err != nil {
return bencherror.NewInternalError(err)
Expand Down
2 changes: 1 addition & 1 deletion bench/isupipe/client_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Payment struct {
ReservationId int
ReservationID int
Tip int
}

Expand Down
10 changes: 5 additions & 5 deletions bench/isupipe/client_reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ type PostReactionRequest struct {
}

type Reaction struct {
Id int `json:"id"`
ID int `json:"id"`
EmojiName string `json:"emoji_name"`
User User `json:"user"`
Livestream Livestream `json:"livestream"`
CreatedAt int `json:"created_at"`
}

func (c *Client) GetReactions(ctx context.Context, livestreamId int, opts ...ClientOption) ([]Reaction, error) {
func (c *Client) GetReactions(ctx context.Context, livestreamID int, opts ...ClientOption) ([]Reaction, error) {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/reaction", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/reaction", livestreamID)
req, err := c.agent.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *Client) GetReactions(ctx context.Context, livestreamId int, opts ...Cli
return reactions, nil
}

func (c *Client) PostReaction(ctx context.Context, livestreamId int, r *PostReactionRequest, opts ...ClientOption) (*Reaction, error) {
func (c *Client) PostReaction(ctx context.Context, livestreamID int, r *PostReactionRequest, opts ...ClientOption) (*Reaction, error) {
var (
defaultStatusCode = http.StatusCreated
o = newClientOptions(defaultStatusCode, opts...)
Expand All @@ -71,7 +71,7 @@ func (c *Client) PostReaction(ctx context.Context, livestreamId int, r *PostReac
return nil, bencherror.NewInternalError(err)
}

urlPath := fmt.Sprintf("/api/livestream/%d/reaction", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/reaction", livestreamID)
req, err := c.agent.NewRequest(http.MethodPost, urlPath, bytes.NewReader(payload))
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down
4 changes: 2 additions & 2 deletions bench/isupipe/client_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (c *Client) GetUserStatistics(ctx context.Context, username string, opts ..
return stats, nil
}

func (c *Client) GetLivestreamStatistics(ctx context.Context, livestreamId int, opts ...ClientOption) (*LivestreamStatistics, error) {
func (c *Client) GetLivestreamStatistics(ctx context.Context, livestreamID int, opts ...ClientOption) (*LivestreamStatistics, error) {
var (
defaultStatusCode = http.StatusOK
o = newClientOptions(defaultStatusCode, opts...)
)

urlPath := fmt.Sprintf("/api/livestream/%d/statistics", livestreamId)
urlPath := fmt.Sprintf("/api/livestream/%d/statistics", livestreamID)
req, err := c.agent.NewRequest(http.MethodGet, urlPath, nil)
if err != nil {
return nil, bencherror.NewInternalError(err)
Expand Down
4 changes: 2 additions & 2 deletions bench/isupipe/client_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type Tag struct {
Id int `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
// CreatedAt is the created timestamp that forms an UNIX time.
CreatedAt int `json:"created_at"`
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *Client) GetRandomTags(ctx context.Context, n int) ([]int, error) {

var tags []int
for i := 0; i < n; i++ {
tags = append(tags, resp.Tags[i].Id)
tags = append(tags, resp.Tags[i].ID)
}

return tags, nil
Expand Down
2 changes: 1 addition & 1 deletion bench/isupipe/client_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

type User struct {
Id int `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
Expand Down
2 changes: 1 addition & 1 deletion bench/scenario/core_finalcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func FinalcheckScenario(ctx context.Context, client *isupipe.Client) error {
// 予約の整合性チェック
for _, payment := range result.Payments {
_ = payment
// payment.ReservationId
// payment.ReservationID
}

lgr.Infof("result = %+v\n", result)
Expand Down
22 changes: 11 additions & 11 deletions bench/scenario/core_pretest.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Pretest(ctx context.Context, client *isupipe.Client) error {
)
var tags []int
for _, tag := range tagResponse.Tags[tagStartIdx:tagEndIdx] {
tags = append(tags, tag.Id)
tags = append(tags, tag.ID)
}

// FIXME: 枠数を超えて予約した場合にエラーになるか
Expand All @@ -95,40 +95,40 @@ func Pretest(ctx context.Context, client *isupipe.Client) error {
}
scheduler.ReservationSched.CommitReservation(reservation)

if _, err = client.GetLivecommentReports(ctx, livestream.Id); err != nil {
if _, err = client.GetLivecommentReports(ctx, livestream.ID); err != nil {
return err
}
if err = client.GetLivestream(ctx, livestream.Id); err != nil {
if err = client.GetLivestream(ctx, livestream.ID); err != nil {
return err
}

if err := client.EnterLivestream(ctx, livestream.Id); err != nil {
if err := client.EnterLivestream(ctx, livestream.ID); err != nil {
return err
}

livecomment, err := client.PostLivecomment(ctx, livestream.Id, &isupipe.PostLivecommentRequest{
livecomment, err := client.PostLivecomment(ctx, livestream.ID, &isupipe.PostLivecommentRequest{
Comment: "test",
Tip: 3,
})
if err != nil {
return err
}

if _, err := client.GetLivecomments(ctx, livestream.Id /* livestream id*/); err != nil {
if _, err := client.GetLivecomments(ctx, livestream.ID /* livestream id*/); err != nil {
return err
}

if err := client.ReportLivecomment(ctx, livestream.Id, livecomment.Id); err != nil {
if err := client.ReportLivecomment(ctx, livestream.ID, livecomment.ID); err != nil {
return err
}

if _, err := client.PostReaction(ctx, livestream.Id /* livestream id*/, &isupipe.PostReactionRequest{
if _, err := client.PostReaction(ctx, livestream.ID /* livestream id*/, &isupipe.PostReactionRequest{
EmojiName: "chair",
}); err != nil {
return err
}

if _, err := client.GetReactions(ctx, livestream.Id /* livestream id*/); err != nil {
if _, err := client.GetReactions(ctx, livestream.ID /* livestream id*/); err != nil {
return err
}

Expand All @@ -140,11 +140,11 @@ func Pretest(ctx context.Context, client *isupipe.Client) error {
return err
}

if _, err := client.GetLivestreamStatistics(ctx, livestream.Id); err != nil {
if _, err := client.GetLivestreamStatistics(ctx, livestream.ID); err != nil {
return err
}

if err := client.LeaveLivestream(ctx, livestream.Id); err != nil {
if err := client.LeaveLivestream(ctx, livestream.ID); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions bench/scenario/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ func BasicViewerScenario(
return err
}

if err := client.EnterLivestream(ctx, livestream.Id); err != nil {
if err := client.EnterLivestream(ctx, livestream.ID); err != nil {
return err
}

for i := 0; i < config.AdvertiseCost*10; i++ {
livecomment := scheduler.LivecommentScheduler.GetLongPositiveComment()
tip := scheduler.LivecommentScheduler.GetTipsForStream()
if _, err := client.PostLivecomment(ctx, livestream.Id, &isupipe.PostLivecommentRequest{
if _, err := client.PostLivecomment(ctx, livestream.ID, &isupipe.PostLivecommentRequest{
Comment: livecomment.Comment,
Tip: tip,
}); err != nil {
return err
}

emojiName := scheduler.GetReaction()
if _, err := client.PostReaction(ctx, livestream.Id, &isupipe.PostReactionRequest{
if _, err := client.PostReaction(ctx, livestream.ID, &isupipe.PostReactionRequest{
EmojiName: emojiName,
}); err != nil {
return err
}
}

if err := client.LeaveLivestream(ctx, livestream.Id); err != nil {
if err := client.LeaveLivestream(ctx, livestream.ID); err != nil {
return err
}

Expand Down
Loading

0 comments on commit d57ee74

Please sign in to comment.