Unverified Commit 1b0fd265 authored by Dmitry Ratushnyy's avatar Dmitry Ratushnyy Committed by GitHub

[ISSUE-30478] Release cache dir lock acquired by a command on sigint or sigterm (#52194)

parent 04a1b78b
......@@ -622,6 +622,7 @@ abstract class FlutterCommand extends Command<void> {
void _registerSignalHandlers(String commandPath, DateTime startTime) {
final SignalHandler handler = (io.ProcessSignal s) {
Cache.releaseLockEarly();
_sendPostUsage(
commandPath,
const FlutterCommandResult(ExitStatus.killed),
......
......@@ -287,6 +287,43 @@ void main() {
SystemClock: () => clock,
Usage: () => usage,
});
testUsingContext('command release lock on kill signal', () async {
mockTimes = <int>[1000, 2000];
final Completer<void> completer = Completer<void>();
setExitFunctionForTests((int exitCode) {
expect(exitCode, 0);
restoreExitFunction();
completer.complete();
});
final Completer<void> checkLockCompleter = Completer<void>();
final DummyFlutterCommand flutterCommand =
DummyFlutterCommand(commandFunction: () async {
await Cache.lock();
checkLockCompleter.complete();
final Completer<void> c = Completer<void>();
await c.future;
return null; // unreachable
});
unawaited(flutterCommand.run());
await checkLockCompleter.future;
Cache.checkLockAcquired();
signalController.add(mockSignal);
await completer.future;
await Cache.lock();
Cache.releaseLockEarly();
}, overrides: <Type, Generator>{
ProcessInfo: () => mockProcessInfo,
Signals: () => FakeSignals(
subForSigTerm: signalUnderTest,
exitSignals: <ProcessSignal>[signalUnderTest],
),
Usage: () => usage
});
});
testUsingCommandContext('report execution timing by default', () async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment