Refactor the list measurements function to make use of nested queries (#662)

* Refactor the list measurements function to make use of nested queries

With a dataset of 1489 test, the ooniprobe list command went from
taking 17.27s to run, to requiring 0.17s or a 100x speed boost

See https://github.com/ooni/probe/issues/1966

* Remove dead code from actions

* Improve the tests for the ListResults function

* Add test for AnomalyCount

* Add more documentation about the merging of the test_keys
This commit is contained in:
Arturo Filastò 2022-01-14 11:24:43 +01:00 committed by GitHub
commit a884481b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 80 deletions

View file

@ -87,17 +87,18 @@ func TestMeasurementWorkflow(t *testing.T) {
t.Fatal(err)
}
m1.IsUploaded = true
m1.IsAnomaly = sql.NullBool{Valid: true, Bool: false}
err = sess.Collection("measurements").Find("measurement_id", m1.ID).Update(m1)
if err != nil {
t.Fatal(err)
}
var m2 Measurement
err = sess.Collection("measurements").Find("measurement_id", m1.ID).One(&m2)
m2, err := CreateMeasurement(sess, reportID, testName, msmtFilePath, 0, resultID, urlID)
if err != nil {
t.Fatal(err)
}
m2.IsUploaded = false
m2.IsAnomaly = sql.NullBool{Valid: true, Bool: true}
err = sess.Collection("measurements").Find("measurement_id", m2.ID).Update(m2)
if err != nil {
t.Fatal(err)
@ -110,6 +111,7 @@ func TestMeasurementWorkflow(t *testing.T) {
if err != nil {
t.Fatal(err)
}
result.Finished(sess)
var r Result
err = sess.Collection("measurements").Find("result_id", result.ID).One(&r)
@ -125,11 +127,18 @@ func TestMeasurementWorkflow(t *testing.T) {
t.Fatal(err)
}
if len(incomplete) != 1 {
t.Error("there should be 1 incomplete measurement")
if len(incomplete) != 0 {
t.Error("there should be 0 incomplete result")
}
if len(done) != 0 {
t.Error("there should be 0 done measurements")
if len(done) != 1 {
t.Error("there should be 1 done result")
}
if done[0].TotalCount != 2 {
t.Error("there should be a total of 2 measurements in the result")
}
if done[0].AnomalyCount != 1 {
t.Error("there should be a total of 1 anomalies in the result")
}
msmts, err := ListMeasurements(sess, resultID)