Skip to content

Commit 1559e0e

Browse files
committed
Expect logs in the future instead and remove now dead code around removing breakpoints for specific libraries
1 parent 6140729 commit 1559e0e

File tree

2 files changed

+64
-67
lines changed

2 files changed

+64
-67
lines changed

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,12 @@ class ChromeProxyService implements VmServiceInterface {
477477
}
478478

479479
/// Removes the breakpoints in the running isolate.
480-
///
481-
/// [libraries] is a set of Dart libraries, where if non-null, only
482-
/// breakpoints within those libraries are removed.
483-
Future<void> disableBreakpoints({Set<String>? libraries}) async {
480+
Future<void> disableBreakpoints() async {
484481
if (!_isIsolateRunning) return;
485482
final isolate = inspector.isolate;
486483

487484
for (final breakpoint in isolate.breakpoints?.toList() ?? <Breakpoint>[]) {
488-
if (libraries == null ||
489-
(breakpoint.location.script != null &&
490-
// ignore: avoid-collection-methods-with-unrelated-types
491-
libraries.contains(breakpoint.location.script.uri))) {
492-
await (await debuggerFuture).removeBreakpoint(breakpoint.id!);
493-
}
485+
await (await debuggerFuture).removeBreakpoint(breakpoint.id!);
494486
}
495487
}
496488

dwds/test/hot_reload_breakpoints_test.dart

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ void main() {
156156
await client.resume(isolate.id!);
157157
}
158158

159+
// When the program is executing, we want to check that at some point it
160+
// will execute code that will emit [expectedString].
161+
Future<void> resumeAndExpectLog(String expectedString) async {
162+
final completer = Completer<void>();
163+
final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen((
164+
e,
165+
) {
166+
if (e.args.first.value == expectedString) {
167+
completer.complete();
168+
}
169+
});
170+
await resume();
171+
await completer.future.then((_) {
172+
newSubscription.cancel();
173+
});
174+
}
175+
159176
Future<List<Breakpoint>> hotReloadAndHandlePausePost(
160177
List<({String file, String breakpointMarker, Breakpoint? bp})>
161178
breakpoints,
@@ -198,6 +215,26 @@ void main() {
198215
await client.evaluate(isolate.id!, rootLib!.id!, 'evaluate()');
199216
}
200217

218+
// Much like `resumeAndExpectLog`, we need a completer to ensure the log
219+
// will eventually occur when code is executing.
220+
Future<void> callEvaluateAndExpectLog(String expectedString) async {
221+
final completer = Completer<void>();
222+
final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen((
223+
e,
224+
) {
225+
if (e.args.first.value == expectedString) {
226+
completer.complete();
227+
}
228+
});
229+
final vm = await client.getVM();
230+
final isolate = await client.getIsolate(vm.isolates!.first.id!);
231+
final rootLib = isolate.rootLib;
232+
await client.evaluate(isolate.id!, rootLib!.id!, 'evaluate()');
233+
await completer.future.then((_) {
234+
newSubscription.cancel();
235+
});
236+
}
237+
201238
test('after edit and hot reload, breakpoint is in new file', () async {
202239
final oldString = 'main gen0';
203240
final newString = 'main gen1';
@@ -214,8 +251,7 @@ void main() {
214251
(event) => event.kind == EventKind.kPauseBreakpoint,
215252
);
216253
expect(consoleLogs.contains(oldString), false);
217-
await resume();
218-
expect(consoleLogs.contains(oldString), true);
254+
await resumeAndExpectLog(oldString);
219255

220256
consoleLogs.clear();
221257

@@ -233,8 +269,7 @@ void main() {
233269
(event) => event.kind == EventKind.kPauseBreakpoint,
234270
);
235271
expect(consoleLogs.contains(newString), false);
236-
await resume();
237-
expect(consoleLogs.contains(newString), true);
272+
await resumeAndExpectLog(newString);
238273
});
239274

240275
test('after adding line, hot reload, removing line, and hot reload, '
@@ -253,8 +288,7 @@ void main() {
253288
(event) => event.kind == EventKind.kPauseBreakpoint,
254289
);
255290
expect(consoleLogs.contains(genLog), false);
256-
await resume();
257-
expect(consoleLogs.contains(genLog), true);
291+
await resumeAndExpectLog(genLog);
258292

259293
consoleLogs.clear();
260294

@@ -276,8 +310,7 @@ void main() {
276310
(event) => event.kind == EventKind.kPauseBreakpoint,
277311
);
278312
expect(consoleLogs.contains(extraLog), true);
279-
await resume();
280-
expect(consoleLogs.contains(genLog), true);
313+
await resumeAndExpectLog(genLog);
281314

282315
consoleLogs.clear();
283316

@@ -295,8 +328,7 @@ void main() {
295328
(event) => event.kind == EventKind.kPauseBreakpoint,
296329
);
297330
expect(consoleLogs.contains(extraLog), false);
298-
await resume();
299-
expect(consoleLogs.contains(genLog), true);
331+
await resumeAndExpectLog(genLog);
300332
});
301333

302334
test(
@@ -317,8 +349,7 @@ void main() {
317349
(event) => event.kind == EventKind.kPauseBreakpoint,
318350
);
319351
expect(consoleLogs.contains(genLog), false);
320-
await resume();
321-
expect(consoleLogs.contains(genLog), true);
352+
await resumeAndExpectLog(genLog);
322353

323354
consoleLogs.clear();
324355

@@ -359,8 +390,7 @@ void main() {
359390
(event) => event.kind == EventKind.kPauseBreakpoint,
360391
);
361392
expect(consoleLogs.contains(libGenLog), false);
362-
await resume();
363-
expect(consoleLogs.contains(libGenLog), true);
393+
await resumeAndExpectLog(libGenLog);
364394

365395
context.removeLibraryFile(libFileName: libFile);
366396
},
@@ -390,8 +420,7 @@ void main() {
390420
final oldCapturedString = 'captured closure gen0';
391421
expect(consoleLogs.contains(oldCapturedString), false);
392422
// Closure gets evaluated for the first time.
393-
await resume();
394-
expect(consoleLogs.contains(oldCapturedString), true);
423+
await resumeAndExpectLog(oldCapturedString);
395424

396425
final newCapturedString = 'captured closure gen1';
397426
await makeEditAndRecompile(
@@ -404,20 +433,9 @@ void main() {
404433
(file: mainFile, breakpointMarker: capturedStringMarker, bp: bp),
405434
]);
406435

407-
// Use a completer as we won't hit a pause.
408-
final completer = Completer<void>();
409-
final consoleSubscription = context.webkitDebugger.onConsoleAPICalled
410-
.listen((e) {
411-
if (e.args.first.value == oldCapturedString) {
412-
completer.complete();
413-
}
414-
});
415-
416-
await callEvaluate();
417-
418-
// Breakpoint should not have been hit as it's now deleted. We should also
419-
// see the old string still as the closure has not been reevaluated.
420-
await completer.future;
436+
// Breakpoint should not be hit as it's now deleted. We should also see
437+
// the old string still as the closure has not been reevaluated.
438+
await callEvaluateAndExpectLog(oldCapturedString);
421439

422440
await consoleSubscription.cancel();
423441
});
@@ -445,30 +463,29 @@ void main() {
445463
await context.tearDown();
446464
});
447465

448-
Future<void> callEvaluate() async {
466+
Future<void> callEvaluateAndExpectLog(String expectedString) async {
467+
final completer = Completer<void>();
468+
final newSubscription = context.webkitDebugger.onConsoleAPICalled.listen((
469+
e,
470+
) {
471+
if (e.args.first.value == expectedString) {
472+
completer.complete();
473+
}
474+
});
449475
final vm = await client.getVM();
450476
final isolate = await client.getIsolate(vm.isolates!.first.id!);
451477
final rootLib = isolate.rootLib;
452478
await client.evaluate(isolate.id!, rootLib!.id!, 'evaluate()');
479+
await completer.future.then((_) {
480+
newSubscription.cancel();
481+
});
453482
}
454483

455484
test('no pause when calling reloadSources', () async {
456485
final oldString = 'main gen0';
457486
final newString = 'main gen1';
458487

459-
// Use a completer as we won't hit a pause.
460-
var completer = Completer<void>();
461-
var consoleSubscription = context.webkitDebugger.onConsoleAPICalled
462-
.listen((e) {
463-
if (e.args.first.value == oldString) {
464-
completer.complete();
465-
}
466-
});
467-
468-
await callEvaluate();
469-
await completer.future;
470-
471-
await consoleSubscription.cancel();
488+
await callEvaluateAndExpectLog(oldString);
472489

473490
// Modify the string that gets printed and hot reload.
474491
await makeEditAndRecompile(mainFile, oldString, newString);
@@ -477,20 +494,8 @@ void main() {
477494
final report = await client.reloadSources(isolate.id!);
478495
expect(report.success, true);
479496

480-
completer = Completer<void>();
481-
consoleSubscription = context.webkitDebugger.onConsoleAPICalled.listen((
482-
e,
483-
) {
484-
if (e.args.first.value == newString) {
485-
completer.complete();
486-
}
487-
});
488-
489497
// Program should not be paused, so this should execute.
490-
await callEvaluate();
491-
await completer.future;
492-
493-
await consoleSubscription.cancel();
498+
await callEvaluateAndExpectLog(newString);
494499
});
495500
}, timeout: Timeout.factor(2));
496501
}

0 commit comments

Comments
 (0)