TestMetricTxnAborts is racy: baseline fetchMetrics is not retried while the assertion is

Abierto Apto para principiantes
#9,811 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 10 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
go
Área
testing-qa

Línea de trabajo

Empieza en dgraph/cmd/alpha/metrics_test.go, en TestMetricTxnAborts, y compara su llamada baseline a fetchMetrics con retryableFetchMetrics. Comprueba los casos relacionados TestMetricTxnCommits y TestMetricTxnDiscards para ver si siguen el mismo patrón. El trabajo estará terminado cuando la línea base de métricas tolere la exportación asíncrona y las pruebas afectadas pasen sin la condición de carrera por métrica ausente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Stale
Summary

TestMetricTxnAborts reads its baseline metric value with an unretried fetchMetrics, while the assertion that follows uses retryableFetchMetrics. Prometheus metric export is asynchronous, so the baseline read can land before dgraph_txn_aborts_total has been published and the test fails with a message that reads like a missing metric rather than a race.

The code

dgraph/cmd/alpha/metrics_test.go:

func TestMetricTxnAborts(t *testing.T) {
	metricName := "dgraph_txn_aborts_total"
	...
	require.NoError(t, commitWithTs(mr1, false))
	require.Error(t, commitWithTs(mr2, false))

	metrics := fetchMetrics(t, metricName)          // <-- not retried

	... second round of mutations ...

	require.NoError(t, retryableFetchMetrics(t, map[string]int{
		metricName: metrics[metricName] + 1,        // <-- retried
	}))
}

The asymmetry looks unintentional: the same value is fetched twice, once without tolerance for propagation delay and once with.

Note also that dgraph_txn_aborts_total does not exist on the /metrics endpoint until the first abort is actually exported, so on a fresh cluster the baseline read is the most likely of the two to race — it is the one that has to wait for the counter to appear at all, not merely to increment.

Observed failure
--- FAIL: TestMetricTxnAborts (0.02s)
    metrics_test.go:153: the required metric 'dgraph_txn_aborts_total' was not found

Line 153 is inside fetchMetrics, reached from the unretried call. It passes on re-run, which is consistent with a propagation race rather than a functional problem. The preceding require.Error(t, commitWithTs(mr2, false)) passes, so the aborting commit did happen.

Seen once in CI on a fork of this repo; green on re-run of the same commit.

Suggested fix

Use the retrying variant for the baseline too, so the test tolerates propagation in both reads:

require.NoError(t, retryableFetchMetrics(t, map[string]int{metricName: 1}))
metrics := fetchMetrics(t, metricName)

Or have fetchMetrics treat "metric absent" as retryable when the caller is establishing a baseline. Either way the intent is that the test waits for the counter to exist before reading it.

TestMetricTxnCommits and TestMetricTxnDiscards have the same shape and are presumably exposed to the same race, though we have only observed the aborts variant failing.

I'm happy to open a PR for this if it's welcome.

Lenguaje dominante
Go
Estrellas
21.8k
Forks
1.6k
Merge medio
11 d 7 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dgraph-io/dgraph

Todos los issues de dgraph-io/dgraph

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.