markerStillClaims function

bool markerStillClaims(
  1. File marker, {
  2. required DateTime now,
  3. Duration markerStaleAfter = defaultMarkerStaleAfter,
})

Whether marker still says a running suite holds what it claims.

False when the marker is absent: a resource nobody marked is nobody's. False when the marker is older than markerStaleAfter: teardown is what removes a marker, so one this old belongs to a run that never got there.

The threshold itself counts as still claiming. Being wrong in the other direction takes a resource away from a run that is still going.

Implementation

bool markerStillClaims(
  File marker, {
  required DateTime now,
  Duration markerStaleAfter = defaultMarkerStaleAfter,
}) {
  // Read the timestamp rather than checking existence first: another suite's
  // teardown can delete the marker between the two calls, and a vanished
  // marker means the same thing as an absent one — the suite that owned it
  // has finished.
  final DateTime modified;
  try {
    modified = marker.lastModifiedSync();
  } on FileSystemException {
    return false;
  }

  return now.toUtc().difference(modified.toUtc()) <= markerStaleAfter;
}