diff --git a/bench/benchmarker/world/chair_routes.go b/bench/benchmarker/world/chair_routes.go index d6943242..e53d7eed 100644 --- a/bench/benchmarker/world/chair_routes.go +++ b/bench/benchmarker/world/chair_routes.go @@ -152,3 +152,15 @@ func (r *ChairLocation) GetCoordByTime(t time.Time) Coordinate { } return r.Initial } + +func (r *ChairLocation) GetLocationEntryByTime(t time.Time) *LocationEntry { + r.mu.RLock() + defer r.mu.RUnlock() + + for _, entry := range slices.Backward(r.history) { + if entry.ServerTime.Valid && !entry.ServerTime.Time.After(t) { + return entry + } + } + return nil +} diff --git a/bench/benchmarker/world/owner.go b/bench/benchmarker/world/owner.go index 93902443..da889ef9 100644 --- a/bench/benchmarker/world/owner.go +++ b/bench/benchmarker/world/owner.go @@ -79,11 +79,12 @@ func (p *Owner) Tick(ctx *Context) error { return WrapCodeError(ErrorCodeFailedToGetOwnerChairs, err) } + baseTime := time.Now() res, err := p.Client.GetOwnerChairs(ctx, &GetOwnerChairsRequest{}) if err != nil { return WrapCodeError(ErrorCodeFailedToGetOwnerChairs, err) } - if err := p.ValidateChairs(res); err != nil { + if err := p.ValidateChairs(res, baseTime); err != nil { return WrapCodeError(ErrorCodeIncorrectOwnerChairsData, err) } } else if ctx.CurrentTime()%LengthOfHour == LengthOfHour-1 { @@ -201,7 +202,7 @@ func (p *Owner) ValidateSales(until time.Time, serverSide *GetOwnerSalesResponse return nil } -func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse) error { +func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse, baseTime time.Time) error { if p.ChairDB.Len() != len(serverSide.Chairs) { return fmt.Errorf("オーナーの椅子の数が一致していません") } @@ -222,8 +223,8 @@ func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse) error { // return fmt.Errorf("activeが一致しないデータがあります (id: %s, got: %v, want: %v)", chair.ServerID, data.Active, !data.Active) //} if data.TotalDistanceUpdatedAt.Valid { - lastMovedAt, ok := chair.Location.LastMovedAt() - if ok && data.TotalDistanceUpdatedAt.Time.Sub(lastMovedAt) > 3*time.Second { + lastMoved := chair.Location.GetLocationEntryByTime(baseTime) + if lastMoved != nil && lastMoved.ServerTime.Time.Sub(data.TotalDistanceUpdatedAt.Time) > 3*time.Second { return fmt.Errorf("total_distanceの反映が遅いデータがあります (id: %s)", chair.ServerID) } want := chair.Location.TotalTravelDistanceUntil(data.TotalDistanceUpdatedAt.Time)