-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathbuild_daemon_breakpoint_test.dart
200 lines (163 loc) · 5.86 KB
/
build_daemon_breakpoint_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
57
58
59
60
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@TestOn('vm')
@Timeout(Duration(minutes: 2))
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';
import 'package:vm_service/vm_service.dart' hide VmServiceInterface;
import 'package:vm_service_interface/vm_service_interface.dart';
import 'fixtures/context.dart';
import 'fixtures/project.dart';
void main() {
final provider = TestSdkConfigurationProvider();
tearDownAll(provider.dispose);
final context =
TestContext(TestProject.testPackageWithSoundNullSafety(), provider);
group('shared context', () {
setUpAll(() async {
await context.setUp();
});
tearDownAll(() async {
await context.tearDown();
});
group('breakpoint', () {
VM vm;
late Isolate isolate;
late String isolateId;
ScriptList scripts;
late ScriptRef mainScript;
late String mainScriptUri;
late Stream<Event> stream;
late VmServiceInterface service;
setUp(() async {
service = context.service;
vm = await service.getVM();
isolate = await service.getIsolate(vm.isolates!.first.id!);
isolateId = isolate.id!;
scripts = await service.getScripts(isolateId);
await service.streamListen('Debug');
stream = service.onEvent('Debug');
mainScript = scripts.scripts!
.firstWhere((each) => each.uri!.contains('main.dart'));
mainScriptUri = mainScript.uri!;
});
tearDown(() async {
await service.resume(isolateId);
});
test('set breakpoint', () async {
final line = await context.findBreakpointLine(
'printLocal',
isolateId,
mainScript,
);
final bp = await service.addBreakpointWithScriptUri(
isolateId,
mainScriptUri,
line,
);
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseBreakpoint,
);
expect(bp, isNotNull);
// Remove breakpoint so it doesn't impact other tests.
await service.removeBreakpoint(isolateId, bp.id!);
});
test('set breakpoint again', () async {
final line = await context.findBreakpointLine(
'printLocal',
isolateId,
mainScript,
);
final bp = await service.addBreakpointWithScriptUri(
isolateId,
mainScriptUri,
line,
);
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseBreakpoint,
);
expect(bp, isNotNull);
// Remove breakpoint so it doesn't impact other tests.
await service.removeBreakpoint(isolateId, bp.id!);
});
test('set existing breakpoint succeeds', () async {
final line = await context.findBreakpointLine(
'printLocal',
isolateId,
mainScript,
);
final bp1 = await service.addBreakpointWithScriptUri(
isolateId,
mainScriptUri,
line,
);
final bp2 = await service.addBreakpointWithScriptUri(
isolateId,
mainScriptUri,
line,
);
expect(bp1, equals(bp2));
expect(bp1, isNotNull);
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseBreakpoint,
);
var currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, containsAll([bp1]));
// Remove breakpoints so they don't impact other tests.
await service.removeBreakpoint(isolateId, bp1.id!);
currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, isEmpty);
});
test('set breakpoints at the same line simultaneously succeeds',
() async {
final line = await context.findBreakpointLine(
'printLocal',
isolateId,
mainScript,
);
final futures = [
service.addBreakpointWithScriptUri(isolateId, mainScriptUri, line),
service.addBreakpointWithScriptUri(isolateId, mainScriptUri, line),
];
final breakpoints = await Future.wait(futures);
expect(breakpoints[0], equals(breakpoints[1]));
expect(breakpoints[0], isNotNull);
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseBreakpoint,
);
var currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, containsAll([breakpoints[0]]));
// Remove breakpoints so they don't impact other tests.
await service.removeBreakpoint(isolateId, breakpoints[0].id!);
currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, isEmpty);
});
test('remove non-existing breakpoint fails', () async {
final line = await context.findBreakpointLine(
'printLocal',
isolateId,
mainScript,
);
final bp = await service.addBreakpointWithScriptUri(
isolateId,
mainScriptUri,
line,
);
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseBreakpoint,
);
var currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, containsAll([bp]));
// Remove breakpoints so they don't impact other tests.
await service.removeBreakpoint(isolateId, bp.id!);
await expectLater(
service.removeBreakpoint(isolateId, bp.id!),
throwsRPCError,
);
currentIsolate = await service.getIsolate(isolateId);
expect(currentIsolate.breakpoints, isEmpty);
});
});
});
}