@@ -20,6 +20,54 @@ traefik_config_last_reload_success 1.725e+09
2020 }
2121}
2222
23+ func TestWaitForMetricsReadyRetriesTemporaryErrors (t * testing.T ) {
24+ originalReader := readLastSuccessfulReload
25+ originalPollInterval := reloadPollInterval
26+ t .Cleanup (func () {
27+ readLastSuccessfulReload = originalReader
28+ reloadPollInterval = originalPollInterval
29+ })
30+
31+ attempts := 0
32+ readLastSuccessfulReload = func () (time.Time , error ) {
33+ attempts ++
34+ if attempts < 3 {
35+ return time.Time {}, os .ErrNotExist
36+ }
37+ return time .Now (), nil
38+ }
39+ reloadPollInterval = time .Millisecond
40+
41+ if err := waitForMetricsReady (50 * time .Millisecond ); err != nil {
42+ t .Fatal (err )
43+ }
44+ if attempts != 3 {
45+ t .Fatalf ("metrics read attempted %d times, want 3" , attempts )
46+ }
47+ }
48+
49+ func TestWaitForMetricsReadyTimesOut (t * testing.T ) {
50+ originalReader := readLastSuccessfulReload
51+ originalPollInterval := reloadPollInterval
52+ t .Cleanup (func () {
53+ readLastSuccessfulReload = originalReader
54+ reloadPollInterval = originalPollInterval
55+ })
56+
57+ readLastSuccessfulReload = func () (time.Time , error ) {
58+ return time.Time {}, os .ErrDeadlineExceeded
59+ }
60+ reloadPollInterval = time .Millisecond
61+
62+ err := waitForMetricsReady (5 * time .Millisecond )
63+ if err == nil {
64+ t .Fatal ("metrics readiness wait unexpectedly succeeded" )
65+ }
66+ if ! strings .Contains (err .Error (), "traefik metrics did not become ready within 5ms" ) {
67+ t .Fatalf ("unexpected timeout error: %v" , err )
68+ }
69+ }
70+
2371func TestDynamicConfigReloadedRequiresReloadAtOrAfterNewestFile (t * testing.T ) {
2472 originalDir := dynamicConfigDir
2573 originalReader := readLastSuccessfulReload
0 commit comments