Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Jul 25, 2023
1 parent acfbf92 commit 50e7d1e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ class LeakTrackingConfiguration {
LeakTrackingConfiguration.passive({
LeakDiagnosticConfig leakDiagnosticConfig = const LeakDiagnosticConfig(),
int numberOfGcCycles = defaultNumberOfGcCycles,
int? maxRequestsForRetainingPath = 10,
}) : this(
stdoutLeaks: false,
notifyDevTools: false,
checkPeriod: null,
disposalTime: const Duration(),
leakDiagnosticConfig: leakDiagnosticConfig,
numberOfGcCycles: numberOfGcCycles,
maxRequestsForRetainingPath: maxRequestsForRetainingPath,
);

/// Number of full GC cycles, enough for a non reachable object to be GCed.
Expand Down
2 changes: 2 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/orchestration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Future<Leaks> withLeakTracking(
LeakDiagnosticConfig leakDiagnosticConfig = const LeakDiagnosticConfig(),
AsyncCodeRunner? asyncCodeRunner,
int numberOfGcCycles = defaultNumberOfGcCycles,
int? maxRequestsForRetainingPath = 10,
}) async {
if (numberOfGcCycles <= 0) {
throw ArgumentError.value(
Expand All @@ -105,6 +106,7 @@ Future<Leaks> withLeakTracking(
config: LeakTrackingConfiguration.passive(
leakDiagnosticConfig: leakDiagnosticConfig,
numberOfGcCycles: numberOfGcCycles,
maxRequestsForRetainingPath: maxRequestsForRetainingPath,
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ import '../../test_infra/data/dart_classes.dart';

/// Tests for non-mocked public API of leak tracker.
void main() {
setUp(() {
LeakTrackerGlobalState.maxRequestsForRetainingPath = null;
});

tearDown(() => LeakTracking.stop());

for (var numberOfGcCycles in [1, defaultNumberOfGcCycles]) {
test(
'Leak tracker respects maxRequestsForRetainingPath, $numberOfGcCycles.',
() async {
LeakTrackerGlobalState.maxRequestsForRetainingPath = 2;
final leaks = await withLeakTracking(
() async {
LeakingClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void main() {
disposalTime: _disposalTime,
coder: mockCoder,
numberOfGcCycles: defaultNumberOfGcCycles,
maxRequestsForRetainingPath: 0,
);
});

Expand Down Expand Up @@ -147,6 +148,7 @@ void main() {
gcCounter: gcCounter,
disposalTime: _disposalTime,
numberOfGcCycles: defaultNumberOfGcCycles,
maxRequestsForRetainingPath: 0,
);
});

Expand Down Expand Up @@ -323,6 +325,7 @@ void main() {
),
disposalTime: _disposalTime,
numberOfGcCycles: defaultNumberOfGcCycles,
maxRequestsForRetainingPath: 0,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MockObjectTracker extends ObjectTracker {
disposalTime: const Duration(milliseconds: 100),
leakDiagnosticConfig: const LeakDiagnosticConfig(),
numberOfGcCycles: defaultNumberOfGcCycles,
maxRequestsForRetainingPath: 0,
);

final events = <Event>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MockObjectTracker extends ObjectTracker {
disposalTime: const Duration(milliseconds: 100),
leakDiagnosticConfig: const LeakDiagnosticConfig(),
numberOfGcCycles: 3,
maxRequestsForRetainingPath: 10,
);

final events = <Event>[];
Expand Down

0 comments on commit 50e7d1e

Please sign in to comment.