Skip to content

Commit

Permalink
refactor(webconnectivityqa): use httpclientx (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone authored May 6, 2024
1 parent 7ab645d commit 3222564
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestMeasureWithCancelledContext(t *testing.T) {
}
tk := measurement.TestKeys.(*webconnectivity.TestKeys)
if *tk.ControlFailure != netxlite.FailureInterrupted {
t.Fatal("unexpected control_failure")
t.Fatal("unexpected control_failure", *tk.ControlFailure)
}
if *tk.DNSExperimentFailure != netxlite.FailureInterrupted {
t.Fatal("unexpected dns_experiment_failure")
Expand Down
19 changes: 11 additions & 8 deletions internal/webconnectivityalgo/calltesthelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package webconnectivityalgo
import (
"context"

"github.com/ooni/probe-cli/v3/internal/httpapi"
"github.com/ooni/probe-cli/v3/internal/httpclientx"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/ooapi"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)

Expand All @@ -27,14 +26,18 @@ func CallWebConnectivityTestHelper(ctx context.Context, creq *model.THRequest,
return nil, 0, model.ErrNoAvailableTestHelpers
}

// initialize a sequence caller for invoking the THs in FIFO order
seqCaller := httpapi.NewSequenceCaller(
ooapi.NewDescriptorTH(creq),
httpapi.NewEndpointList(sess.DefaultHTTPClient(), sess.Logger(), sess.UserAgent(), testhelpers...)...,
// create overlapped state for performing overlapped HTTP calls
overlapped := httpclientx.NewOverlappedPostJSON[*model.THRequest, *model.THResponse](
creq, &httpclientx.Config{
Authorization: "", // not needed
Client: sess.DefaultHTTPClient(),
Logger: sess.Logger(),
UserAgent: sess.UserAgent(),
},
)

// issue the composed call proper and obtain a response and an index or an error
cresp, idx, err := seqCaller.Call(ctx)
// perform the overlapped HTTP API calls
cresp, idx, err := overlapped.Run(ctx, httpclientx.NewEndpointFromModelOOAPIServices(testhelpers...)...)

// handle the case where all test helpers failed
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/webconnectivityqa/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func controlFailureWithSuccessfulHTTPWebsite() *TestCase {
},
ExpectErr: false,
ExpectTestKeys: &TestKeys{
ControlFailure: "unknown_failure: httpapi: all endpoints failed: [ connection_reset; connection_reset; connection_reset; connection_reset;]",
ControlFailure: "connection_reset",
XStatus: 8, // StatusAnomalyControlUnreachable
Accessible: nil,
Blocking: nil,
Expand Down Expand Up @@ -88,7 +88,7 @@ func controlFailureWithSuccessfulHTTPSWebsite() *TestCase {
},
ExpectErr: false,
ExpectTestKeys: &TestKeys{
ControlFailure: "unknown_failure: httpapi: all endpoints failed: [ connection_reset; connection_reset; connection_reset; connection_reset;]",
ControlFailure: "connection_reset",
XStatus: 1, // StatusSuccessSecure
XBlockingFlags: 32, // AnalysisBlockingFlagSuccess
XNullNullFlags: 8, // AnalysisFlagNullNullSuccessfulHTTPS
Expand Down

0 comments on commit 3222564

Please sign in to comment.