Files
tmail-flutter/integration_test/memory/memory_probe.dart
T
Dang Dat 7af4869bed test: add memory test tag, heavy image and memory probe
Add the memory tag (excluded from the normal Patrol runs), a per-test timeout,
a generated 5 MB PNG, inline-image provisioning and a probe that samples the
Dart heap on Android and the sidecar on web.

Refs #4365
2026-11-06 15:40:29 +07:00

33 lines
982 B
Dart

import 'package:flutter/painting.dart';
import 'package:patrol/patrol.dart';
import 'memory_probe_io.dart'
if (dart.library.js_interop) 'memory_probe_web.dart' as platform;
const String _sidecarUrl = String.fromEnvironment('MEMORY_SIDECAR_URL');
/// Settles the app, then sends one memory sample to the CI sidecar.
///
/// Fails fast when the sidecar is not configured or the platform cannot
/// measure, so a leak check never passes silently.
Future<void> sampleMemory(
PatrolIntegrationTester $, {
required String caseId,
required String label,
}) async {
if (_sidecarUrl.isEmpty) {
throw StateError('MEMORY_SIDECAR_URL is not set');
}
// imageCache is a bounded framework cache, not a leak.
PaintingBinding.instance.imageCache
..clear()
..clearLiveImages();
await $.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 2));
await platform.postSample(
sidecarUrl: _sidecarUrl,
caseId: caseId,
label: label,
);
}