Added debug info to TestUpdateStatsOnReplica (#19825)

To debug occasional CI failures.
This commit is contained in:
Victor Lyuboslavsky 2024-06-18 11:29:13 -05:00 committed by GitHub
parent 27d25b7874
commit 8d5914b6fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ package service
import (
"context"
"crypto/tls"
"github.com/fleetdm/fleet/v4/server/contexts/ctxdb"
"math/rand"
"net/http"
"net/http/httptest"
@ -256,7 +257,21 @@ func testUpdateStats(t *testing.T, ds *mysql.Datastore, usingReplica bool) {
}()
select {
case <-time.After(2 * time.Second):
t.Fatal("Timeout waiting for aggregated stats")
// We fail the test. Gather information for debug.
// Grab stats from primary DB (master)
lastErr := ""
if err != nil {
lastErr = err.Error()
}
aggStats, err = mysql.GetAggregatedStats(
ctxdb.RequirePrimary(ctx, true), svc.ds.(*mysql.Datastore), fleet.AggregatedStatsTypeScheduledQuery, queryID,
)
if err != nil {
t.Logf("Error getting aggregated stats from primary DB: %s", err.Error())
} else {
t.Logf("Aggregated stats from primary DB: totalExecutions=%f %#v", *aggStats.TotalExecutions, aggStats)
}
t.Fatalf("Timeout waiting for aggregated stats. Last error: %s", lastErr)
case <-done:
// Continue
}