From 77ab8d92f1dfc753d820e64c14c92a80e4799940 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 11 Apr 2022 11:40:51 -0400 Subject: [PATCH] E2E: oversubscription assertion needs to wait for stats (#12540) The oversubscription test expects an output that requires the client has polled the task for stats at least once. Wait long enough to ensure that we've polled the stats before failing the test. --- e2e/oversubscription/oversubscription.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/e2e/oversubscription/oversubscription.go b/e2e/oversubscription/oversubscription.go index e2c082bee..3118134f9 100644 --- a/e2e/oversubscription/oversubscription.go +++ b/e2e/oversubscription/oversubscription.go @@ -2,6 +2,8 @@ package oversubscription import ( "fmt" + "strings" + "time" "github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/e2e/e2eutil" @@ -110,11 +112,18 @@ func (tc *OversubscriptionTest) runTest(f *framework.F, jobPrefix, jobfile strin f.Equal(int64(20), resources.Memory.MemoryMB) f.Equal(int64(30), resources.Memory.MemoryMaxMB) - // assert the status API report memory - allocInfo, err := e2eutil.Command("nomad", "alloc", "status", alloc.ID) - f.NoError(err) - f.Contains(allocInfo, "/20 MiB") // memory reserve - f.Contains(allocInfo, "Max: 30 MiB") // memory max + // assert the status API reports memory, we need to wait for the + // for metrics to be written before we can assert the entire + // command line + var allocInfo string + f.Eventually(func() bool { + allocInfo, err = e2eutil.Command("nomad", "alloc", "status", alloc.ID) + if err != nil { + return false + } + return strings.Contains(allocInfo, "/20 MiB") && // memory reserve + strings.Contains(allocInfo, "Max: 30 MiB") // memory max + }, 10*time.Second, 200*time.Millisecond, "unexpected memory output") return alloc }