diff --git a/internal/tests/cluster/sequential/session_cleanup_test.go b/internal/tests/cluster/sequential/session_cleanup_test.go index 16b0fdad99..8e5ff16e90 100644 --- a/internal/tests/cluster/sequential/session_cleanup_test.go +++ b/internal/tests/cluster/sequential/session_cleanup_test.go @@ -289,6 +289,7 @@ func testWorkerSessionCleanupMulti(burdenCase timeoutBurdenType) func(t *testing // Worker needs some extra time to become ready, otherwise for a // currently-unknown reason the next successful status update fails // because it's not sent before the context times out. + time.Sleep(5 * time.Second) wg.Add(2) go func() { defer wg.Done() diff --git a/internal/tests/helper/testing_helper.go b/internal/tests/helper/testing_helper.go index 862723fa48..6788f116e5 100644 --- a/internal/tests/helper/testing_helper.go +++ b/internal/tests/helper/testing_helper.go @@ -442,14 +442,21 @@ func NewTestTcpServer(t *testing.T) *TestTcpServer { if err != nil { return false } - _, err = c.Write([]byte{}) + _, err = c.Write([]byte("test")) if err != nil { return false } - _, err = c.Read([]byte{}) + buf := make([]byte, len("test")) + _, err = c.Read(buf) if err != nil { return false } + if string(buf) != "test" { + return false + } + if err := c.Close(); err != nil { + return false + } return true }, 10*time.Second, 100*time.Millisecond) @@ -463,25 +470,17 @@ func ExpectWorkers(t *testing.T, c *controller.TestController, workers ...*worke // validate the controller has no reported workers if len(workers) == 0 { require.Eventually(t, func() bool { - updateTimes := c.Controller().WorkerStatusUpdateTimes() - workerMap := map[string]*worker.TestWorker{} - for _, w := range workers { - workerMap[w.Name()] = w - } - updateTimes.Range(func(k, v any) bool { - require.NotNil(t, k) - require.NotNil(t, v) - if workerMap[k.(string)] == nil { - // We don't remove from updateTimes currently so if we're not - // expecting it we'll see an out-of-date entry - return true + workers := []string{} + c.Controller().WorkerStatusUpdateTimes().Range(func(workerId, lastStatusTime any) bool { + require.NotNil(t, workerId) + require.NotNil(t, lastStatusTime) + if time.Since(lastStatusTime.(time.Time)) < DefaultSuccessfulStatusGracePeriod { + workers = append(workers, workerId.(string)) } - assert.WithinDuration(t, time.Now(), v.(time.Time), 30*time.Second) - delete(workerMap, k.(string)) return true }) - return len(workerMap) == 0 - }, 30*time.Second, 250*time.Millisecond) + return len(workers) == 0 + }, 2*DefaultSuccessfulStatusGracePeriod, 250*time.Millisecond) return }