refactor: pass experiment arguments using a struct (#983)
Closes https://github.com/ooni/probe/issues/2358.
This commit is contained in:
parent
c2ea0b4704
commit
a0dc65641d
|
@ -92,7 +92,12 @@ func (eaw *experimentAsyncWrapper) RunAsync(
|
|||
out := make(chan *model.ExperimentAsyncTestKeys)
|
||||
measurement := eaw.experiment.newMeasurement(input)
|
||||
start := time.Now()
|
||||
err := eaw.experiment.measurer.Run(ctx, eaw.session, measurement, eaw.callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: eaw.callbacks,
|
||||
Measurement: measurement,
|
||||
Session: eaw.session,
|
||||
}
|
||||
err := eaw.experiment.measurer.Run(ctx, args)
|
||||
stop := time.Now()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -249,10 +249,10 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements model.ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
tk := new(TestKeys)
|
||||
measurement.TestKeys = tk
|
||||
saver := &tracex.Saver{}
|
||||
|
|
|
@ -270,15 +270,15 @@ func TestMeasureWithCancelledContext(t *testing.T) {
|
|||
cancel() // cause failure
|
||||
measurement := new(model.Measurement)
|
||||
m := &Measurer{}
|
||||
err := m.Run(
|
||||
ctx,
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableHTTPClient: http.DefaultClient,
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
// See corresponding comment in Measurer.Run implementation to
|
||||
// understand why here it's correct to return nil.
|
||||
if !errors.Is(err, nil) {
|
||||
|
|
|
@ -120,10 +120,11 @@ var (
|
|||
)
|
||||
|
||||
// Run implements model.ExperimentSession.Run
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
// 1. fill the measurement with test keys
|
||||
tk := new(TestKeys)
|
||||
tk.Lookups = make(map[string]urlgetter.TestKeys)
|
||||
|
|
|
@ -56,12 +56,12 @@ func TestExperimentNameAndVersion(t *testing.T) {
|
|||
|
||||
func TestDNSCheckFailsWithoutInput(t *testing.T) {
|
||||
measurer := NewExperimentMeasurer(Config{Domain: "example.com"})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: new(model.Measurement),
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, ErrInputRequired) {
|
||||
t.Fatal("expected no input error")
|
||||
}
|
||||
|
@ -69,12 +69,12 @@ func TestDNSCheckFailsWithoutInput(t *testing.T) {
|
|||
|
||||
func TestDNSCheckFailsWithInvalidURL(t *testing.T) {
|
||||
measurer := NewExperimentMeasurer(Config{})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
&model.Measurement{Input: "Not a valid URL \x7f"},
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{Input: "Not a valid URL \x7f"},
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, ErrInvalidURL) {
|
||||
t.Fatal("expected invalid input error")
|
||||
}
|
||||
|
@ -82,12 +82,12 @@ func TestDNSCheckFailsWithInvalidURL(t *testing.T) {
|
|||
|
||||
func TestDNSCheckFailsWithUnsupportedProtocol(t *testing.T) {
|
||||
measurer := NewExperimentMeasurer(Config{})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
&model.Measurement{Input: "file://1.1.1.1"},
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{Input: "file://1.1.1.1"},
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, ErrUnsupportedURLScheme) {
|
||||
t.Fatal("expected unsupported scheme error")
|
||||
}
|
||||
|
@ -100,12 +100,12 @@ func TestWithCancelledContext(t *testing.T) {
|
|||
DefaultAddrs: "1.1.1.1 1.0.0.1",
|
||||
})
|
||||
measurement := &model.Measurement{Input: "dot://one.one.one.one"}
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
newsession(),
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -147,12 +147,12 @@ func TestDNSCheckValid(t *testing.T) {
|
|||
DefaultAddrs: "1.1.1.1 1.0.0.1",
|
||||
})
|
||||
measurement := model.Measurement{Input: "dot://one.one.one.one:853"}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
&measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err.Error())
|
||||
}
|
||||
|
@ -195,12 +195,12 @@ func TestDNSCheckWait(t *testing.T) {
|
|||
measurer := &Measurer{Endpoints: endpoints}
|
||||
run := func(input string) {
|
||||
measurement := model.Measurement{Input: model.MeasurementTarget(input)}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
&measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err.Error())
|
||||
}
|
||||
|
|
|
@ -85,12 +85,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
if measurement.Input == "" {
|
||||
return errNoInputProvided
|
||||
}
|
||||
|
|
|
@ -61,7 +61,12 @@ func TestMeasurer_run(t *testing.T) {
|
|||
MockableLogger: model.DiscardLogger,
|
||||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
return meas, m, err
|
||||
}
|
||||
|
||||
|
|
|
@ -57,10 +57,10 @@ func (m Measurer) ExperimentVersion() string {
|
|||
var ErrFailure = errors.New("mocked error")
|
||||
|
||||
// Run implements model.ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
var err error
|
||||
if m.config.ReturnError {
|
||||
err = ErrFailure
|
||||
|
|
|
@ -26,7 +26,12 @@ func TestSuccess(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(sess.Logger())
|
||||
measurement := new(model.Measurement)
|
||||
err := m.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -47,7 +52,12 @@ func TestFailure(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(sess.Logger())
|
||||
err := m.Run(ctx, sess, new(model.Measurement), callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: new(model.Measurement),
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if !errors.Is(err, example.ErrFailure) {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
|
|
|
@ -157,10 +157,10 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
urlgetter.RegisterExtensions(measurement)
|
||||
|
|
|
@ -35,7 +35,12 @@ func TestSuccess(t *testing.T) {
|
|||
sess := newsession(t)
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -97,7 +102,12 @@ func TestWithCancelledContext(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -90,10 +90,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
urlgetter.RegisterExtensions(measurement)
|
||||
|
|
|
@ -45,7 +45,12 @@ func TestSuccess(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -153,7 +158,12 @@ func TestCancelledContext(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -259,7 +269,12 @@ func TestNoHelpers(t *testing.T) {
|
|||
sess := &mockable.Session{}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hhfm.ErrNoAvailableTestHelpers) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -309,7 +324,12 @@ func TestNoActualHelpersInList(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hhfm.ErrNoAvailableTestHelpers) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -362,7 +382,12 @@ func TestWrongTestHelperType(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hhfm.ErrInvalidHelperType) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -415,7 +440,12 @@ func TestNewRequestFailure(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -472,7 +502,12 @@ func TestInvalidJSONBody(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -78,10 +78,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
tk := new(TestKeys)
|
||||
measurement.TestKeys = tk
|
||||
if len(m.Methods) < 1 {
|
||||
|
|
|
@ -42,7 +42,12 @@ func TestSuccess(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -91,7 +96,12 @@ func TestCancelledContext(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -190,7 +200,12 @@ func TestWithFakeMethods(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -251,7 +266,12 @@ func TestWithNoMethods(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hirl.ErrNoMeasurementMethod) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -279,7 +299,12 @@ func TestNoHelpers(t *testing.T) {
|
|||
sess := &mockable.Session{}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hirl.ErrNoAvailableTestHelpers) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -311,7 +336,12 @@ func TestNoActualHelperInList(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hirl.ErrNoAvailableTestHelpers) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -346,7 +376,12 @@ func TestWrongTestHelperType(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, hirl.ErrInvalidHelperType) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
|
|
@ -46,12 +46,10 @@ func (m *Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
if measurement.Input == "" {
|
||||
return errors.New("experiment requires input")
|
||||
}
|
||||
|
|
|
@ -30,12 +30,12 @@ func TestMeasurerMeasureNoMeasurementInput(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{
|
||||
TestHelperURL: "http://www.google.com",
|
||||
})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{},
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err == nil || err.Error() != "experiment requires input" {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -44,12 +44,12 @@ func TestMeasurerMeasureNoMeasurementInput(t *testing.T) {
|
|||
func TestMeasurerMeasureNoTestHelper(t *testing.T) {
|
||||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := &model.Measurement{Input: "x.org"}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -75,12 +75,12 @@ func TestRunnerHTTPSetHostHeader(t *testing.T) {
|
|||
measurement := &model.Measurement{
|
||||
Input: "x.org",
|
||||
}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if host != "x.org" {
|
||||
t.Fatal("not the host we expected")
|
||||
}
|
||||
|
|
|
@ -210,10 +210,10 @@ func (m *Measurer) doUpload(
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
tk := new(TestKeys)
|
||||
tk.Protocol = 7
|
||||
measurement.TestKeys = tk
|
||||
|
|
|
@ -84,7 +84,12 @@ func TestRunWithCancelledContext(t *testing.T) {
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // immediately cancel
|
||||
meas := &model.Measurement{}
|
||||
err := m.Run(ctx, sess, meas, model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
// Here we get nil because we still want to submit this measurement
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatal("not the error we expected")
|
||||
|
@ -104,15 +109,15 @@ func TestGood(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
measurer := NewExperimentMeasurer(Config{})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableHTTPClient: http.DefaultClient,
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -133,15 +138,15 @@ func TestFailDownload(t *testing.T) {
|
|||
cancel()
|
||||
}
|
||||
meas := &model.Measurement{}
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: meas,
|
||||
Session: &mockable.Session{
|
||||
MockableHTTPClient: http.DefaultClient,
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
meas,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
// We expect a nil failure here because we want to submit anyway
|
||||
// a measurement that failed to connect to m-lab.
|
||||
if err != nil {
|
||||
|
@ -164,15 +169,15 @@ func TestFailUpload(t *testing.T) {
|
|||
cancel()
|
||||
}
|
||||
meas := &model.Measurement{}
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: meas,
|
||||
Session: &mockable.Session{
|
||||
MockableHTTPClient: http.DefaultClient,
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
meas,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
// Here we expect a nil error because we want to submit this measurement
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -197,15 +202,15 @@ func TestDownloadJSONUnmarshalFail(t *testing.T) {
|
|||
seenError = true
|
||||
return expected
|
||||
}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{},
|
||||
Session: &mockable.Session{
|
||||
MockableHTTPClient: http.DefaultClient,
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -38,12 +38,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
// TODO(DecFox): Replace the localhost deployment with an OONI testhelper
|
||||
// Ensure that we only do this once we have a deployed testhelper
|
||||
testhelper := "http://127.0.0.1"
|
||||
|
|
|
@ -29,7 +29,12 @@ func TestMeasurer_run(t *testing.T) {
|
|||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
ctx := context.Background()
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -66,10 +66,10 @@ func (m *Measurer) printprogress(
|
|||
}
|
||||
|
||||
// Run runs the measurement
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
const maxruntime = 300
|
||||
ctx, cancel := context.WithTimeout(ctx, maxruntime*time.Second)
|
||||
var (
|
||||
|
|
|
@ -33,8 +33,12 @@ func TestRunWithCancelledContext(t *testing.T) {
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(ctx, newfakesession(), measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newfakesession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit the measurement
|
||||
t.Fatal("expected another error here")
|
||||
}
|
||||
|
@ -64,8 +68,12 @@ func TestRunWithCustomInputAndCancelledContext(t *testing.T) {
|
|||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // fail immediately
|
||||
err := measurer.Run(ctx, newfakesession(), measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newfakesession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit the measurement
|
||||
t.Fatal("expected another error here")
|
||||
}
|
||||
|
@ -84,7 +92,12 @@ func TestRunWillPrintSomethingWithCancelledContext(t *testing.T) {
|
|||
cancel() // fail after we've given the printer a chance to run
|
||||
}
|
||||
observer := observerCallbacks{progress: &atomicx.Int64{}}
|
||||
err := measurer.Run(ctx, newfakesession(), measurement, observer)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: observer,
|
||||
Measurement: measurement,
|
||||
Session: newfakesession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit the measurement
|
||||
t.Fatal("expected another error here")
|
||||
}
|
||||
|
|
|
@ -221,12 +221,11 @@ func (m *Measurer) receiver(
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
host := string(measurement.Input)
|
||||
// allow URL input
|
||||
if u, err := url.ParseRequestURI(host); err == nil {
|
||||
|
|
|
@ -33,8 +33,12 @@ func TestInvalidHost(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("a.a.a.a")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
|
@ -53,8 +57,12 @@ func TestURLInput(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("https://google.com/")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error")
|
||||
}
|
||||
|
@ -73,8 +81,12 @@ func TestSuccess(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("google.com")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal("did not expect an error here")
|
||||
}
|
||||
|
@ -117,8 +129,12 @@ func TestWithCancelledContext(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
err := measurer.Run(ctx, sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal("did not expect an error here")
|
||||
}
|
||||
|
@ -138,8 +154,12 @@ func TestListenFails(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("google.com")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
|
@ -182,8 +202,12 @@ func TestWriteFails(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("google.com")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error")
|
||||
}
|
||||
|
@ -239,8 +263,12 @@ func TestReadFails(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("google.com")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error")
|
||||
}
|
||||
|
@ -271,8 +299,12 @@ func TestNoResponse(t *testing.T) {
|
|||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("ooni.org")
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
err := measurer.Run(context.Background(), sess, measurement,
|
||||
model.NewPrinterCallbacks(log.Log))
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal("did not expect an error here")
|
||||
}
|
||||
|
|
|
@ -175,8 +175,11 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 90*time.Second)
|
||||
defer cancel()
|
||||
testkeys := NewTestKeys()
|
||||
|
|
|
@ -100,7 +100,7 @@ const (
|
|||
"cert": "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||
"iatMode": "0"
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"type":"openvpn",
|
||||
"protocols":[
|
||||
|
@ -328,7 +328,12 @@ func TestInvalidCaCert(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -599,7 +604,12 @@ func TestMissingTransport(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err = measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err = measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -790,14 +800,14 @@ func runDefaultMockTest(t *testing.T, multiGetter urlgetter.MultiGetter) *model.
|
|||
}
|
||||
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -21,5 +21,10 @@ func (m *dnsCheckMain) do(ctx context.Context, input StructuredInput,
|
|||
measurement.TestName = exp.ExperimentName()
|
||||
measurement.TestVersion = exp.ExperimentVersion()
|
||||
measurement.Input = model.MeasurementTarget(input.Input)
|
||||
return exp.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
return exp.Run(ctx, args)
|
||||
}
|
||||
|
|
|
@ -46,10 +46,10 @@ type StructuredInput struct {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.ExperimentVersion.
|
||||
func (Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
var input StructuredInput
|
||||
if err := json.Unmarshal([]byte(measurement.Input), &input); err != nil {
|
||||
return err
|
||||
|
|
|
@ -31,7 +31,12 @@ func TestRunDNSCheckWithCancelledContext(t *testing.T) {
|
|||
cancel() // fail immediately
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
// TODO(bassosimone): here we could improve the tests by checking
|
||||
// whether the result makes sense for a cancelled context.
|
||||
if err != nil {
|
||||
|
@ -62,7 +67,12 @@ func TestRunURLGetterWithCancelledContext(t *testing.T) {
|
|||
cancel() // fail immediately
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil { // here we expected nil b/c we want to submit the measurement
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -86,7 +96,12 @@ func TestRunWithInvalidJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err == nil || err.Error() != "invalid character '}' looking for beginning of value" {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
}
|
||||
|
@ -100,7 +115,12 @@ func TestRunWithUnknownExperiment(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err == nil || err.Error() != "no such experiment: antani" {
|
||||
t.Fatalf("not the error we expected: %+v", err)
|
||||
}
|
||||
|
|
|
@ -18,5 +18,10 @@ func (m *urlGetterMain) do(ctx context.Context, input StructuredInput,
|
|||
measurement.TestName = exp.ExperimentName()
|
||||
measurement.TestVersion = exp.ExperimentVersion()
|
||||
measurement.Input = model.MeasurementTarget(input.Input)
|
||||
return exp.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
return exp.Run(ctx, args)
|
||||
}
|
||||
|
|
|
@ -141,8 +141,10 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run
|
||||
func (m Measurer) Run(ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
urlgetter.RegisterExtensions(measurement)
|
||||
|
|
|
@ -25,14 +25,14 @@ func TestNewExperimentMeasurer(t *testing.T) {
|
|||
func TestGood(t *testing.T) {
|
||||
measurer := signal.NewExperimentMeasurer(signal.Config{})
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -103,14 +103,14 @@ func TestBadSignalCA(t *testing.T) {
|
|||
SignalCA: "INVALIDCA",
|
||||
})
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err.Error() != "AppendCertsFromPEM failed" {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
|
|
@ -112,12 +112,11 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
if measurement.Input == "" {
|
||||
return errNoInputProvided
|
||||
}
|
||||
|
|
|
@ -65,7 +65,12 @@ func TestMeasurer_run(t *testing.T) {
|
|||
MockableLogger: model.DiscardLogger,
|
||||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
return meas, m, err
|
||||
}
|
||||
|
||||
|
|
|
@ -233,12 +233,10 @@ func maybeURLToSNI(input model.MeasurementTarget) (model.MeasurementTarget, erro
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
m.mu.Lock()
|
||||
if m.cache == nil {
|
||||
m.cache = make(map[string]Subresult)
|
||||
|
|
|
@ -116,12 +116,12 @@ func TestMeasurerMeasureNoMeasurementInput(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{
|
||||
ControlSNI: "example.com",
|
||||
})
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
newsession(),
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{},
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err.Error() != "Experiment requires measurement.Input" {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -136,12 +136,12 @@ func TestMeasurerMeasureWithInvalidInput(t *testing.T) {
|
|||
measurement := &model.Measurement{
|
||||
Input: "\t",
|
||||
}
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
newsession(),
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
|
@ -156,12 +156,12 @@ func TestMeasurerMeasureWithCancelledContext(t *testing.T) {
|
|||
measurement := &model.Measurement{
|
||||
Input: "kernel.org",
|
||||
}
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
newsession(),
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: newsession(),
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -73,10 +73,10 @@ var errStunMissingPortInURL = errors.New("stun: missing port in URL")
|
|||
var errUnsupportedURLScheme = errors.New("stun: unsupported URL scheme")
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
tk := new(TestKeys)
|
||||
measurement.TestKeys = tk
|
||||
registerExtensions(measurement)
|
||||
|
|
|
@ -32,12 +32,12 @@ func TestMeasurerExperimentNameVersion(t *testing.T) {
|
|||
func TestRunWithoutInput(t *testing.T) {
|
||||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, errStunMissingInput) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ func TestRunWithInvalidURL(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("\t") // <- invalid URL
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
@ -62,12 +62,12 @@ func TestRunWithNoPort(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("stun://stun.ekiga.net")
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, errStunMissingPortInURL) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
@ -77,12 +77,12 @@ func TestRunWithUnsupportedURLScheme(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget("https://stun.ekiga.net:3478")
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, errUnsupportedURLScheme) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
@ -92,14 +92,14 @@ func TestRunWithInput(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget(defaultInput)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: model.DiscardLogger,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -124,14 +124,14 @@ func TestCancelledContext(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget(defaultInput)
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: model.DiscardLogger,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
@ -166,14 +166,14 @@ func TestNewClientFailure(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(*config)
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget(defaultInput)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: model.DiscardLogger,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -202,14 +202,14 @@ func TestStartFailure(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(*config)
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget(defaultInput)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: model.DiscardLogger,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -242,14 +242,14 @@ func TestReadFailure(t *testing.T) {
|
|||
measurer := NewExperimentMeasurer(*config)
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = model.MeasurementTarget(defaultInput)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: model.DiscardLogger,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
|
|
@ -82,12 +82,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
if measurement.Input == "" {
|
||||
return errNoInputProvided
|
||||
}
|
||||
|
|
|
@ -51,7 +51,12 @@ func TestMeasurer_run(t *testing.T) {
|
|||
MockableLogger: model.DiscardLogger,
|
||||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
return meas, m, err
|
||||
}
|
||||
|
||||
|
|
|
@ -101,8 +101,11 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run
|
||||
func (m Measurer) Run(ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
urlgetter.RegisterExtensions(measurement)
|
||||
|
|
|
@ -28,14 +28,14 @@ func TestNewExperimentMeasurer(t *testing.T) {
|
|||
func TestGood(t *testing.T) {
|
||||
measurer := telegram.NewExperimentMeasurer(telegram.Config{})
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -297,7 +297,12 @@ func TestWeConfigureWebChecksToFailOnHTTPError(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
if err := measurer.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := measurer.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if called.Load() < 1 {
|
||||
|
|
|
@ -52,12 +52,10 @@ var (
|
|||
)
|
||||
|
||||
// // Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
if measurement.Input == "" {
|
||||
return errNoInputProvided
|
||||
}
|
||||
|
|
|
@ -38,7 +38,12 @@ func TestMeasurer_input_failure(t *testing.T) {
|
|||
},
|
||||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
return meas, m, err
|
||||
}
|
||||
|
||||
|
|
|
@ -112,12 +112,10 @@ var (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
if measurement.Input == "" {
|
||||
return errNoInputProvided
|
||||
}
|
||||
|
|
|
@ -58,7 +58,12 @@ func TestMeasurer_run(t *testing.T) {
|
|||
MockableLogger: model.DiscardLogger,
|
||||
}
|
||||
callbacks := model.NewPrinterCallbacks(model.DiscardLogger)
|
||||
err := m.Run(ctx, sess, meas, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: meas,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
return meas, m, err
|
||||
}
|
||||
|
||||
|
|
|
@ -78,12 +78,11 @@ var allMethods = []method{{
|
|||
}}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
// TODO(bassosimone): wondering whether this experiment should
|
||||
// actually be merged with sniblocking instead?
|
||||
tk := new(TestKeys)
|
||||
|
|
|
@ -27,12 +27,12 @@ func TestRunWithExplicitSNI(t *testing.T) {
|
|||
})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = "8.8.8.8:853"
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ func TestRunWithImplicitSNI(t *testing.T) {
|
|||
measurer := tlstool.NewExperimentMeasurer(tlstool.Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = "dns.google:853"
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -60,12 +60,12 @@ func TestRunWithCancelledContext(t *testing.T) {
|
|||
measurer := tlstool.NewExperimentMeasurer(tlstool.Config{})
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = "dns.google:853"
|
||||
err := measurer.Run(
|
||||
ctx,
|
||||
&mockable.Session{},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -166,12 +166,10 @@ func (m *Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
targets, err := m.gimmeTargets(ctx, sess)
|
||||
if err != nil {
|
||||
return err // fail the measurement if we cannot get any target
|
||||
|
|
|
@ -36,14 +36,14 @@ func TestMeasurerMeasureFetchTorTargetsError(t *testing.T) {
|
|||
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
|
||||
return nil, expected
|
||||
}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{},
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ func TestMeasurerMeasureFetchTorTargetsEmptyList(t *testing.T) {
|
|||
return nil, nil
|
||||
}
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -79,14 +79,14 @@ func TestMeasurerMeasureGoodWithMockedOrchestra(t *testing.T) {
|
|||
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
|
||||
return nil, nil
|
||||
}
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
&mockable.Session{
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: &model.Measurement{},
|
||||
Session: &mockable.Session{
|
||||
MockableLogger: log.Log,
|
||||
},
|
||||
new(model.Measurement),
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -99,12 +99,12 @@ func TestMeasurerMeasureGood(t *testing.T) {
|
|||
measurer := NewMeasurer(Config{})
|
||||
sess := newsession()
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
sess,
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -142,12 +142,12 @@ func TestMeasurerMeasureSanitiseOutput(t *testing.T) {
|
|||
key: staticPrivateTestingTarget,
|
||||
}
|
||||
measurement := new(model.Measurement)
|
||||
err := measurer.Run(
|
||||
context.Background(),
|
||||
sess,
|
||||
measurement,
|
||||
model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(context.Background(), args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,12 @@ func TestRunWithExistingTor(t *testing.T) {
|
|||
MockableLogger: log.Log,
|
||||
MockableTempDir: tempdir,
|
||||
}
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,10 +124,10 @@ const maxRuntime = 600 * time.Second
|
|||
// set the relevant OONI error inside of the measurement and
|
||||
// return nil. This is important because the caller may not submit
|
||||
// the measurement if this method returns an error.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
ptl, sfdialer, err := m.setup(ctx, sess.Logger())
|
||||
if err != nil {
|
||||
// we cannot setup the experiment
|
||||
|
|
|
@ -47,7 +47,12 @@ func TestFailureWithInvalidRendezvousMethod(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
err := m.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if !errors.Is(err, ptx.ErrSnowflakeNoSuchRendezvousMethod) {
|
||||
t.Fatal("unexpected error", err)
|
||||
}
|
||||
|
@ -70,7 +75,12 @@ func TestFailureToStartPTXListener(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); !errors.Is(err, expected) {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
if tk := measurement.TestKeys; tk != nil {
|
||||
|
@ -108,7 +118,12 @@ func TestSuccessWithMockedTunnelStart(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if called.Load() != 1 {
|
||||
|
@ -168,7 +183,12 @@ func TestWithCancelledContext(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*TestKeys)
|
||||
|
@ -231,7 +251,12 @@ func TestFailureToStartTunnel(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*TestKeys)
|
||||
|
|
|
@ -97,10 +97,10 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements model.ExperimentSession.Run
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
// When using the urlgetter experiment directly, there is a nonconfigurable
|
||||
// default timeout that applies. When urlgetter is used as a library, it's
|
||||
// instead the responsibility of the user of urlgetter to set timeouts. Note
|
||||
|
|
|
@ -23,10 +23,12 @@ func TestMeasurer(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = "https://www.google.com"
|
||||
err := m.Run(
|
||||
ctx, &mockable.Session{},
|
||||
measurement, model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit the measurement
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
@ -60,10 +62,12 @@ func TestMeasurerDNSCache(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
measurement.Input = "https://www.google.com"
|
||||
err := m.Run(
|
||||
ctx, &mockable.Session{},
|
||||
measurement, model.NewPrinterCallbacks(log.Log),
|
||||
)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: model.NewPrinterCallbacks(log.Log),
|
||||
Measurement: measurement,
|
||||
Session: &mockable.Session{},
|
||||
}
|
||||
err := m.Run(ctx, args)
|
||||
if !errors.Is(err, nil) { // nil because we want to submit the measurement
|
||||
t.Fatal("not the error we expected")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,12 @@ func TestRunWithExistingTor(t *testing.T) {
|
|||
MockableLogger: log.Log,
|
||||
MockableTempDir: tempdir,
|
||||
}
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,10 +106,10 @@ const maxRuntime = 200 * time.Second
|
|||
// set the relevant OONI error inside of the measurement and
|
||||
// return nil. This is important because the caller may not submit
|
||||
// the measurement if this method returns an error.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
m.registerExtensions(measurement)
|
||||
start := time.Now()
|
||||
ctx, cancel := context.WithTimeout(ctx, maxRuntime)
|
||||
|
|
|
@ -59,7 +59,12 @@ func TestSuccessWithMockedTunnelStart(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if called.Load() != 1 {
|
||||
|
@ -113,7 +118,12 @@ func TestWithCancelledContext(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*TestKeys)
|
||||
|
@ -170,7 +180,12 @@ func TestFailureToStartTunnel(t *testing.T) {
|
|||
callbacks := &model.PrinterCallbacks{
|
||||
Logger: model.DiscardLogger,
|
||||
}
|
||||
if err := m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := m.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*TestKeys)
|
||||
|
|
|
@ -121,12 +121,11 @@ const (
|
|||
)
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context,
|
||||
sess model.ExperimentSession,
|
||||
measurement *model.Measurement,
|
||||
callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
tk := new(TestKeys)
|
||||
|
|
|
@ -37,7 +37,12 @@ func TestSuccess(t *testing.T) {
|
|||
sess := newsession(t, true)
|
||||
measurement := &model.Measurement{Input: "http://www.example.com"}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -65,7 +70,12 @@ func TestMeasureWithCancelledContext(t *testing.T) {
|
|||
sess := newsession(t, true)
|
||||
measurement := &model.Measurement{Input: "http://www.example.com"}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
if err := measurer.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := measurer.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*webconnectivity.TestKeys)
|
||||
|
@ -99,7 +109,12 @@ func TestMeasureWithNoInput(t *testing.T) {
|
|||
sess := newsession(t, true)
|
||||
measurement := &model.Measurement{Input: ""}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, webconnectivity.ErrNoInput) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -127,7 +142,12 @@ func TestMeasureWithInputNotBeingAnURL(t *testing.T) {
|
|||
sess := newsession(t, true)
|
||||
measurement := &model.Measurement{Input: "\t\t\t\t\t\t"}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, webconnectivity.ErrInputIsNotAnURL) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -155,7 +175,12 @@ func TestMeasureWithUnsupportedInput(t *testing.T) {
|
|||
sess := newsession(t, true)
|
||||
measurement := &model.Measurement{Input: "dnslookup://example.com"}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, webconnectivity.ErrUnsupportedInput) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -183,7 +208,12 @@ func TestMeasureWithNoAvailableTestHelpers(t *testing.T) {
|
|||
sess := newsession(t, false)
|
||||
measurement := &model.Measurement{Input: "https://www.example.com"}
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if !errors.Is(err, webconnectivity.ErrNoAvailableTestHelpers) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -154,10 +154,11 @@ func (m Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run
|
||||
func (m Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
urlgetter.RegisterExtensions(measurement)
|
||||
|
|
|
@ -35,7 +35,12 @@ func TestSuccess(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -70,7 +75,12 @@ func TestFailureAllEndpoints(t *testing.T) {
|
|||
sess := &mockable.Session{MockableLogger: log.Log}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
err := measurer.Run(ctx, sess, measurement, callbacks)
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
err := measurer.Run(ctx, args)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -598,7 +608,12 @@ func TestWeConfigureWebChecksCorrectly(t *testing.T) {
|
|||
}
|
||||
measurement := new(model.Measurement)
|
||||
callbacks := model.NewPrinterCallbacks(log.Log)
|
||||
if err := measurer.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err := measurer.Run(ctx, args); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if called.Load() != 263 {
|
||||
|
|
|
@ -475,10 +475,7 @@ func (am *antaniMeasurer) ExperimentVersion() string {
|
|||
return "0.1.1"
|
||||
}
|
||||
|
||||
func (am *antaniMeasurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (am *antaniMeasurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,13 @@ func (m *Measurer) ExperimentVersion() string {
|
|||
}
|
||||
|
||||
// Run implements model.ExperimentMeasurer.
|
||||
func (m *Measurer) Run(ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
// Reminder: when this function returns an error, the measurement result
|
||||
// WILL NOT be submitted to the OONI backend. You SHOULD only return an error
|
||||
// for fundamental errors (e.g., the input is invalid or missing).
|
||||
_ = args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
|
||||
// make sure we have a cancellable context such that we can stop any
|
||||
// goroutine running in the background (e.g., priority.go's ones)
|
||||
|
|
|
@ -117,6 +117,19 @@ func (d PrinterCallbacks) OnProgress(percentage float64, message string) {
|
|||
d.Logger.Infof("[%5.1f%%] %s", percentage*100, message)
|
||||
}
|
||||
|
||||
// ExperimentArgs contains the arguments passed to an experiment.
|
||||
type ExperimentArgs struct {
|
||||
// Callbacks contains MANDATORY experiment callbacks.
|
||||
Callbacks ExperimentCallbacks
|
||||
|
||||
// Measurement is the MANDATORY measurement in which the experiment
|
||||
// must write the results of the measurement.
|
||||
Measurement *Measurement
|
||||
|
||||
// Session is the MANDATORY session the experiment can use.
|
||||
Session ExperimentSession
|
||||
}
|
||||
|
||||
// ExperimentMeasurer is the interface that allows to run a
|
||||
// measurement for a specific experiment.
|
||||
type ExperimentMeasurer interface {
|
||||
|
@ -133,10 +146,7 @@ type ExperimentMeasurer interface {
|
|||
// set the relevant OONI error inside of the measurement and
|
||||
// return nil. This is important because the caller WILL NOT submit
|
||||
// the measurement if this method returns an error.
|
||||
Run(
|
||||
ctx context.Context, sess ExperimentSession,
|
||||
measurement *Measurement, callbacks ExperimentCallbacks,
|
||||
) error
|
||||
Run(ctx context.Context, args *ExperimentArgs) error
|
||||
|
||||
// GetSummaryKeys returns summary keys expected by ooni/probe-cli.
|
||||
GetSummaryKeys(*Measurement) (interface{}, error)
|
||||
|
|
|
@ -211,7 +211,12 @@ need any fancy context and we pass a `context.Background` to `Run`.
|
|||
|
||||
```Go
|
||||
ctx := context.Background()
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
log.WithError(err).Fatal("torsf experiment failed")
|
||||
}
|
||||
```
|
||||
|
|
|
@ -212,7 +212,12 @@ func main() {
|
|||
//
|
||||
// ```Go
|
||||
ctx := context.Background()
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
log.WithError(err).Fatal("torsf experiment failed")
|
||||
}
|
||||
// ```
|
||||
|
|
|
@ -117,10 +117,10 @@ chapters, finally, we will modify this function until it is a
|
|||
minimal implementation of the `torsf` experiment.
|
||||
|
||||
```Go
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
_ = args.Measurement
|
||||
sess := args.Session
|
||||
```
|
||||
As you can see, this is just a stub implementation that sleeps
|
||||
for one second and prints a logging message.
|
||||
|
|
|
@ -54,7 +54,12 @@ func main() {
|
|||
MockableLogger: log.Log,
|
||||
MockableTempDir: tempdir,
|
||||
}
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
log.WithError(err).Fatal("torsf experiment failed")
|
||||
}
|
||||
data, err := json.Marshal(measurement)
|
||||
|
|
|
@ -93,10 +93,10 @@ func (m *Measurer) ExperimentVersion() string {
|
|||
// minimal implementation of the `torsf` experiment.
|
||||
//
|
||||
// ```Go
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
_ = args.Callbacks
|
||||
_ = args.Measurement
|
||||
sess := args.Session
|
||||
// ```
|
||||
// As you can see, this is just a stub implementation that sleeps
|
||||
// for one second and prints a logging message.
|
||||
|
|
|
@ -32,10 +32,10 @@ print periodic updates via the `callbacks`. We will defer the
|
|||
real work to a private function called `run`.
|
||||
|
||||
```Go
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
```
|
||||
|
||||
Let's create an instance of `TestKeys` and let's modify
|
||||
|
|
|
@ -28,7 +28,12 @@ func main() {
|
|||
MockableLogger: log.Log,
|
||||
MockableTempDir: tempdir,
|
||||
}
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
log.WithError(err).Fatal("torsf experiment failed")
|
||||
}
|
||||
data, err := json.Marshal(measurement)
|
||||
|
|
|
@ -65,10 +65,10 @@ type TestKeys struct {
|
|||
// real work to a private function called `run`.
|
||||
//
|
||||
// ```Go
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
// ```
|
||||
//
|
||||
// Let's create an instance of `TestKeys` and let's modify
|
||||
|
|
|
@ -28,7 +28,12 @@ func main() {
|
|||
MockableLogger: log.Log,
|
||||
MockableTempDir: tempdir,
|
||||
}
|
||||
if err = m.Run(ctx, sess, measurement, callbacks); err != nil {
|
||||
args := &model.ExperimentArgs{
|
||||
Callbacks: callbacks,
|
||||
Measurement: measurement,
|
||||
Session: sess,
|
||||
}
|
||||
if err = m.Run(ctx, args); err != nil {
|
||||
log.WithError(err).Fatal("torsf experiment failed")
|
||||
}
|
||||
data, err := json.Marshal(measurement)
|
||||
|
|
|
@ -99,10 +99,10 @@ type TestKeys struct {
|
|||
}
|
||||
|
||||
// Run implements ExperimentMeasurer.Run.
|
||||
func (m *Measurer) Run(
|
||||
ctx context.Context, sess model.ExperimentSession,
|
||||
measurement *model.Measurement, callbacks model.ExperimentCallbacks,
|
||||
) error {
|
||||
func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
|
||||
callbacks := args.Callbacks
|
||||
measurement := args.Measurement
|
||||
sess := args.Session
|
||||
testkeys := &TestKeys{}
|
||||
measurement.TestKeys = testkeys
|
||||
start := time.Now()
|
||||
|
|
Loading…
Reference in New Issue
Block a user