@@ -967,26 +967,32 @@ func TestServer(t *testing.T) {
967
967
assert.NoError(t, err)
968
968
// nolint:bodyclose
969
969
res, err = http.DefaultClient.Do(req)
970
- return err == nil
971
- }, testutil.WaitShort, testutil.IntervalFast)
972
- defer res.Body.Close()
973
-
974
- scanner := bufio.NewScanner(res.Body)
975
- hasActiveUsers := false
976
- for scanner.Scan() {
977
- // This metric is manually registered to be tracked in the server. That's
978
- // why we test it's tracked here.
979
- if strings.HasPrefix(scanner.Text(), "coderd_api_active_users_duration_hour") {
980
- hasActiveUsers = true
981
- continue
970
+ if err != nil {
971
+ return false
982
972
}
983
- if strings.HasPrefix(scanner.Text(), "coderd_db_query_latencies_seconds") {
984
- t.Fatal("db metrics should not be tracked when --prometheus-collect-db-metrics is not enabled")
973
+ defer res.Body.Close()
974
+
975
+ scanner := bufio.NewScanner(res.Body)
976
+ hasActiveUsers := false
977
+ for scanner.Scan() {
978
+ // This metric is manually registered to be tracked in the server. That's
979
+ // why we test it's tracked here.
980
+ if strings.HasPrefix(scanner.Text(), "coderd_api_active_users_duration_hour") {
981
+ hasActiveUsers = true
982
+ continue
983
+ }
984
+ if strings.HasPrefix(scanner.Text(), "coderd_db_query_latencies_seconds") {
985
+ t.Fatal("db metrics should not be tracked when --prometheus-collect-db-metrics is not enabled")
986
+ }
987
+ t.Logf("scanned %s", scanner.Text())
985
988
}
986
- t.Logf("scanned %s", scanner.Text())
987
- }
988
- require.NoError(t, scanner.Err())
989
- require.True(t, hasActiveUsers)
989
+ if scanner.Err() != nil {
990
+ t.Logf("scanner err: %s", scanner.Err().Error())
991
+ return false
992
+ }
993
+
994
+ return hasActiveUsers
995
+ }, testutil.WaitShort, testutil.IntervalFast, "didn't find coderd_api_active_users_duration_hour in time")
990
996
})
991
997
992
998
t.Run("DBMetricsEnabled", func(t *testing.T) {
@@ -1017,20 +1023,25 @@ func TestServer(t *testing.T) {
1017
1023
assert.NoError(t, err)
1018
1024
// nolint:bodyclose
1019
1025
res, err = http.DefaultClient.Do(req)
1020
- return err == nil
1021
- }, testutil.WaitShort, testutil.IntervalFast)
1022
- defer res.Body.Close()
1023
-
1024
- scanner := bufio.NewScanner(res.Body)
1025
- hasDBMetrics := false
1026
- for scanner.Scan() {
1027
- if strings.HasPrefix(scanner.Text(), "coderd_db_query_latencies_seconds") {
1028
- hasDBMetrics = true
1026
+ if err != nil {
1027
+ return false
1029
1028
}
1030
- t.Logf("scanned %s", scanner.Text())
1031
- }
1032
- require.NoError(t, scanner.Err())
1033
- require.True(t, hasDBMetrics)
1029
+ defer res.Body.Close()
1030
+
1031
+ scanner := bufio.NewScanner(res.Body)
1032
+ hasDBMetrics := false
1033
+ for scanner.Scan() {
1034
+ if strings.HasPrefix(scanner.Text(), "coderd_db_query_latencies_seconds") {
1035
+ hasDBMetrics = true
1036
+ }
1037
+ t.Logf("scanned %s", scanner.Text())
1038
+ }
1039
+ if scanner.Err() != nil {
1040
+ t.Logf("scanner err: %s", scanner.Err().Error())
1041
+ return false
1042
+ }
1043
+ return hasDBMetrics
1044
+ }, testutil.WaitShort, testutil.IntervalFast, "didn't find coderd_db_query_latencies_seconds in time")
1034
1045
})
1035
1046
})
1036
1047
t.Run("GitHubOAuth", func(t *testing.T) {
@@ -1347,7 +1358,7 @@ func TestServer(t *testing.T) {
1347
1358
}
1348
1359
return lastStat.Size() > 0
1349
1360
},
1350
- testutil.WaitShort,
1361
+ dur, //nolint:gocritic
1351
1362
testutil.IntervalFast,
1352
1363
"file at %s should exist, last stat: %+v",
1353
1364
fiName, lastStat,
0 commit comments