waitForProxiedStateStoreExit function
Polls survivingPids and heldLockPaths until both come back empty.
Returns only for a store that is wholly gone. Otherwise it throws a
StateError naming the residue it timed out on — surviving PIDs, held lock
paths, both sorted — because residue nothing can remove is a live Dolt
server writing into a directory a test is about to delete, and the only
useful report of that is the one that names it. now and delay are
injected so the bound can be proved without spending it.
Implementation
Future<void> waitForProxiedStateStoreExit({
required Future<Set<int>> Function() survivingPids,
required Future<Set<String>> Function() heldLockPaths,
required DateTime Function() now,
required Future<void> Function(Duration) delay,
Duration bound = const Duration(seconds: 10),
Duration pollInterval = const Duration(milliseconds: 50),
}) async {
final deadline = now().add(bound);
while (true) {
final pids = (await survivingPids()).toList()..sort();
final locks = (await heldLockPaths()).toList()..sort();
if (pids.isEmpty && locks.isEmpty) return;
if (!now().isBefore(deadline)) {
throw StateError(
'the proxied state store did not exit within '
'${bound.inMilliseconds}ms: surviving pids [${pids.join(', ')}], '
'held locks [${locks.join(', ')}]',
);
}
await delay(pollInterval);
}
}