diff --git a/drivers/exec/driver_test.go b/drivers/exec/driver_test.go index b53b359fa..09ce0cfc5 100644 --- a/drivers/exec/driver_test.go +++ b/drivers/exec/driver_test.go @@ -284,6 +284,8 @@ func TestExecDriver_Stats(t *testing.T) { select { case stats := <-statsCh: require.NotZero(stats.ResourceUsage.MemoryStats.RSS) + require.NotZero(stats.Timestamp) + require.WithinDuration(time.Now(), time.Unix(0, stats.Timestamp), time.Second) case <-time.After(time.Second): require.Fail("timeout receiving from channel") } diff --git a/drivers/shared/executor/executor_test.go b/drivers/shared/executor/executor_test.go index ab0955faf..aad0647bd 100644 --- a/drivers/shared/executor/executor_test.go +++ b/drivers/shared/executor/executor_test.go @@ -178,9 +178,9 @@ func TestExecutor_WaitExitSignal(pt *testing.T) { case <-time.After(time.Second): return false, fmt.Errorf("stats failed to send on interval") case ru := <-ch: - if len(ru.Pids) == 0 { - return false, fmt.Errorf("no pids recorded in stats") - } + assert.NotEmpty(t, ru.Pids, "no pids recorded in stats") + assert.NotZero(t, ru.ResourceUsage.MemoryStats.RSS) + assert.WithinDuration(t, time.Now(), time.Unix(0, ru.Timestamp), time.Second) } proc, err := os.FindProcess(ps.Pid) if err != nil { diff --git a/plugins/drivers/utils.go b/plugins/drivers/utils.go index 8eb254e5e..f84b75461 100644 --- a/plugins/drivers/utils.go +++ b/plugins/drivers/utils.go @@ -412,7 +412,7 @@ func TaskStatsFromProto(pb *proto.TaskStats) (*TaskResourceUsage, error) { } stats := &TaskResourceUsage{ - Timestamp: timestamp.Unix(), + Timestamp: timestamp.UnixNano(), ResourceUsage: resourceUsageFromProto(pb.AggResourceUsage), Pids: pids, }