Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ce508286
Unverified
Commit
ce508286
authored
Jul 07, 2023
by
Polina Cherkasova
Committed by
GitHub
Jul 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test that inspector does not hold objects. (#130102)
parent
3f2d798b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
4 deletions
+41
-4
widget_inspector_test.dart
packages/flutter/test/widgets/widget_inspector_test.dart
+41
-4
No files found.
packages/flutter/test/widgets/widget_inspector_test.dart
View file @
ce508286
...
...
@@ -10,6 +10,7 @@
library
;
import
'dart:convert'
;
import
'dart:developer'
;
import
'dart:math'
;
import
'dart:ui'
as
ui
;
...
...
@@ -240,6 +241,29 @@ extension TextFromString on String {
}
}
/// Forces garbage collection by aggressive memory allocation.
///
/// Copied from internal code of
/// https://github.com/dart-lang/leak_tracker
Future
<
void
>
_forceGC
()
async
{
const
int
gcCycles
=
3
;
// 1 should be enough, but we do 3 to make sure test is not flaky.
final
int
barrier
=
reachabilityBarrier
;
final
List
<
List
<
DateTime
>>
storage
=
<
List
<
DateTime
>>[];
void
allocateMemory
()
{
storage
.
add
(
Iterable
<
DateTime
>.
generate
(
10000
,
(
_
)
=>
DateTime
.
now
()).
toList
());
if
(
storage
.
length
>
100
)
{
storage
.
removeAt
(
0
);
}
}
while
(
reachabilityBarrier
<
barrier
+
gcCycles
)
{
await
Future
<
void
>.
delayed
(
Duration
.
zero
);
allocateMemory
();
}
}
final
List
<
Object
>
_weakValueTests
=
<
Object
>[
1
,
1.0
,
'hello'
,
true
,
false
,
Object
(),
<
int
>[
3
,
4
],
DateTime
(
2023
)];
void
main
(
)
{
...
...
@@ -299,6 +323,19 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect
(
WidgetInspectorService
.
objectToDiagnosticsNode
(
Alignment
.
bottomCenter
),
isNull
);
});
test
(
'WidgetInspector does not hold objects from GC'
,
()
async
{
List
<
DateTime
>?
someObject
=
<
DateTime
>[
DateTime
.
now
(),
DateTime
.
now
()];
final
String
?
id
=
service
.
toId
(
someObject
,
'group_name'
);
expect
(
id
,
isNotNull
);
final
WeakReference
<
Object
>
ref
=
WeakReference
<
Object
>(
someObject
);
someObject
=
null
;
await
_forceGC
();
expect
(
ref
.
target
,
null
);
});
testWidgets
(
'WidgetInspector smoke test'
,
(
WidgetTester
tester
)
async
{
// This is a smoke test to verify that adding the inspector doesn't crash.
await
tester
.
pumpWidget
(
...
...
@@ -3775,7 +3812,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
_CreationLocation
location
=
knownLocations
[
id
]!;
expect
(
location
.
file
,
equals
(
file
));
// ClockText widget.
expect
(
location
.
line
,
equals
(
5
5
));
expect
(
location
.
line
,
equals
(
5
6
));
expect
(
location
.
column
,
equals
(
9
));
expect
(
location
.
name
,
equals
(
'ClockText'
));
expect
(
count
,
equals
(
1
));
...
...
@@ -3785,7 +3822,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
location
=
knownLocations
[
id
]!;
expect
(
location
.
file
,
equals
(
file
));
// Text widget in _ClockTextState build method.
expect
(
location
.
line
,
equals
(
9
3
));
expect
(
location
.
line
,
equals
(
9
4
));
expect
(
location
.
column
,
equals
(
12
));
expect
(
location
.
name
,
equals
(
'Text'
));
expect
(
count
,
equals
(
1
));
...
...
@@ -3812,7 +3849,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
location
=
knownLocations
[
id
]!;
expect
(
location
.
file
,
equals
(
file
));
// ClockText widget.
expect
(
location
.
line
,
equals
(
5
5
));
expect
(
location
.
line
,
equals
(
5
6
));
expect
(
location
.
column
,
equals
(
9
));
expect
(
location
.
name
,
equals
(
'ClockText'
));
expect
(
count
,
equals
(
3
));
// 3 clock widget instances rebuilt.
...
...
@@ -3822,7 +3859,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
location
=
knownLocations
[
id
]!;
expect
(
location
.
file
,
equals
(
file
));
// Text widget in _ClockTextState build method.
expect
(
location
.
line
,
equals
(
9
3
));
expect
(
location
.
line
,
equals
(
9
4
));
expect
(
location
.
column
,
equals
(
12
));
expect
(
location
.
name
,
equals
(
'Text'
));
expect
(
count
,
equals
(
3
));
// 3 clock widget instances rebuilt.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment