Skip to content

deps: bump benchttp/sdk to v0.2 #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion runner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module github.com/benchttp/desktop/runner

go 1.17

require github.com/benchttp/engine v0.1.1
require (
github.com/benchttp/sdk v0.1.1
)

require (
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/benchttp/sdk => ../../engine
31 changes: 13 additions & 18 deletions runner/httpclient/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@ package httpclient

import (
"errors"
"io"
"log"
"net/http"
"time"

"github.com/benchttp/engine/configparse"
"github.com/benchttp/engine/runner"
"github.com/benchttp/sdk/benchttp"
"github.com/benchttp/sdk/configio"

"github.com/benchttp/desktop/runner/httpclient/response"
)

func handle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")

b, err := io.ReadAll(r.Body)
if err != nil {
internalError(w, err)
return
}
runner := benchttp.DefaultRunner()
runner.OnProgress = streamProgress(w)

cfg, err := configparse.JSON(b)
if err != nil {
if err := configio.NewJSONDecoder(r.Body).DecodeRunner(&runner); err != nil {
clientError(w, err)
return
}

rep, err := runner.New(streamProgress(w)).Run(r.Context(), cfg)
var invalidConfigError *runner.InvalidConfigError
report, err := runner.Run(r.Context())
var errInvalidRunner *benchttp.InvalidRunnerError
switch {
case err == nil:
// Pass through.
case err == runner.ErrCanceled:
case err == benchttp.ErrCanceled:
clientError(w, err)
return
case errors.As(err, &invalidConfigError):
clientError(w, invalidConfigError.Errors...)
case errors.As(err, &errInvalidRunner):
clientError(w, errInvalidRunner.Errors...)
return
default:
internalError(w, err)
Expand All @@ -49,14 +44,14 @@ func handle(w http.ResponseWriter, r *http.Request) {
// The issue is likely on the read side (front-end), but this is
// the easiest fix for now.
time.Sleep(10 * time.Millisecond)
if err := response.Report(rep).EncodeJSON(w); err != nil {
if err := response.Report(report).EncodeJSON(w); err != nil {
internalError(w, err)
return
}
}

func streamProgress(w http.ResponseWriter) func(runner.RecordingProgress) {
return func(progress runner.RecordingProgress) {
func streamProgress(w http.ResponseWriter) func(benchttp.RecordingProgress) {
return func(progress benchttp.RecordingProgress) {
if err := response.Progress(progress).EncodeJSON(w); err != nil {
internalError(w, err)
}
Expand Down
4 changes: 2 additions & 2 deletions runner/httpclient/response/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package response
import (
"time"

"github.com/benchttp/engine/runner"
"github.com/benchttp/sdk/benchttp"
)

func Progress(in runner.RecordingProgress) Response {
func Progress(in benchttp.RecordingProgress) Response {
return newResponse(progressResponse{
Done: in.Done,
Error: in.Error,
Expand Down
10 changes: 5 additions & 5 deletions runner/httpclient/response/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package response
import (
"time"

"github.com/benchttp/engine/runner"
"github.com/benchttp/sdk/benchttp"
)

func Report(rep *runner.Report) Response {
func Report(rep *benchttp.Report) Response {
return newResponse(reportResponse{
Metadata: metadataResponse{
FinishedAt: rep.Metadata.FinishedAt,
Expand Down Expand Up @@ -87,7 +87,7 @@ type requestFailureResponse struct {
Reason string `json:"reason"`
}

func toTestResultsResponse(testResults []runner.TestCaseResult) []testResultResponse {
func toTestResultsResponse(testResults []benchttp.TestCaseResult) []testResultResponse {
resp := make([]testResultResponse, len(testResults))
for i, r := range testResults {
resp[i] = testResultResponse{
Expand All @@ -104,7 +104,7 @@ func toTestResultsResponse(testResults []runner.TestCaseResult) []testResultResp
return resp
}

func toTimeStatsResponse(stats runner.MetricsTimeStats) timeStatsResponse {
func toTimeStatsResponse(stats benchttp.MetricsTimeStats) timeStatsResponse {
return timeStatsResponse{
Min: stats.Min,
Max: stats.Max,
Expand All @@ -116,7 +116,7 @@ func toTimeStatsResponse(stats runner.MetricsTimeStats) timeStatsResponse {
}
}

func toRequestEventTimesResponse(in map[string]runner.MetricsTimeStats) map[string]timeStatsResponse {
func toRequestEventTimesResponse(in map[string]benchttp.MetricsTimeStats) map[string]timeStatsResponse {
resp := map[string]timeStatsResponse{}
for k, v := range in {
resp[k] = toTimeStatsResponse(v)
Expand Down