hot_test.dart 22 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:async';

7 8 9
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
10
import 'package:vm_service/vm_service.dart' as vm_service;
11
import 'package:flutter_tools/src/artifacts.dart';
12
import 'package:flutter_tools/src/base/io.dart';
13
import 'package:flutter_tools/src/build_info.dart';
14
import 'package:flutter_tools/src/compile.dart';
15
import 'package:flutter_tools/src/devfs.dart';
16 17
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/resident_runner.dart';
18
import 'package:flutter_tools/src/run_hot.dart';
19
import 'package:flutter_tools/src/vmservice.dart';
20 21
import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart';
22

23 24 25
import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart';
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate(
  id: '1',
  pauseEvent: vm_service.Event(
    kind: vm_service.EventKind.kResume,
    timestamp: 0
  ),
  breakpoints: <vm_service.Breakpoint>[],
  exceptionPauseMode: null,
  libraries: <vm_service.LibraryRef>[],
  livePorts: 0,
  name: 'test',
  number: '1',
  pauseOnExit: false,
  runnable: true,
  startTime: 0,
);

final FlutterView fakeFlutterView = FlutterView(
  id: 'a',
  uiIsolate: fakeUnpausedIsolate,
);

final FakeVmServiceRequest listViews = FakeVmServiceRequest(
  method: kListViewsMethod,
  jsonResponse: <String, Object>{
    'views': <Object>[
      fakeFlutterView.toJson(),
    ],
  },
);
57
void main() {
58 59 60
  group('validateReloadReport', () {
    testUsingContext('invalid', () async {
      expect(HotRunner.validateReloadReport(<String, dynamic>{}), false);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{},
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[
          ],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <String, dynamic>{
            'message': 'error',
          },
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[
95
            <String, dynamic>{'message': false},
96 97 98 99 100 101 102 103
          ],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[
104
            <String, dynamic>{'message': <String>['error']},
105 106 107 108 109 110 111 112
          ],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[
113 114
            <String, dynamic>{'message': 'error'},
            <String, dynamic>{'message': <String>['error']},
115 116 117 118 119 120 121 122
          ],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': false,
        'details': <String, dynamic>{
          'notices': <Map<String, dynamic>>[
123
            <String, dynamic>{'message': 'error'},
124 125 126 127 128 129 130
          ],
        },
      }), false);
      expect(HotRunner.validateReloadReport(<String, dynamic>{
        'type': 'ReloadReport',
        'success': true,
      }), true);
131 132
    });
  });
133 134

  group('hotRestart', () {
135
    final MockResidentCompiler residentCompiler = MockResidentCompiler();
136
    final MockDevFs mockDevFs = MockDevFs();
137
    FileSystem fileSystem;
138

139
    when(mockDevFs.update(
140
      mainUri: anyNamed('mainUri'),
141 142 143 144 145 146 147 148 149 150
      target: anyNamed('target'),
      bundle: anyNamed('bundle'),
      firstBuildTime: anyNamed('firstBuildTime'),
      bundleFirstUpload: anyNamed('bundleFirstUpload'),
      generator: anyNamed('generator'),
      fullRestart: anyNamed('fullRestart'),
      dillOutputPath: anyNamed('dillOutputPath'),
      trackWidgetCreation: anyNamed('trackWidgetCreation'),
      projectRootPath: anyNamed('projectRootPath'),
      pathToReload: anyNamed('pathToReload'),
151
      invalidatedFiles: anyNamed('invalidatedFiles'),
152
      packageConfig: anyNamed('packageConfig'),
153 154
    )).thenAnswer((Invocation _) => Future<UpdateFSReport>.value(
        UpdateFSReport(success: true, syncedBytes: 1000, invalidatedSourcesCount: 1)));
155
    when(mockDevFs.assetPathsToEvict).thenReturn(<String>{});
156
    when(mockDevFs.baseUri).thenReturn(Uri.file('test'));
157 158
    when(mockDevFs.sources).thenReturn(<Uri>[Uri.file('test')]);
    when(mockDevFs.lastCompiled).thenReturn(DateTime.now());
159

160
    setUp(() {
161
      fileSystem = MemoryFileSystem.test();
162 163
    });

164
    testUsingContext('Does not hot restart when device does not support it', () async {
165
      fileSystem.file('.packages')
166 167
        ..createSync(recursive: true)
        ..writeAsStringSync('\n');
168 169 170 171
      // Setup mocks
      final MockDevice mockDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(false);
172
      when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
173 174
      // Trigger hot restart.
      final List<FlutterDevice> devices = <FlutterDevice>[
175
        FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
176
      ];
177 178 179 180
      final OperationResult result = await HotRunner(
        devices,
        debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
      ).restart(fullRestart: true);
181
      // Expect hot restart failed.
182
      expect(result.isOk, false);
183
      expect(result.message, 'hotRestart not supported');
184
    }, overrides: <Type, Generator>{
185
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
186 187 188 189
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
190 191 192
    });

    testUsingContext('Does not hot restart when one of many devices does not support it', () async {
193
      fileSystem.file('.packages')
194 195
        ..createSync(recursive: true)
        ..writeAsStringSync('\n');
196 197 198 199 200 201 202 203 204
      // Setup mocks
      final MockDevice mockDevice = MockDevice();
      final MockDevice mockHotDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(false);
      when(mockHotDevice.supportsHotReload).thenReturn(true);
      when(mockHotDevice.supportsHotRestart).thenReturn(true);
      // Trigger hot restart.
      final List<FlutterDevice> devices = <FlutterDevice>[
205 206
        FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
        FlutterDevice(mockHotDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
207
      ];
208 209 210 211
      final OperationResult result = await HotRunner(
        devices,
        debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
      ).restart(fullRestart: true);
212 213 214 215
      // Expect hot restart failed.
      expect(result.isOk, false);
      expect(result.message, 'hotRestart not supported');
    }, overrides: <Type, Generator>{
216
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
217 218 219 220
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
221 222 223
    });

    testUsingContext('Does hot restarts when all devices support it', () async {
224
      final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
225 226 227 228 229 230 231
        listViews,
        FakeVmServiceRequest(
          method: 'getIsolate',
          args: <String, Object>{
            'isolateId': fakeUnpausedIsolate.id,
          },
          jsonResponse: fakeUnpausedIsolate.toJson(),
232 233 234 235 236
        ),
        FakeVmServiceRequest(
          method: 'getVM',
          jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson()
        ),
237 238 239 240 241 242 243 244
        listViews,
        FakeVmServiceRequest(
          method: 'getIsolate',
          args: <String, Object>{
            'isolateId': fakeUnpausedIsolate.id,
          },
          jsonResponse: fakeUnpausedIsolate.toJson(),
        ),
245 246 247 248
        FakeVmServiceRequest(
          method: 'getVM',
          jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson()
        ),
249 250
        listViews,
        listViews,
251
        const FakeVmServiceRequest(
252 253 254
          method: 'streamListen',
          args: <String, Object>{
            'streamId': 'Isolate',
255 256 257
          }
        ),
        const FakeVmServiceRequest(
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
          method: 'streamListen',
          args: <String, Object>{
            'streamId': 'Isolate',
          }
        ),
        FakeVmServiceStreamResponse(
          streamId: 'Isolate',
          event: vm_service.Event(
            timestamp: 0,
            kind: vm_service.EventKind.kIsolateRunnable,
          )
        ),
        FakeVmServiceStreamResponse(
          streamId: 'Isolate',
          event: vm_service.Event(
            timestamp: 0,
            kind: vm_service.EventKind.kIsolateRunnable,
          )
        ),
        FakeVmServiceRequest(
          method: kRunInViewMethod,
          args: <String, Object>{
            'viewId': fakeFlutterView.id,
            'mainScript': 'lib/main.dart.dill',
            'assetDirectory': 'build/flutter_assets',
          }
        ),
        FakeVmServiceRequest(
          method: kRunInViewMethod,
          args: <String, Object>{
            'viewId': fakeFlutterView.id,
            'mainScript': 'lib/main.dart.dill',
            'assetDirectory': 'build/flutter_assets',
291 292 293
          }
        ),
      ]);
294 295 296 297 298 299 300 301 302
      // Setup mocks
      final MockDevice mockDevice = MockDevice();
      final MockDevice mockHotDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(true);
      when(mockHotDevice.supportsHotReload).thenReturn(true);
      when(mockHotDevice.supportsHotRestart).thenReturn(true);
      // Trigger a restart.
      final List<FlutterDevice> devices = <FlutterDevice>[
303 304 305 306 307 308
        FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
          ..vmService = fakeVmServiceHost.vmService
          ..devFS = mockDevFs,
        FlutterDevice(mockHotDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
          ..vmService = fakeVmServiceHost.vmService
          ..devFS = mockDevFs,
309
      ];
310 311 312 313
      final HotRunner hotRunner = HotRunner(
        devices,
        debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
      );
314
      final OperationResult result = await hotRunner.restart(fullRestart: true);
315
      // Expect hot restart was successful.
316
      expect(hotRunner.uri, mockDevFs.baseUri);
317 318 319
      expect(result.isOk, true);
      expect(result.message, isNot('hotRestart not supported'));
    }, overrides: <Type, Generator>{
320
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
321 322 323 324
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
325 326 327
    });

    testUsingContext('setup function fails', () async {
328
      fileSystem.file('.packages')
329 330
        ..createSync(recursive: true)
        ..writeAsStringSync('\n');
331 332 333
      final MockDevice mockDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(true);
334
      when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
335
      final List<FlutterDevice> devices = <FlutterDevice>[
336
        FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
337
      ];
338 339 340 341
      final OperationResult result = await HotRunner(
        devices,
        debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
      ).restart(fullRestart: true);
342 343
      expect(result.isOk, false);
      expect(result.message, 'setupHotRestart failed');
344
    }, overrides: <Type, Generator>{
345
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: false),
346 347 348 349
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
350
    });
351 352

    testUsingContext('hot restart supported', () async {
353
      fileSystem.file('.packages')
354 355
        ..createSync(recursive: true)
        ..writeAsStringSync('\n');
356
      // Setup mocks
357
      final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
358 359 360 361 362 363 364
        listViews,
        FakeVmServiceRequest(
          method: 'getIsolate',
          args: <String, Object>{
            'isolateId': fakeUnpausedIsolate.id,
          },
          jsonResponse: fakeUnpausedIsolate.toJson(),
365 366 367
        ),
        FakeVmServiceRequest(
          method: 'getVM',
368
          jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
369
        ),
370
        listViews,
371
        const FakeVmServiceRequest(
372 373 374
          method: 'streamListen',
          args: <String, Object>{
            'streamId': 'Isolate',
375 376
          }
        ),
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
        FakeVmServiceRequest(
          method: kRunInViewMethod,
          args: <String, Object>{
            'viewId': fakeFlutterView.id,
            'mainScript': 'lib/main.dart.dill',
            'assetDirectory': 'build/flutter_assets',
          }
        ),
        FakeVmServiceStreamResponse(
          streamId: 'Isolate',
          event: vm_service.Event(
            timestamp: 0,
            kind: vm_service.EventKind.kIsolateRunnable,
          )
        ),
392
      ]);
393 394 395
      final MockDevice mockDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(true);
396
      when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
397 398
      // Trigger hot restart.
      final List<FlutterDevice> devices = <FlutterDevice>[
399 400 401
        FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
          ..vmService = fakeVmServiceHost.vmService
          ..devFS = mockDevFs,
402
      ];
403 404 405 406
      final HotRunner hotRunner = HotRunner(
        devices,
        debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
      );
407
      final OperationResult result = await hotRunner.restart(fullRestart: true);
408
      // Expect hot restart successful.
409
      expect(hotRunner.uri, mockDevFs.baseUri);
410 411 412
      expect(result.isOk, true);
      expect(result.message, isNot('setupHotRestart failed'));
    }, overrides: <Type, Generator>{
413
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
414 415 416 417
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
418
    });
419 420 421 422 423 424 425 426 427 428 429

    group('shutdown hook tests', () {
      TestHotRunnerConfig shutdownTestingConfig;

      setUp(() {
        shutdownTestingConfig = TestHotRunnerConfig(
          successfulSetup: true,
        );
      });

      testUsingContext('shutdown hook called after signal', () async {
430
        fileSystem.file('.packages')
431 432
          ..createSync(recursive: true)
          ..writeAsStringSync('\n');
433 434 435
        final MockDevice mockDevice = MockDevice();
        when(mockDevice.supportsHotReload).thenReturn(true);
        when(mockDevice.supportsHotRestart).thenReturn(true);
436
        when(mockDevice.supportsFlutterExit).thenReturn(false);
437
        final List<FlutterDevice> devices = <FlutterDevice>[
438
          FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
439
        ];
440 441 442 443
        await HotRunner(
          devices,
          debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
        ).cleanupAfterSignal();
444
        expect(shutdownTestingConfig.shutdownHookCalled, true);
445
      }, overrides: <Type, Generator>{
446
        HotRunnerConfig: () => shutdownTestingConfig,
447 448 449 450
        Artifacts: () => Artifacts.test(),
        FileSystem: () => fileSystem,
        Platform: () => FakePlatform(operatingSystem: 'linux'),
        ProcessManager: () => FakeProcessManager.any(),
451 452 453
      });

      testUsingContext('shutdown hook called after app stop', () async {
454
        fileSystem.file('.packages')
455 456
          ..createSync(recursive: true)
          ..writeAsStringSync('\n');
457 458 459
        final MockDevice mockDevice = MockDevice();
        when(mockDevice.supportsHotReload).thenReturn(true);
        when(mockDevice.supportsHotRestart).thenReturn(true);
460
        when(mockDevice.supportsFlutterExit).thenReturn(false);
461
        final List<FlutterDevice> devices = <FlutterDevice>[
462
          FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
463
        ];
464 465 466 467
        await HotRunner(
          devices,
          debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
        ).preExit();
468
        expect(shutdownTestingConfig.shutdownHookCalled, true);
469
      }, overrides: <Type, Generator>{
470
        HotRunnerConfig: () => shutdownTestingConfig,
471 472 473 474
        Artifacts: () => Artifacts.test(),
        FileSystem: () => fileSystem,
        Platform: () => FakePlatform(operatingSystem: 'linux'),
        ProcessManager: () => FakeProcessManager.any(),
475 476
      });
    });
477
  });
478 479

  group('hot attach', () {
480
    FileSystem fileSystem;
481 482

    setUp(() {
483
      fileSystem = MemoryFileSystem.test();
484 485
    });

486 487
    testUsingContext('Exits with code 2 when when HttpException is thrown '
      'during VM service connection', () async {
488
      fileSystem.file('.packages')
489 490 491
        ..createSync(recursive: true)
        ..writeAsStringSync('\n');

492
      final MockResidentCompiler residentCompiler = MockResidentCompiler();
493 494 495 496 497 498 499 500 501 502 503
      final MockDevice mockDevice = MockDevice();
      when(mockDevice.supportsHotReload).thenReturn(true);
      when(mockDevice.supportsHotRestart).thenReturn(false);
      when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
      when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation _) async => 'Android 10');

      final List<FlutterDevice> devices = <FlutterDevice>[
        TestFlutterDevice(
          device: mockDevice,
          generator: residentCompiler,
          exception: const HttpException('Connection closed before full header was received, '
504
              'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'),
505 506 507 508 509 510 511 512 513
        ),
      ];

      final int exitCode = await HotRunner(devices,
        debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
      ).attach();
      expect(exitCode, 2);
    }, overrides: <Type, Generator>{
      HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
514 515 516 517
      Artifacts: () => Artifacts.test(),
      FileSystem: () => fileSystem,
      Platform: () => FakePlatform(operatingSystem: 'linux'),
      ProcessManager: () => FakeProcessManager.any(),
518 519
    });
  });
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549

  group('hot cleanupAtFinish()', () {
    MockFlutterDevice mockFlutterDeviceFactory(Device device) {
      final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
      when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) => Future<void>.value(null));
      when(mockFlutterDevice.device).thenReturn(device);
      return mockFlutterDevice;
    }

    testUsingContext('disposes each device', () async {
      final MockDevice mockDevice1 = MockDevice();
      final MockDevice mockDevice2 = MockDevice();
      final MockFlutterDevice mockFlutterDevice1 = mockFlutterDeviceFactory(mockDevice1);
      final MockFlutterDevice mockFlutterDevice2 = mockFlutterDeviceFactory(mockDevice2);

      final List<FlutterDevice> devices = <FlutterDevice>[
        mockFlutterDevice1,
        mockFlutterDevice2,
      ];

      await HotRunner(devices,
        debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
      ).cleanupAtFinish();

      verify(mockDevice1.dispose());
      verify(mockFlutterDevice1.stopEchoingDeviceLog());
      verify(mockDevice2.dispose());
      verify(mockFlutterDevice2.stopEchoingDeviceLog());
    });
  });
550 551
}

552 553
class MockDevFs extends Mock implements DevFS {}

554 555 556 557 558 559
class MockDevice extends Mock implements Device {
  MockDevice() {
    when(isSupported()).thenReturn(true);
  }
}

560 561
class MockFlutterDevice extends Mock implements FlutterDevice {}

562 563 564 565
class TestFlutterDevice extends FlutterDevice {
  TestFlutterDevice({
    @required Device device,
    @required this.exception,
566
    @required ResidentCompiler generator,
567
  })  : assert(exception != null),
568
        super(device, buildInfo: BuildInfo.debug, generator: generator);
569 570 571 572 573 574 575 576 577

  /// The exception to throw when the connect method is called.
  final Exception exception;

  @override
  Future<void> connect({
    ReloadSources reloadSources,
    Restart restart,
    CompileExpression compileExpression,
578
    ReloadMethod reloadMethod,
579
    GetSkSLMethod getSkSLMethod,
580
    PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
581
    bool disableServiceAuthCodes = false,
582 583
    bool disableDds = false,
    bool ipv6 = false,
584
    int hostVmServicePort
585 586 587 588 589
  }) async {
    throw exception;
  }
}

590
class TestHotRunnerConfig extends HotRunnerConfig {
591
  TestHotRunnerConfig({@required this.successfulSetup});
592
  bool successfulSetup;
593
  bool shutdownHookCalled = false;
594

595 596 597 598
  @override
  Future<bool> setupHotRestart() async {
    return successfulSetup;
  }
599 600 601 602 603

  @override
  Future<void> runPreShutdownOperations() async {
    shutdownHookCalled = true;
  }
604
}