1- // Copyright 2025 The Flutter Authors
1+ // Copyright 2026 The Flutter Authors
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
44
@@ -40,11 +40,24 @@ class HotRestartNetworkVmService extends FakeVmServiceWrapper {
4040 static final _testVmFlagManager = VmFlagManager ();
4141
4242 String _currentIsolateId = 'isolates/1' ;
43- int _timelineMicros = 1000000 ;
4443
44+ /// A monotonic microsecond counter simulating the VM timeline clock.
45+ int _timelineMicros = 1_000_000 ;
46+
47+ /// A map of isolate ID to the list of mock HTTP requests recorded on that
48+ /// isolate.
4549 final _httpProfiles = < String , List <HttpProfileRequest >> {};
50+
51+ /// A map of isolate ID to the list of mock socket statistics recorded on that
52+ /// isolate.
4653 final _socketProfiles = < String , List <SocketStatistic >> {};
54+
55+ /// A map tracking whether HTTP timeline logging is enabled (true/false) per
56+ /// isolate ID.
4757 final _httpLoggingEnabled = < String , bool > {};
58+
59+ /// A map tracking whether socket profiling is enabled (true/false) per isolate
60+ /// ID.
4861 final _socketProfilingEnabled = < String , bool > {};
4962
5063 /// The isolate ID currently returned by [forEachIsolate] .
@@ -79,28 +92,27 @@ class HotRestartNetworkVmService extends FakeVmServiceWrapper {
7992 _currentIsolateId = nextId;
8093 _httpLoggingEnabled[nextId] = false ;
8194 _socketProfilingEnabled[nextId] = false ;
82- _timelineMicros += 5000000 ;
95+ // Advance past pre-restart request timestamps so refresh logic treats them
96+ // as stale on the new isolate.
97+ _timelineMicros += 5_000_000 ;
8398 return nextId;
8499 }
85100
86101 /// Appends [request] to the HTTP profile for [isolateId] .
87102 void appendHttpRequest (String isolateId, HttpProfileRequest request) {
88- _httpProfiles[isolateId] = [
89- ...(_httpProfiles[isolateId] ?? const []),
90- request,
91- ];
103+ _httpProfiles[isolateId] = [...? _httpProfiles[isolateId], request];
92104 }
93105
94106 @override
95- Future <Success > clearHttpProfileWrapper (String isolateId) {
107+ Future <Success > clearHttpProfileWrapper (String isolateId) async {
96108 _httpProfiles[isolateId] = [];
97- return Future . value ( Success () );
109+ return Success ();
98110 }
99111
100112 @override
101- Future <Success > clearSocketProfileWrapper (String isolateId) {
113+ Future <Success > clearSocketProfileWrapper (String isolateId) async {
102114 _socketProfiles[isolateId] = [];
103- return Future . value ( Success () );
115+ return Success ();
104116 }
105117
106118 @override
@@ -111,45 +123,39 @@ class HotRestartNetworkVmService extends FakeVmServiceWrapper {
111123 Future <HttpTimelineLoggingState > httpEnableTimelineLoggingWrapper (
112124 String isolateId, [
113125 bool ? enabled,
114- ]) {
126+ ]) async {
115127 if (enabled != null ) {
116128 _httpLoggingEnabled[isolateId] = enabled;
117- return Future . value ( HttpTimelineLoggingState (enabled: enabled) );
129+ return HttpTimelineLoggingState (enabled: enabled);
118130 }
119- return Future .value (
120- HttpTimelineLoggingState (
121- enabled: _httpLoggingEnabled[isolateId] ?? false ,
122- ),
131+ return HttpTimelineLoggingState (
132+ enabled: _httpLoggingEnabled[isolateId] ?? false ,
123133 );
124134 }
125135
126136 @override
127137 Future <SocketProfilingState > socketProfilingEnabledWrapper (
128138 String isolateId, [
129139 bool ? enabled,
130- ]) {
140+ ]) async {
131141 if (enabled != null ) {
132142 _socketProfilingEnabled[isolateId] = enabled;
133- return Future . value ( SocketProfilingState (enabled: enabled) );
143+ return SocketProfilingState (enabled: enabled);
134144 }
135- return Future .value (
136- SocketProfilingState (
137- enabled: _socketProfilingEnabled[isolateId] ?? false ,
138- ),
145+ return SocketProfilingState (
146+ enabled: _socketProfilingEnabled[isolateId] ?? false ,
139147 );
140148 }
141149
142150 @override
143151 Future <HttpProfile > getHttpProfileWrapper (
144152 String isolateId, {
145153 DateTime ? updatedSince,
146- }) {
154+ }) async {
147155 if (! (_httpLoggingEnabled[isolateId] ?? false )) {
148- return Future .value (
149- HttpProfile (
150- requests: [],
151- timestamp: DateTime .fromMicrosecondsSinceEpoch (_timelineMicros),
152- ),
156+ return HttpProfile (
157+ requests: [],
158+ timestamp: DateTime .fromMicrosecondsSinceEpoch (_timelineMicros),
153159 );
154160 }
155161
@@ -165,25 +171,21 @@ class HotRestartNetworkVmService extends FakeVmServiceWrapper {
165171 )
166172 .toList ();
167173 }
168- return Future .value (
169- HttpProfile (
170- requests: requests,
171- timestamp: DateTime .fromMicrosecondsSinceEpoch (_timelineMicros),
172- ),
174+ return HttpProfile (
175+ requests: requests,
176+ timestamp: DateTime .fromMicrosecondsSinceEpoch (_timelineMicros),
173177 );
174178 }
175179
176180 @override
177- Future <SocketProfile > getSocketProfileWrapper (String isolateId) {
181+ Future <SocketProfile > getSocketProfileWrapper (String isolateId) async {
178182 if (! (_socketProfilingEnabled[isolateId] ?? false )) {
179- return Future . value ( SocketProfile (sockets: []) );
183+ return SocketProfile (sockets: []);
180184 }
181- return Future .value (
182- SocketProfile (sockets: _socketProfiles[isolateId] ?? const []),
183- );
185+ return SocketProfile (sockets: _socketProfiles[isolateId] ?? const []);
184186 }
185187
186188 @override
187- Future <Timestamp > getVMTimelineMicros () =>
188- Future . value ( Timestamp (timestamp: _timelineMicros) );
189+ Future <Timestamp > getVMTimelineMicros () async =>
190+ Timestamp (timestamp: _timelineMicros);
189191}
0 commit comments