Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebko committed Dec 20, 2024
1 parent b293f60 commit ace2602
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions internal/tests/cluster/sequential/session_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
35 changes: 17 additions & 18 deletions internal/tests/helper/testing_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}

Expand Down

0 comments on commit ace2602

Please sign in to comment.