-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dslx): collect speed samples (#1167)
Part of ooni/probe#2493
- Loading branch information
1 parent
7b88651
commit e00ba0e
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package dslx | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/model" | ||
"github.com/ooni/probe-cli/v3/internal/randx" | ||
"github.com/ooni/probe-cli/v3/internal/throttling" | ||
) | ||
|
||
func TestMakeSureWeCollectSpeedSamples(t *testing.T) { | ||
const ( | ||
chunkSize = 1 << 14 | ||
repetitions = 10 | ||
totalBody = repetitions * chunkSize | ||
traceID = 14 | ||
) | ||
|
||
// create a testing server that sleeps after each send for a given number of sends | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
chunk := []byte(randx.Letters(chunkSize)) | ||
for idx := 0; idx < repetitions; idx++ { | ||
w.Write(chunk) | ||
time.Sleep(250 * time.Millisecond) | ||
} | ||
})) | ||
defer server.Close() | ||
|
||
// instantiate a connection pool | ||
pool := &ConnPool{} | ||
defer pool.Close() | ||
|
||
// create a measuring function | ||
f0 := Compose3( | ||
TCPConnect(pool), | ||
HTTPTransportTCP(), | ||
HTTPRequest(), | ||
) | ||
|
||
// create the endpoint to measure | ||
epnt := &Endpoint{ | ||
Address: server.Listener.Addr().String(), | ||
Domain: "", | ||
IDGenerator: &atomic.Int64{}, | ||
Logger: model.DiscardLogger, | ||
Network: "tcp", | ||
Tags: []string{}, | ||
ZeroTime: time.Now(), | ||
} | ||
|
||
// measure the endpoint | ||
result := f0.Apply(context.Background(), epnt) | ||
|
||
// get observations | ||
observations := ExtractObservations(result) | ||
|
||
// process the network events and check for summary | ||
var foundSummary bool | ||
for _, entry := range observations { | ||
for _, ev := range entry.NetworkEvents { | ||
if ev.Operation == throttling.BytesReceivedCumulativeOperation { | ||
t.Log(ev) | ||
foundSummary = true | ||
} | ||
} | ||
} | ||
if !foundSummary { | ||
t.Fatal("did not find the summary") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters